webssh-service-unit/install.sh
2024-07-13 15:19:41 +02:00

60 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
run_directory=$(dirname $(readlink -f "$0"))
user=$(whoami)
source "$run_directory/variables.conf"
if [ -f $run_directory/.disabled ]; then
echo "Installation is disabled. Exiting..."
exit 0
fi
if [ -f /usr/lib/python3.12/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' \
/usr/lib/python3.12/site-packages/webssh/handler.py
else
sed -i -e 's/or wrong passphrase "{}" for decrypting it/or wrong passphrase for decrypting it/g' \
/usr/lib/python3.12/site-packages/webssh/handler.py
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
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
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
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
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
fi
echo "Reloading Systemd..."
if [[ $user != 'root' ]]; then
sudo systemctl daemon-reload
else
systemctl daemon-reload
fi
echo "Finished install. Exiting..."
exit 0