forked from dannyti/seedbox-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 4
/
createSyncThingUserInstall
executable file
·67 lines (53 loc) · 2.78 KB
/
createSyncThingUserInstall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Hellish Tech
# No commercial usage without authorization
exec 1> >(logger -s -t $(basename $0)) 2>&1
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-u|--username)
USERNAME="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
SYSTEMHOSTNAME=`cat /etc/seedbox-from-scratch/hostname.info`
LISTENINGPORT=$(/etc/seedbox-from-scratch/sfsgetAvailablePort -sp 22001 -ep 22101)
PROTOCOLPORT=$(/etc/seedbox-from-scratch/sfsgetAvailablePort -sp 21028 -ep 21128)
WEBSERVERPORT=$(/etc/seedbox-from-scratch/sfsgetAvailablePort -sp 8385 -ep 8485)
USERPASSWORD=`sfsGenerateRandomPasswordString`
USERUID=$(id -u ${USERNAME})
USERGID=$(id -g ${USERNAME})
USERHASH=$(openssl passwd -apr1 ${USERPASSWORD})
grep '${USERNAME}:' | awk '{print $2}'
docker pull linuxserver/syncthing:latest
docker run --restart=always -d --name ${USERNAME}_syncthing -e LOCAL_USER_ID=${USERUID} -h ${SYSTEMHOSTNAME} -v /home/${USERNAME}/media:/data1 -v /home/${USERNAME}/downloads:/data2 -v /home/${USERNAME}/syncthing/config:/config -e PGID=${USERGID} -e PUID=${USERUID} -p ${WEBSERVERPORT}:8384 -v /etc/localtime:/etc/localtime:ro linuxserver/syncthing:latest
sleep 5
CHECKIFRUNNING=$(/etc/seedbox-from-scratch/sfsRunningUserDockerInfo -u ${USERNAME} -d syncthing | tr -cd '[[:alnum:]]._-' )
if [[ (${CHECKIFRUNNING} == "STOPPED") || (${CHECKIFRUNNING} == "RUNNING") ]]; then
if [ ! -d "/home/${USERNAME}/syncthing" ]; then
mkdir /home/${USERNAME}/syncthing
mkdir /home/${USERNAME}/syncthing/config
chown ${USERNAME}:${USERNAME} /home/${USERNAME}/syncthing/ -R
fi
echo "SERVICE: syncthing" > /home/${USERNAME}/private/syncthing.serviceinfo
echo "USERNAME: $USERNAME" >> /home/${USERNAME}/private/syncthing.serviceinfo
echo "ACCESSURL: http://$SYSTEMHOSTNAME:$WEBSERVERPORT" >> /home/${USERNAME}/private/syncthing.serviceinfo
echo "WEBSERVERPORT: $WEBSERVERPORT" >> /home/${USERNAME}/private/syncthing.serviceinfo
echo "LISTENINGPORT: $LISTENINGPORT" >> /home/${USERNAME}/private/syncthing.serviceinfo
echo "PROTOCOLPORT: $PROTOCOLPORT" >> /home/${USERNAME}/private/syncthing.serviceinfo
echo "Please log in and create a username and password, admins are not responsible for a users failure to secure the system." >> /home/${USERNAME}/private/syncthing.serviceinfo
chown www-data:www-data /home/${USERNAME}/private/*.serviceinfo
fi
sudo perl -ip -e "s/<user><\/user>/<user>${USERNAME}<\/user>/g" /home/${USERNAME}/syncthing/config/config.xml
sudo perl -ip -e 's/<password><\/password>/<password>USERHASH<\/password>/g' /home/${USERNAME}/syncthing/config/config.xml
sudo perl -pi -e "s/tls=\"false\"/tls=\"true\"/g" /home/${USERNAME}/syncthing/config/config.xml
if [[ -n $1 ]]; then
echo "Last line of file specified as non-opt/last argument:"
tail -1 $1
fi