first commit

This commit is contained in:
julien
2024-12-03 00:49:51 +01:00
commit ba023e9f59
11 changed files with 244 additions and 0 deletions

22
README.md Executable file
View File

@@ -0,0 +1,22 @@
# debian
Server (Debian Stable) system general configuration, prepares the system on first boot or anytime.
## Usage
Run the `run.sh` script.
## Manual tasks
### Server
Edit crontab with :
```
# crontab -e
```
And add the following content :
```
# Run the NETig backup script at 4h every monday
0 4 * * mon /usr/local/sbin/netig-srv-backup
```

11
config/sources.list Normal file
View File

@@ -0,0 +1,11 @@
deb http://deb.debian.org/debian bookworm main contrib non-free-firmware
# deb-src http://deb.debian.org/debian bookworm main contrib non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free-firmware
# deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free-firmware
# deb http://deb.debian.org/debian bookworm-backports main contrib non-free-firmware
# deb-src http://deb.debian.org/debian bookworm-backports main contrib non-free-firmware
deb http://security.debian.org/debian-security bookworm-security main contrib non-free-firmware
# deb-src http://security.debian.org/debian-security bookworm-security main contrib non-free-firmware

29
modules/docker.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/bash
#############
### Docker
echo
echo " => Docker"
echo
if [ -f /usr/bin/docker ]
then
echo " -> Already done !"
else
# Add Docker's official GPG key
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg --yes
chmod a+rx /etc/apt/keyrings
chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources
echo \
"deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bullseye stable" \
| tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
# Install packages
apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
fi

15
modules/pkgs.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
#######################
### Install packages
echo
echo " => Packages"
echo
pkglist="git
htop
tree
rsync"
apt-get install $pkglist -y

10
modules/repos.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
###########################
### Repos configuration
echo
echo " => Repos configuration"
echo
cp config/sources.list /etc/apt/sources.list

10
modules/scripts.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
###################
### Copy scripts
echo
echo " => Scripts"
echo
cp scripts/* /usr/local/sbin

11
modules/update.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
#############
### Update
echo
echo " => Update"
echo
apt-get update
apt-get upgrade -y

28
modules/volumes.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
##########################
### Volumes mountpoints
echo
echo " => Volumes mountpoints"
echo
if [ -d /var/netig/srv ]
then
echo " -> Already done !"
else
mkdir -p /var/netig/srv
echo
echo " => Adjust /etc/fstab accordingly !"
echo
fi
if [ -d /var/netig/bak ]
then
echo " -> Already done !"
else
mkdir -p /var/netig/bak
echo
echo " => Adjust /etc/fstab accordingly !"
echo
fi

19
modules/zram.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
###########
### ZRAM
echo
echo " => ZRAM"
echo
if [ -f /usr/bin/zramswap ]
then
echo " -> Already done !"
else
apt-get install zram-tools -y
sed -i '/#ALGO=lz4/s/^#//g' /etc/default/zramswap
sed -i '/#PERCENT=50/s/^#//g' /etc/default/zramswap
sed -i 's/ALGO=lz4/ALGO=zstd/g' /etc/default/zramswap
systemctl restart zramswap.service
fi

28
run.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
# If root
ID=$(id -u)
if [ "$ID" -ne 0 ]
then
echo
echo "Please run as root !"
exit
fi
# Post-installation
modules="repos.sh
update.sh
pkgs.sh
docker.sh
zram.sh
scripts.sh
volumes.sh"
for i in $modules
do
modules/$i
done
# End message
echo
echo "Post-installation done !"

61
scripts/netig-srv-backup Executable file
View File

@@ -0,0 +1,61 @@
#!/bin/bash
################################################################################
### Variables
# Source directory
source="/var/netig/srv"
# Destination directory
destination="/var/netig/bak"
# Backup file name
backup="bak_$(hostname -f)_$(date +"%Y%m%d").tar.zst"
################################################################################
### Down services
( cd /var/netig/srv/status.netig.net && docker compose down )
for f in /var/netig/srv/*
do
if [ -d "$f" ]; then
cd $f
docker compose down
fi
done
################################################################################
### Making the backup archive
echo
echo " Making the backup archive."
echo
tar --zstd -cf $destination/$backup -C $source .
################################################################################
### Up services
for f in /var/netig/srv/*
do
if [ -d "$f" ]; then
cd $f
if [ -d "django" ]
then
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
else
docker compose up -d
fi
fi
done
################################################################################
### Remove destination archives older than n days
find $destination -name "bak_*" -type f -mtime +20 -delete
################################################################################
### End message
echo
echo " Backup done."
echo