refactor: use tools dir
This commit is contained in:
parent
7c4160effc
commit
6b06453d37
9 changed files with 102 additions and 59 deletions
59
setup.sh
59
setup.sh
|
@ -1,59 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# setup new server
|
|
||||||
|
|
||||||
## PREFLIGHT
|
|
||||||
|
|
||||||
ORIGIN_PWD="$PWD"
|
|
||||||
|
|
||||||
if ! [ "$UID" = "0" ]; then
|
|
||||||
echo "please perform as root, attempting to escalate privileges..."
|
|
||||||
exec sudo $(cat /proc/$$/cmdline | sed 's/\x00/ /g')
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! ssh git@git.ixvd.net; then
|
|
||||||
echo "can't connect to git, please setup ssh"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## MAIN
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
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
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! [ -f "/root/.ssh/authorized_keys" ]; then
|
|
||||||
echo "importing authorized_keys..."
|
|
||||||
mkdir -p /root/.ssh
|
|
||||||
cp /etc/ixvd/secrets/ssh/authorized_keys /root/.ssh/authorized_keys
|
|
||||||
else
|
|
||||||
if ! grep -q "# IXVD keys" /root/.ssh/authorized_keys; then
|
|
||||||
echo "importing authorized_keys..."
|
|
||||||
cat /etc/ixvd/secrets/ssh/authorized_keys >> /root/.ssh/authorized_keys
|
|
||||||
fi
|
|
||||||
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
|
|
||||||
//$domain/backup /mnt/backups cifs credentials=/etc/ixvd/secrets/backups.cifs,file_mode=0777,dir_mode=0777,noperm 0 0
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! [ -d "/mnt/backups" ]; then
|
|
||||||
echo "mounting share..."
|
|
||||||
mkdir /mnt/backups
|
|
||||||
mount /mnt/backups
|
|
||||||
fi
|
|
5
tools/README.md
Normal file
5
tools/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
> **Warning**
|
||||||
|
> Do **NOT** run these tools in this directory.
|
||||||
|
> Run them from the *main* directory.
|
||||||
|
|
||||||
|
Tools used for the IXVD infra
|
18
tools/remove-skel.sh
Normal file
18
tools/remove-skel.sh
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# remove skeleton **files**
|
||||||
|
|
||||||
|
if ! [ "$UID" = "0" ]; then
|
||||||
|
echo "not root"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "WARNING; this will remove neb's skel **files**, not it's directories!"
|
||||||
|
echo "WARNING; you will have to remove those manually"
|
||||||
|
|
||||||
|
cd skel/
|
||||||
|
for f in $(find . -type f | sed 's|.\/|\/|'); do
|
||||||
|
printf "\r\033[2KRM $f"
|
||||||
|
[ -f $f ] && rm $f
|
||||||
|
done
|
||||||
|
echo -e "\r\033[2KDONE!"
|
28
tools/setup-server.sh
Normal file
28
tools/setup-server.sh
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# setup server
|
||||||
|
|
||||||
|
## PREFLIGHT
|
||||||
|
|
||||||
|
ORIGIN_PWD="$PWD"
|
||||||
|
|
||||||
|
if ! [ "$UID" = "0" ]; then
|
||||||
|
echo "please perform as root, attempting to escalate privileges..."
|
||||||
|
exec sudo $(cat /proc/$$/cmdline | sed 's/\x00/ /g')
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "testing git connection..."
|
||||||
|
if ! ssh -Tq git@git.ixvd.net &> /dev/null; then
|
||||||
|
echo "can't connect to git, please setup ssh"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
## MAIN
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
for s in tools/setup/*; do
|
||||||
|
echo "running $s..."
|
||||||
|
sh $s
|
||||||
|
done
|
6
tools/setup/00-apply-skel.sh
Normal file
6
tools/setup/00-apply-skel.sh
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if ! [ -f "/etc/ixvd/version" ]; then
|
||||||
|
echo "applying overlay..."
|
||||||
|
cp -r skel/. /
|
||||||
|
fi
|
6
tools/setup/10-clone-ixvd-secrets.sh
Normal file
6
tools/setup/10-clone-ixvd-secrets.sh
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if ! [ -d "/etc/ixvd/secrets" ]; then
|
||||||
|
echo "setting up ixvd/secrets"
|
||||||
|
git clone git@git.ixvd.net:ixvd/secrets /etc/ixvd/secrets
|
||||||
|
fi
|
12
tools/setup/20-ssh-authorized-keys.sh
Normal file
12
tools/setup/20-ssh-authorized-keys.sh
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if ! [ -f "/root/.ssh/authorized_keys" ]; then
|
||||||
|
echo "importing authorized_keys..."
|
||||||
|
mkdir -p /root/.ssh
|
||||||
|
cp /etc/ixvd/secrets/ssh/authorized_keys /root/.ssh/authorized_keys
|
||||||
|
else
|
||||||
|
if ! grep -q "# IXVD keys" /root/.ssh/authorized_keys; then
|
||||||
|
echo "importing authorized_keys..."
|
||||||
|
cat /etc/ixvd/secrets/ssh/authorized_keys >> /root/.ssh/authorized_keys
|
||||||
|
fi
|
||||||
|
fi
|
17
tools/setup/30-cifs.sh
Normal file
17
tools/setup/30-cifs.sh
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
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
|
||||||
|
//$domain/backup /mnt/backups cifs credentials=/etc/ixvd/secrets/backups.cifs,file_mode=0777,dir_mode=0777,noperm 0 0
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [ -d "/mnt/backups" ]; then
|
||||||
|
echo "mounting share..."
|
||||||
|
mkdir /mnt/backups
|
||||||
|
mount /mnt/backups
|
||||||
|
fi
|
10
tools/update-server.sh
Normal file
10
tools/update-server.sh
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if cd /etc/ixvd/secrets; then
|
||||||
|
git pull
|
||||||
|
cd -
|
||||||
|
fi
|
||||||
|
|
||||||
|
sh tools/remove-skel.sh
|
||||||
|
git pull
|
||||||
|
sh tools/setup-server.sh
|
Loading…
Reference in a new issue