Skip to content

Instantly share code, notes, and snippets.

@dotysan
Created February 5, 2025 18:46
Show Gist options
  • Save dotysan/3adb50d4ca3a5515511e01223f7243a4 to your computer and use it in GitHub Desktop.
Save dotysan/3adb50d4ca3a5515511e01223f7243a4 to your computer and use it in GitHub Desktop.
Wrapper around Synology_HDD_db
#! /usr/bin/env bash
#
# Wrapper around Synology_HDD_db.
#
set -o errexit
set -o nounset
set -o pipefail
PS4func() {
local lineno="$1"
local i f=''
local c="\033[0;36m" y="\033[0;33m" n="\033[0m"
local d=$((${#FUNCNAME[@]}-2))
if [[ $lineno == 1 ]]
then lineno=0
fi
for ((i=d; i>0; i--))
do printf -v f "%s%s()" "$f" "${FUNCNAME[i]}"
done
printf "$y%s:%04d$c%s$n " "${BASH_SOURCE[1]##*/}" "$lineno" "$f"
}
PS4='\r$(PS4func $LINENO)'
set -o xtrace
main() {
USER="${1:-007revad}"
BRANCH="${2:-main}"
REPO="$USER/Synology_HDD_db"
if [[ ! -d "$REPO" ]]
then
mkdir --parents "$USER"
cd "$USER"
git clone "https://github.com/$REPO.git"
cd Synology_HDD_db
else
cd "$REPO"
git switch "$BRANCH"
git pull --prune
fi
~curtis/src/sh/lt.sh ||:
get_rel_info # sets latest $tag
git switch --detach "tags/$tag"
~curtis/src/sh/lt.sh ||:
chmod u+x syno_hdd_db.sh
./syno_hdd_db.sh --help
#sudo ./syno_hdd_db.sh --noupdate --ram --showedits
}
get_rel_info() {
local release
if release=$(curl --silent --max-time 10 --connect-timeout 5 \
"https://api.github.com/repos/$REPO/releases/latest")
then
tag=$(jq --raw-output .tag_name <<<"$release")
else
echo "ERROR: Unable to fetch release info. Try again."
exit 1
fi >&2
}
main "$@"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment