webssh-service-unit/install.sh

58 lines
2.0 KiB
Bash
Raw Normal View History

2022-08-19 13:11:27 +02:00
#!/usr/bin/env bash
run_directory=$(dirname $(readlink -f "$0"))
2022-08-19 13:11:27 +02:00
user=$(whoami)
source "$run_directory/variables.conf"
if [ -f $run_directory/.disabled ]; then
echo "Installation is disabled. Exiting..."
exit 0
fi
2023-12-03 17:45:08 +01:00
if [ -f /usr/lib/python3.11/site-packages/webssh/handler.py ]; then
echo "Alter WebSSH configuration to remove SSH key passphrase from error message..."
if [[ $user != 'root' ]]; then
sudo sed -i -e "s/or wrong passphrase {} for decrypting it/or wrong passphrase for decrypting it/g"
else
sed -i -e "s/or wrong passphrase {} for decrypting it/or wrong passphrase for decrypting it/g"
fi
else
echo "WARNING: Could not find webssh directory! Could be due to major Python upgrade, or you not using PIP package."
fi
if [ ! -f $keyfile ] || [ ! -f $certfile ]; then
echo "Creating self-signed certificate for web server..."
if [[ $user != 'root' ]]; then
sudo openssl req -newkey rsa:4096 -x509 -sha256 -days 999 -nodes -out $certfile -keyout $keyfile \
-subj "/C=/ST=/L=/O=/OU=/CN="
else
openssl req -newkey rsa:4096 -x509 -sha256 -days 999 -nodes -out $certfile -keyout $keyfile \
-subj "/C=/ST=/L=/O=/OU=/CN="
fi
fi
2022-08-19 13:11:27 +02:00
echo "Copying WebSSH unit to system directory..."
if [[ $user != 'root' ]]; then
sudo cp webssh.service /etc/systemd/system/
sudo sed -i -e "s:PH_ADDR:$address:g" /etc/systemd/system/webssh.service
sudo sed -i -e "s:PH_PORT:$port:g" /etc/systemd/system/webssh.service
2023-12-03 17:45:08 +01:00
sudo sed -i -e "s:PH_CRT:$certfile:g" /etc/systemd/system/webssh.service
sudo sed -i -e "s:PH_KEY:$keyfile:g" /etc/systemd/system/webssh.service
2022-08-19 13:11:27 +02:00
else
cp webssh.service /etc/systemd/system/
sed -i -e "s:PH_ADDR:$address:g" /etc/systemd/system/webssh.service
sed -i -e "s:PH_PORT:$port:g" /etc/systemd/system/webssh.service
2023-12-03 17:45:08 +01:00
sed -i -e "s:PH_CRT:$certfile:g" /etc/systemd/system/webssh.service
sed -i -e "s:PH_KEY:$keyfile:g" /etc/systemd/system/webssh.service
2022-08-19 13:11:27 +02:00
fi
echo "Reloading Systemd..."
if [[ $user != 'root' ]]; then
sudo systemctl daemon-reload
else
systemctl daemon-reload
fi
echo "Finished install. Exiting..."
exit 0