Initialize

This commit is contained in:
Bill Niblock 2022-07-09 23:15:36 -04:00
commit 2a0f86604f
2 changed files with 191 additions and 0 deletions

42
README.md Normal file
View file

@ -0,0 +1,42 @@
# Syncthing Deck Setup
This script will download a Syncthing build and install it in the user's home
directory. This allows a user to run Syncthing using a SystemD user service, and
keep all necessary files within their home directory. In scenarios where the
traditional directory for installed packages may be overwritten (ie., the Steam
Deck's filesystem), this allows Syncthing to persist through updates, and still
run automatically in the background when the Deck is started. There is no GUI
provided for Syncthing when installed this way. Instead, use the web-UI
available at `localhost:8384`.
## Requirements
- `bash`
- `curl`
- `tar`
## Usage
Run the script. Optionally include a version, a platform, and an architecture.
Acceptable values can be found on the [Syncthing
Releases](https://github.com/syncthing/syncthing/releases) page.
```
Usage: syncthing-deck-setup [<options>]
-V, --version Specify a Syncthing Version. Default is latest.
-P, --platform Specify an OS/Platform. Default is linux.
-A, --arch Specify an architecture. Default is amd64.
-U, --uninstall Remove files setup with this script.
-v Show version
-h Show this usage
```
## Contact
If you're interested in discussing this project, you can speak with me on
Matrix! I'm [Vagabond](https://matrix.to/#/@vagabondazulien:exp.farm).
## Licenses / Copyrights/ Bureaucracy
All code is [Unlicensed](https://unlicense.org/).

149
syncthing-deck-setup.sh Normal file
View file

@ -0,0 +1,149 @@
#!/bin/bash
SDS_VERSION="0.0.1"
DEFAULT_VERSION="latest"
DEFAULT_PLATFORM="linux"
DEFAULT_ARCH="amd64"
SYNC_VERSION=$DEFAULT_VERSION
SYNC_PLATFORM=$DEFAULT_PLATFORM
SYNC_ARCH=$DEFAULT_ARCH
PKG_NAME="syncthing-$SYNC_PLATFORM-$SYNC_ARCH-v$SYNC_VERSION"
SDS_DIR_TMP="$HOME/.cache/steamdecksync"
SDS_DIR_BIN="$HOME/.local/bin"
SDS_DIR_SYS="$HOME/.config/systemd/user"
sds_extract_local_files () {
tar -xf $SDS_DIR_TMP/syncthing-files.tar.gz -C $SDS_DIR_TMP
}
sds_fetch_remote_files () {
echo "Pulling Syncthing package $PKG_NAME"
local REPO_URL="https://github.com/syncthing/syncthing/"
local RELEASE_URL="$REPO_URL/releases/download/v$SYNC_VERSION/$PKG_NAME.tar.gz"
curl --silent -L $RELEASE_URL > $SDS_DIR_TMP/syncthing-files.tar.gz
}
sds_install () {
cp $SDS_DIR_TMP/$PKB_NAME/syncthing $SDS_DIR_BIN/syncthing
systemctl --user daemon-reload
systemctl --user enable syncthing.service
systemctl --user start syncthing.service
}
sds_make_syncthing_service () {
cat > $HOME/.config/systemd/user/syncthing.service <<- EOM
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization
Documentation=man:syncthing(1)
StartLimitIntervalSec=60
StartLimitBurst=4
[Service]
ExecStart=/home/deck/.local/bin/syncthing serve --no-browser --no-restart --logflags=0
Restart=on-failure
RestartSec=1
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
# Hardening
SystemCallArchitectures=native
MemoryDenyWriteExecute=true
NoNewPrivileges=true
[Install]
WantedBy=default.target
EOM
}
sds_set_package_name () {
if [ $SYNC_VERSION == "latest" ]; then
local TAG_URL="https://api.github.com/repos/syncthing/syncthing/tags?per_page=1"
local SYNC_VERSION=$(\
curl --silent $TAG_URL | \
grep '"name":' | \
sed -r 's/.*v(.*)\".*/\1/'
)
fi
PKG_NAME="syncthing-$SYNC_PLATFORM-$SYNC_ARCH-v$SYNC_VERSION"
}
sds_setup () {
mkdir -p $SDS_DIR_TMP
mkdir -p $SDS_DIR_BIN
mkdir -p $SDS_DIR_SYS
}
sds_uninstall () {
echo "Stopping/Disabling Systemd User Service"
systemctl --user disable syncthing.service
systemctl --user stop syncthing.service
echo "Removing SDS directories and files"
rm -rf $SDS_DIR_TMP
rm $SDS_DIR_BIN/syntching
rm $SDS_DIR_SYS/syncthing.service
echo "SDS uninstalled"
}
sds_usage () {
echo -e "Usage: syncthing-deck-setup [<options>]"
printf "\n%17s %s" "-V, --version" "Specify a Syncthing Version. Default is latest."
printf "\n%17s %s" "-P, --platform" "Specify an OS/Platform. Default is linux."
printf "\n%17s %s" "-A, --arch" "Specify an architecture. Default is amd64."
printf "\n%17s %s" "-U, --uninstall" "Remove files setup with this script."
printf "\n%17s %s" "-v" "Show version"
printf "\n%17s %s" "-h" "Show this usage"
echo -e "\n"
}
while [[ $# -gt 0 ]]; do
case $1 in
-V|--version)
SYNC_VERSION="$2"
shift
shift
;;
-P|--platform)
SYNC_PLATFORM="$2"
shift
shift
;;
-A|--arch)
SYNC_ARCH="$2"
shift
shift
;;
-U|--uninstall)
sds_uninstall
exit 0
;;
-v)
echo "Syncthing Deck Setup version $SDS_VERSION"
exit 0
;;
*)
sds_usage
exit 0
;;
esac
done
sds_setup
sds_set_package_name
sds_fetch_remote_files
sds_make_syncthing_service
sds_extract_local_files
sds_install