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

69 lines
2.9 KiB
Bash
Raw Normal View History

2022-09-16 15:00:38 +02:00
#!/usr/bin/env bash
2022-09-22 18:55:15 +02:00
run_directory=$(dirname $(readlink -f "$0"))
2022-09-16 15:00:38 +02:00
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
2022-09-16 15:07:51 +02:00
$sudo openssl req -newkey rsa:4096 -x509 -sha256 -days 999 -nodes -out /etc/ssl/cert.crt -keyout /etc/ssl/cert.key \
2022-09-16 15:00:38 +02:00
-subj "/C=/ST=/L=/O=/OU=/CN="
fi
2022-09-16 15:07:51 +02:00
if [ -d /etc/nginx ]; then
$sudo cp $run_directory/nginx-blocks/0-http-redirect /etc/nginx/sites-available/0-http-redirect
2022-09-16 15:10:27 +02:00
$sudo ln -sf ../sites-available/0-http-redirect /etc/nginx/sites-enabled/0-http-redirect
2022-09-16 15:07:51 +02:00
fi
2022-09-16 15:00:38 +02:00
2022-09-16 15:07:51 +02:00
if [ "$filebrowser" = "yes" ]; then
2022-09-16 15:00:38 +02:00
$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
2022-09-16 15:09:16 +02:00
$sudo sed -i -e "s:PH_NAS_DIRECTORY:$nas_location:g" /etc/systemd/system/filebrowser.service
2022-09-16 15:00:38 +02:00
$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
2022-09-16 15:10:27 +02:00
$sudo ln -sf ../sites-available/filebrowser /etc/nginx/sites-enabled/filebrowser
2022-09-16 15:00:38 +02:00
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/
2022-09-16 20:25:23 +02:00
$sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/transmission-vpn.service
2022-09-16 15:00:38 +02:00
$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
2022-09-16 15:10:27 +02:00
$sudo ln -sf ../sites-available/transmission /etc/nginx/sites-enabled/transmission
2022-09-16 15:00:38 +02:00
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