Scripts/Linux/Syncthing/install_syncthing.sh

64 lines
1.8 KiB
Bash
Raw Normal View History

2021-11-02 14:16:03 +00:00
#!/bin/bash
# Elevate Privelage
echo "This Script has to be ran as Sudo"
sudo -v
sudo apt install net-tools
# Set Variables
ip=$(sudo ifconfig eth0 | perl -ne 'print $1 if /inet\s.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b/')
syncthingversion=$(curl --silent "https://api.github.com/repos/syncthing/syncthing/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
2021-11-02 14:16:03 +00:00
2022-05-29 12:06:29 +00:00
#Setup Syncthing User
2021-11-02 14:16:03 +00:00
sudo mkdir /opt/syncthing
sudo chown syncthing -R /opt/syncthing
sudo chgrp $(echo "$USER") -R /opt/syncthing
sudo chmod 770 /opt/syncthing
mkdir /opt/syncthing/config
mkdir /opt/syncthing/bin
mkdir /opt/syncthing/bin/current
2022-05-29 12:06:29 +00:00
sudo adduser \
--system \
--shell /bin/bash \
--gecos 'Syncthing Client' \
--group \
--disabled-password \
--home /opt/syncthing/config \
syncthing
2021-11-02 14:16:03 +00:00
# Get Syncthing and setup
cd /opt/syncthing/bin
wget https://github.com/syncthing/syncthing/releases/download/$(echo $syncthingversion)/syncthing-linux-amd64-$(echo $syncthingversion).tar.gz
2022-04-19 15:08:02 +00:00
tar -xvf syncthing-linux-amd64-$syncthingversion.tar.gz
cp -r syncthing-linux-amd64-$syncthingversion/* /opt/syncthing/bin/current
cat <<EOF > /opt/syncthing/bin/version.txt
$syncthingversion
EOF
rm syncthing-linux-amd64-$syncthingversion.tar.gz
rm -r syncthing-linux-amd64-$(echo $syncthingversion)
2021-11-02 14:16:03 +00:00
# Setup Supervisor
sudo apt-get install supervisor
2022-04-19 15:04:57 +00:00
sudo bash -c 'cat <<EOF > /etc/supervisor/conf.d/syncthing.conf
2021-11-02 14:16:03 +00:00
[program:syncthing]
autorestart = True
directory = /opt/syncthing/config
user = sycthing
command = /usr/local/bin/syncthing -no-browser -logflags=0 -gui-address=$ip:8384 -home=/opt/syncthing/config/
environment = STNORESTART="1", HOME="/opt/syncthing/config/"
2022-04-19 15:04:57 +00:00
EOF'
2021-11-02 14:16:03 +00:00
sudo supervisorctl reread
sudo supervisorctl update
2022-05-29 12:06:29 +00:00
sudo supervisorctl reload
2021-11-02 14:16:03 +00:00
echo "If everything installed with no errors"
echo "Please go to http://$ip:8384"