2017-06-12 00:38:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
{ # failed download protection
|
|
|
|
|
|
|
|
|
|
|
|
cat > /etc/apt/sources.list <<EOF
|
2017-06-12 00:45:18 +00:00
|
|
|
deb http://mirror.hetzner.de/debian/packages stretch main contrib non-free
|
|
|
|
deb http://mirror.hetzner.de/debian/security stretch/updates main contrib non-free
|
2017-06-12 00:38:21 +00:00
|
|
|
EOF
|
|
|
|
apt update
|
|
|
|
|
|
|
|
|
|
|
|
echo "Install important system tools."
|
2017-06-12 00:45:18 +00:00
|
|
|
apt install -y htop ne iotop curl wget zsh figlet iptraf borgbackup systemd-cron apticron logwatch unattended-upgrades
|
2017-06-12 00:38:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
echo "Use zsh!"
|
|
|
|
wget -q -O /root/.zshrc http://git.grml.org/f/grml-etc-core/etc/zsh/zshrc
|
|
|
|
cat >>/root/.zshrc << EOF
|
|
|
|
export LS_COLORS="*=00;37:rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:"
|
|
|
|
RED="$(tput setaf 1)"
|
|
|
|
ORANGE="$(tput setaf 3)"
|
|
|
|
BLUE="$(tput setaf 4)"
|
|
|
|
BLACK="$(tput sgr0)"
|
|
|
|
colorls() {
|
|
|
|
/bin/ls -lh --color=yes $@ | sed -e "s/ \([0-9,.]\+K\) / ${BLUE}\1${BLACK} /g" -e "s/ \([0-9.,]\+G\) / ${RED}\1${BLACK} /g" -e "s/ \([0-9.,]\+M\) / ${ORANGE}\1${BLACK} /g"
|
|
|
|
}
|
|
|
|
alias ls='command ls -h --color=auto'
|
|
|
|
alias l='colorls'
|
|
|
|
alias ll='colorls -A'
|
|
|
|
EOF
|
|
|
|
chsh -s /bin/zsh
|
|
|
|
|
|
|
|
|
|
|
|
echo "Setup hostname."
|
|
|
|
( exec ne /etc/hostname /etc/hosts )
|
|
|
|
hostname -F /etc/hostname
|
|
|
|
|
|
|
|
|
|
|
|
echo "Nice motd."
|
|
|
|
figlet `hostname -f | sed 's/\./ \. /g'` > /etc/motd
|
|
|
|
|
|
|
|
apt install -y ssmtp
|
|
|
|
( exec ne /etc/ssmtp/* )
|
|
|
|
|
|
|
|
|
|
|
|
echo "Disable unneeded getty"
|
|
|
|
for i in {4..6}; do
|
|
|
|
systemctl stop getty@tty$i.service
|
|
|
|
systemctl disable getty@tty$i.service
|
|
|
|
done
|
|
|
|
|
2017-06-12 00:45:18 +00:00
|
|
|
echo "setup systembackup"
|
2017-06-12 01:07:00 +00:00
|
|
|
if [ ! -f /root/.ssh/id_rsa ]; then
|
|
|
|
ssh-keygen
|
|
|
|
fi
|
|
|
|
cat /root/.ssh/id_rsa.pub
|
2017-06-12 01:16:31 +00:00
|
|
|
read -n 1 -p "Create backup account now" unused
|
2017-06-12 01:07:00 +00:00
|
|
|
|
2017-06-12 00:38:21 +00:00
|
|
|
wget -q -O /usr/local/sbin/systembackup https://code.camijo.de/gmueller/server-scripts/raw/master/systembackup
|
2017-06-12 01:07:00 +00:00
|
|
|
chmod +x /usr/local/sbin/systembackup
|
2017-06-12 00:46:05 +00:00
|
|
|
if [ ! -f /etc/systembackup.conf ]; then
|
2017-06-12 01:16:31 +00:00
|
|
|
PASSWD=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32}`
|
2017-06-12 00:38:21 +00:00
|
|
|
cat >>/etc/systembackup.conf <<EOF
|
2017-06-12 01:16:31 +00:00
|
|
|
REPOSITORY=ssh://borg-@backup.camijo.de/~/repo
|
|
|
|
PASSPHRASE=$PASSWD
|
2017-06-12 00:38:21 +00:00
|
|
|
MYSQL=no
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
( exec ne /etc/systembackup.conf )
|
|
|
|
|
2017-06-12 01:07:00 +00:00
|
|
|
if [ ! -f /etc/cron.d/systembackup ]; then
|
|
|
|
cat >>/etc/cron.d/systembackup <<EOF
|
|
|
|
18 */4 * * * root /usr/local/sbin/systembackup
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
( exec ne /etc/cron.d/systembackup )
|
|
|
|
|
|
|
|
source /etc/systembackup.conf
|
|
|
|
BORG_PASSPHRASE=$PASSPHRASE borg init $REPOSITORY
|
|
|
|
|
2017-06-12 00:38:21 +00:00
|
|
|
}
|
|
|
|
|