#!/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 [[ $user != 'root' ]]; then sudo="sudo" else sudo="" fi echo "Copying Systemd units to system directory..." if [ ! -f /etc/ssl/cert.crt ]; then $sudo openssl req -newkey rsa:4096 -x509 -sha256 -days 999 -nodes -out /etc/ssl/cert.crt -keyout /etc/ssl/cert.key \ -subj "/C=/ST=/L=/O=/OU=/CN=" fi if [ -d /etc/nginx ]; then $sudo cp $run_directory/nginx-blocks/0-http-redirect /etc/nginx/sites-available/0-http-redirect $sudo ln -sf ../sites-available/0-http-redirect /etc/nginx/sites-enabled/0-http-redirect fi if [ "$filebrowser" = "yes" ]; then $sudo cp $run_directory/systemd-templates/filebrowser.service /etc/systemd/system/ $sudo sed -i -e "s/PH_NAS_USER/$nas_user/g" /etc/systemd/system/filebrowser.service $sudo sed -i -e "s:PH_NAS_DIRECTORY:$nas_location:g" /etc/systemd/system/filebrowser.service $sudo cp $run_directory/nginx-blocks/filebrowser /etc/nginx/sites-available/filebrowser $sudo sed -i -e "s/PH_FQDN/$(hostname)/g" /etc/nginx/sites-available/filebrowser $sudo ln -sf ../sites-available/filebrowser /etc/nginx/sites-enabled/filebrowser fi if [ "$dlna_server" = "yes" ]; then $sudo sed -i -e "s:media_dir=/var/lib/minidlna:media_dir=$nas_location:g" /etc/minidlna.conf $sudo sed -i -e "s:#friendly_name=:friendly_name=$(hostname -s):g" /etc/minidlna.conf fi if [ "$dl_server" = "yes" ]; then $sudo cp $run_directory/systemd-templates/transmission-daemon.service /etc/systemd/system/ $sudo sed -i -e "s/PH_NAS_USER/$nas_user/g" /etc/systemd/system/transmission-daemon.service $sudo sed -i -e "s/PH_AUTHORIZED_ADDRESSES/$authorized_ips/g" /etc/systemd/system/transmission-daemon.service $sudo sed -i -e "s/PH_USER/$user/g" /etc/systemd/system/transmission-daemon.service $sudo sed -i -e "s/PH_PASSWORD/$password/g" /etc/systemd/system/transmission-daemon.service $sudo sed -i -e "s:PH_DL_LOCATION:$dl_location:g" /etc/systemd/system/transmission-daemon.service $sudo cp $run_directory/systemd-templates/transmission-vpn.service /etc/systemd/system/ $sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/transmission-vpn.service $sudo cp $run_directory/systemd-templates/transmission-vpn.timer /etc/systemd/system/ $sudo cp $run_directory/nginx-blocks/transmission /etc/nginx/sites-available/transmission $sudo sed -i -e "s/PH_FQDN/$(hostname)/g" /etc/nginx/sites-available/transmission $sudo ln -sf ../sites-available/transmission /etc/nginx/sites-enabled/transmission fi if [ "$ftp_server" = "yes" ]; then $sudo sed -i -e "s/#write_enable=YES/write_enable=YES/g" /etc/vsftpd.conf $sudo sed -i -e "s/#utf8_filesystem=YES/utf8_filesystem=YES/g" /etc/vsftpd.conf fi echo "Reloading Systemd..." sudo systemctl daemon-reload echo "Finished install. Exiting..." exit 0