Merge branch '0.0.2' into 'master'
Version 0.0.2 See merge request VagabondAzulien/steam-deck-syncthing!1
This commit is contained in:
commit
533cdb66fc
4 changed files with 246 additions and 151 deletions
11
README.md
11
README.md
|
@ -1,4 +1,4 @@
|
|||
# Syncthing Deck Setup
|
||||
# Steam Deck Syncthing
|
||||
|
||||
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
|
||||
|
@ -22,12 +22,19 @@ Acceptable values can be found on the [Syncthing
|
|||
Releases](https://github.com/syncthing/syncthing/releases) page.
|
||||
|
||||
```
|
||||
Usage: syncthing-deck-setup [<options>]
|
||||
Usage: steam-deck-syntching-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.
|
||||
|
||||
--no-systemd Don't do Systemd-related actions.
|
||||
--no-enable Don't enable the Systemd user-service.
|
||||
--no-start Don't start the Systemd user-service.
|
||||
--no-binary Don't install the Syncthing binary.
|
||||
|
||||
-U, --uninstall Remove files setup with this script.
|
||||
|
||||
-v Show version
|
||||
-h Show this usage
|
||||
```
|
||||
|
|
24
UNLICENSE
Normal file
24
UNLICENSE
Normal file
|
@ -0,0 +1,24 @@
|
|||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
213
steam-deck-syntching-setup.sh
Normal file
213
steam-deck-syntching-setup.sh
Normal file
|
@ -0,0 +1,213 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euf -o pipefail
|
||||
|
||||
SDS_VERSION="0.0.2"
|
||||
|
||||
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/steamdecksyncthing"
|
||||
SDS_DIR_BIN="${HOME}/.local/bin"
|
||||
SDS_DIR_SYS="${HOME}/.config/systemd/user"
|
||||
|
||||
SDS_SYSTEMD=1
|
||||
SDS_SYSD_ENABLE=1
|
||||
SDS_SYSD_START=1
|
||||
SDS_INSTALL_BINARY=1
|
||||
|
||||
|
||||
sds_extract_local_files () {
|
||||
echo "==> Extracting files to ${SDS_DIR_TMP}"
|
||||
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 () {
|
||||
if [[ "${SDS_INSTALL_BINARY}" -gt 0 ]]; then
|
||||
echo "==> Installing Syncthing binary to ${SDS_DIR_BIN}"
|
||||
cp "${SDS_DIR_TMP}"/"${PKG_NAME}"/syncthing "${SDS_DIR_BIN}"/syncthing
|
||||
fi
|
||||
|
||||
if [[ "${SDS_SYSTEMD}" -gt 0 ]]; then
|
||||
echo "==> Performing Systemd steps:"
|
||||
echo "===> Reloading user daemon"
|
||||
systemctl --user daemon-reload
|
||||
if [[ "${SDS_SYSD_ENABLE}" -gt 0 ]]; then
|
||||
echo "===> Enabling Syncthing user service"
|
||||
systemctl --user enable syncthing.service
|
||||
fi
|
||||
|
||||
if [[ "${SDS_SYSD_START}" -gt 0 ]]; then
|
||||
echo "===> Enabling Syncthing user service"
|
||||
systemctl --user start syncthing.service
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
sds_make_syncthing_service () {
|
||||
echo "==> Creating Systemd user service file in ${SDS_DIR_SYS}."
|
||||
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="${SDS_DIR_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/'
|
||||
)
|
||||
|
||||
SYNC_VERSION="${sync_version}"
|
||||
fi
|
||||
|
||||
PKG_NAME="syncthing-${SYNC_PLATFORM}-${SYNC_ARCH}-v${SYNC_VERSION}"
|
||||
}
|
||||
|
||||
sds_setup () {
|
||||
echo "==> Establishing desired directories"
|
||||
echo "===> Making ${SDS_DIR_TMP} (if not exists)"
|
||||
mkdir -p "${SDS_DIR_TMP}"
|
||||
echo "===> Making ${SDS_DIR_BIN} (if not exists)"
|
||||
mkdir -p "${SDS_DIR_BIN}"
|
||||
echo "===> Making ${SDS_DIR_SYS} (if not exists)"
|
||||
mkdir -p "${SDS_DIR_SYS}"
|
||||
}
|
||||
|
||||
sds_uninstall () {
|
||||
echo "=> Starting..."
|
||||
echo "==> Stopping/Disabling Systemd User Service"
|
||||
systemctl --user disable syncthing.service > /dev/null 2>&1
|
||||
systemctl --user stop syncthing.service > /dev/null 2>&1
|
||||
|
||||
echo "==> Removing SDS directories and files"
|
||||
echo "===> Removing ${SDS_DIR_TMP}"
|
||||
rm -rf "${SDS_DIR_TMP}" > /dev/null 2>&1
|
||||
echo "===> Removing Syncthing binary from ${SDS_DIR_BIN}"
|
||||
rm "${SDS_DIR_BIN}"/syntching > /dev/null 2>&1
|
||||
echo "===> Removing Syncthing user service file from ${SDS_DIR_SYS}"
|
||||
rm "${SDS_DIR_SYS}"/syncthing.service > /dev/null 2>&1
|
||||
|
||||
echo "SDS uninstalled"
|
||||
}
|
||||
|
||||
sds_usage () {
|
||||
echo -e "Usage: steam-deck-syntching-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."
|
||||
echo -e
|
||||
printf "\n%17s %s" "--no-systemd" "Don't do Systemd-related actions."
|
||||
printf "\n%17s %s" "--no-enable" "Don't enable the Systemd user-service."
|
||||
printf "\n%17s %s" "--no-start" "Don't start the Systemd user-service."
|
||||
printf "\n%17s %s" "--no-binary" "Don't install the Syncthing binary."
|
||||
echo -e
|
||||
printf "\n%17s %s" "-U, --uninstall" "Remove files setup with this script."
|
||||
echo -e
|
||||
printf "\n%17s %s" "-v" "Show version"
|
||||
printf "\n%17s %s" "-h" "Show this usage"
|
||||
echo -e "\n"
|
||||
}
|
||||
|
||||
sds_version () {
|
||||
echo "Steam Deck Syncthing Setup Version ${SDS_VERSION}"
|
||||
}
|
||||
|
||||
|
||||
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_version
|
||||
sds_uninstall
|
||||
exit 0
|
||||
;;
|
||||
--no-systemd)
|
||||
SDS_SYSTEMD=0
|
||||
shift
|
||||
;;
|
||||
--no-enable)
|
||||
SDS_SYSD_ENABLE=0
|
||||
shift
|
||||
;;
|
||||
--no-start)
|
||||
SDS_SYSD_START=0
|
||||
shift
|
||||
;;
|
||||
--no-binary)
|
||||
SDS_INSTALL_BINARY=0
|
||||
shift
|
||||
;;
|
||||
-v)
|
||||
sds_version
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
sds_version
|
||||
sds_usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
sds_version
|
||||
echo "=> Starting..."
|
||||
sds_setup
|
||||
sds_set_package_name
|
||||
sds_fetch_remote_files
|
||||
[[ "${SDS_SYSTEMD}" -gt 0 ]] && sds_make_syncthing_service
|
||||
sds_extract_local_files
|
||||
sds_install
|
||||
echo "=> Finished!"
|
|
@ -1,149 +0,0 @@
|
|||
#!/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
|
Loading…
Reference in a new issue