neb/setup.sh

41 lines
956 B
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 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"
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 20:58:24 +02:00
fi