m2.nz/static/setup.sh

46 lines
1.3 KiB
Bash
Raw Normal View History

2022-10-11 09:25:55 +00:00
#!/bin/bash
# wget -q -O - "http://m2.nz/setup.sh" | bash
# curl "http://m2.nz/setup.sh" | bash
# Clean up if needed
if [[ "$1" == "uninstall" ]]; then
sudo rm -fr /tmp/authorized_keys
sudo rm -fr /usr/local/bin/check_keys
sed -i 's/^AuthorizedKeysCommand/#&/' /etc/ssh/sshd_config
sed -i 's/^AuthorizedKeysCommandUser/#&/' /etc/ssh/sshd_config
exit;
2022-10-11 09:50:28 +00:00
elif [[ "$1" == "update" ]]; then
wget -q -O /tmp/authorized_keys https://m2.nz/authorized_keys || curl -sSo /tmp/authorized_keys https://m2.nz/authorized_keys
exit;
2022-10-11 09:25:55 +00:00
fi
# Write script
sudo cat << EOF > /usr/local/bin/check_keys
#!/bin/bash
2022-10-11 09:50:28 +00:00
# Check if we have it cached, if so use that
2022-10-11 09:25:55 +00:00
if test -f "/tmp/authorized_keys"; then
cat /tmp/authorized_keys
2022-10-11 09:50:28 +00:00
# update for next login
bash /usr/local/bin/check_keys update &
2022-10-11 09:25:55 +00:00
else
2022-10-11 09:50:28 +00:00
wget -q -O /tmp/authorized_keys https://m2.nz/authorized_keys || curl -sSo /tmp/authorized_keys https://m2.nz/authorized_keys
2022-10-11 09:25:55 +00:00
cat /tmp/authorized_keys
fi
EOF
# Make executable
sudo chmod +x /usr/local/bin/check_keys
# Trigger on initial run
/usr/local/bin/check_keys
# Update SSHD to use it..
2022-10-11 09:28:15 +00:00
sudo echo "AuthorizedKeysCommand /usr/local/bin/check_keys" >> /etc/ssh/sshd_config
sudo echo "AuthorizedKeysCommandUser nobody" >> /etc/ssh/sshd_config
2022-10-11 09:25:55 +00:00
# Restart for good luck
sudo systemctl restart {sshd,ssh}