This repository has been archived on 2023-08-13. You can view files and clone it, but cannot push or open issues or pull requests.
nas-server/install.sh
2022-09-16 15:00:38 +02:00

65 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
run_directory=$(dirname "$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
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 [ "$file_browser" = "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 -s ../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:$run_directory: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 -s ../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