Created
May 7, 2022 08:48
-
-
Save fengjijiao/6c67941a103fd0e12b376da9941dd648 to your computer and use it in GitHub Desktop.
simpe to install syncthing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VERSION=v1.20.1 | |
INSTALL_DIR=/usr/local/syncthing | |
TMP_DIR=/tmp/syncthing | |
HOME_DIR=/etc/syncthing | |
function check_error() { | |
if [[ $? -ne 0 ]]; then | |
echo $1 | |
exit 1 | |
fi | |
} | |
function install() { | |
mkdir $INSTALL_DIR | |
mkdir $TMP_DIR | |
mkdir $HOME_DIR | |
cd $TMP_DIR | |
wget -O syncthing.tar.gz https://github.com/syncthing/syncthing/releases/download/${VERSION}/syncthing-linux-amd64-${VERSION}.tar.gz | |
check_error "download failed!" | |
tar -zxf syncthing.tar.gz --strip-components 1 -C $INSTALL_DIR | |
check_error "decopmression error!" | |
cat << EOT > /etc/systemd/system/[email protected] | |
[Unit] | |
Description=Syncthing - Open Source Continuous File Synchronization for %I | |
Documentation=man:syncthing(1) | |
After=network.target | |
[Service] | |
User=%i | |
ExecStart=${INSTALL_DIR}/syncthing -no-browser -gui-address="0.0.0.0:8384" -no-restart -logflags=0 | |
Restart=on-failure | |
SuccessExitStatus=3 4 | |
RestartForceExitStatus=3 4 | |
[Install] | |
WantedBy=multi-user.target | |
EOT | |
systemctl enable --now syncthing@${USER} | |
rm -rf $TMP_DIR | |
rm -rf syncthing.tar.gz | |
clear | |
echo 'http://127.0.0.1:8384' | |
echo 'install finished!' | |
} | |
function remove() { | |
systemctl stop syncthing@${USER} | |
systemctl disable syncthing@${USER} | |
rm -rf /etc/systemd/system/syncthing.service | |
rm -rf $INSTALL_DIR | |
clear | |
echo 'remove finished!' | |
} | |
function help() { | |
cat << EOF | |
syncthing install helper!!! | |
usage: | |
./syncthing.sh menu | |
install: install syncthing | |
remove: remove syncthing | |
EOF | |
} | |
function main() { | |
if [ $# -lt 1 ]; then | |
help | |
else | |
case $1 in | |
install) | |
install | |
;; | |
remove) | |
remove | |
;; | |
*) | |
echo 'command not found!' | |
help | |
;; | |
esac | |
fi | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment