neb/setup.sh

59 lines
1.4 KiB
Bash
Raw Normal View History

2023-10-18 01:31:05 +02:00
#!/bin/sh
# setup new server
## PREFLIGHT
2023-10-18 18:08:05 +02:00
ORIGIN_PWD="$PWD"
2023-10-18 01:31:05 +02:00
if ! [ "$UID" = "0" ]; then
echo "please perform as root, attempting to escalate privileges..."
2023-10-18 18:08:05 +02:00
exec sudo $(cat /proc/$$/cmdline | sed 's/\x00/ /g')
2023-10-18 01:31:05 +02:00
exit 1
fi
if ! ssh git@git.ixvd.net; then
echo "can't connect to git, please setup ssh"
exit 1
fi
## MAIN
2023-10-18 22:14:01 +02:00
set -e
2023-10-18 20:58:24 +02:00
if ! [ -f "/etc/ixvd/version" ]; then
echo "applying overlay..."
cp -r skel /
fi
if ! [ -d "/etc/ixvd/secrets" ]; then
echo "setting up ixvd/secrets"
2023-10-18 22:14:01 +02:00
git clone git@git.ixvd.net:ixvd/secrets /etc/ixvd/secrets
2023-10-18 01:31:05 +02:00
fi
2023-10-18 18:08:05 +02:00
if ! [ -f "/root/.ssh/authorized_keys" ]; then
echo "importing authorized_keys..."
mkdir -p /root/.ssh
2023-10-18 20:58:24 +02:00
cp /etc/ixvd/secrets/ssh/authorized_keys /root/.ssh/authorized_keys
2023-10-18 18:08:05 +02:00
else
if ! grep -q "# IXVD keys" /root/.ssh/authorized_keys; then
echo "importing authorized_keys..."
2023-10-18 20:58:24 +02:00
cat /etc/ixvd/secrets/ssh/authorized_keys >> /root/.ssh/authorized_keys
2023-10-18 18:08:05 +02:00
fi
2023-10-18 22:14:01 +02:00
fi
if ! grep -q "# cifs mount backups" /etc/fstab; then
echo "modifying fstab..."
cp /etc/fstab /etc/fstab.$(date +"%H-%M-%S_%d-%m-%y").bak
. /etc/ixvd/secrets/backups.cifs
cat<<EOF>>/etc/fstab
# cifs mount backups
2023-10-18 22:35:10 +02:00
//$domain/backup /mnt/backups cifs credentials=/etc/ixvd/secrets/backups.cifs,file_mode=0777,dir_mode=0777,noperm 0 0
2023-10-18 22:14:01 +02:00
EOF
fi
if ! [ -d "/mnt/backups" ]; then
echo "mounting share..."
mkdir /mnt/backups
mount /mnt/backups
2023-10-18 20:58:24 +02:00
fi