Skip to content

Commit f102ded

Browse files
bakerboy448claude
andcommitted
feat: add qbm-qbit + notifiarr-branch-builder scripts
Cherry-picked from xseed-improvements branch (PR #37) — keeping only the qbittorrent-manage + notifiarr-deploy helpers, not the xseed.sh work superseded by qui-xseed.sh on main. Inline fixes during cherry-pick: - qbm-qbit.sh: aligned QBQBM_* var names to consumer line (was defining QBQBM_VENV_PATH etc. but invoking unset $VENV_PATH etc.) - qbm-qbit.sh: removed unused QBQBM_LOCK_TIME - qbm-qbit.sh: fixed $LOCK reference in remove_lock (was unset) - notifiarr-branch-builder.sh: replaced unicode smart quotes (“/”, –) with ASCII equivalents so bash parses correctly Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bb8759e commit f102ded

2 files changed

Lines changed: 185 additions & 0 deletions

File tree

notifiarr-branch-builder.sh

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
2+
3+
# Extend the PATH to include the go binary directory
4+
export PATH=$PATH:/usr/local/go/bin
5+
6+
# Function to display error messages and exit with status 1
7+
handle_error() {
8+
echo "Error: $1" >&2
9+
exit 1
10+
}
11+
12+
# Function to display usage information
13+
display_help() {
14+
echo "Usage: $0 [options]"
15+
echo "Options:"
16+
echo " -h, --help Display this help message"
17+
echo " --repo-url URL Set the repository URL (default: https://github.com/Notifiarr/notifiarr.git)"
18+
echo " --repo-dir DIR Set the repository directory (default: /opt/notifiarr-repo)"
19+
echo " --bin-path PATH Set the binary path (default: /usr/bin/notifiarr)"
20+
echo " --branch BRANCH Set the branch (default: master)"
21+
echo " --reinstall-apt Reinstall Notifiarr using apt without prompting."
22+
exit 0
23+
}
24+
25+
# Function to check and prompt for installation of a required tool
26+
ensure_tool_installed() {
27+
local tool=$1
28+
local install_cmd=$2
29+
if ! command -v "$tool" &>/dev/null; then
30+
read -p "$tool is not installed. Do you want to install it? [Y/n] " response
31+
if [[ "$response" =~ ^[Yy] ]]; then
32+
eval "$install_cmd" || handle_error "Failed to install $tool."
33+
else
34+
echo "$tool is required for this script. Exiting."
35+
exit 1
36+
fi
37+
fi
38+
}
39+
40+
# Default parameters
41+
repo_url="https://github.com/Notifiarr/notifiarr.git"
42+
repo_dir="/opt/notifiarr-repo"
43+
bin_path="/usr/bin/notifiarr"
44+
branch="master"
45+
apt_reinstall=false
46+
47+
# Parse command line options
48+
while [[ $# -gt 0 ]]; do
49+
case "$1" in
50+
-h | --help)
51+
display_help
52+
;;
53+
--repo-url)
54+
repo_url="$2"
55+
shift
56+
;;
57+
--repo-dir)
58+
repo_dir="$2"
59+
shift
60+
;;
61+
--bin-path)
62+
bin_path="$2"
63+
shift
64+
;;
65+
--branch)
66+
branch="$2"
67+
shift
68+
;;
69+
--reinstall-apt)
70+
apt_reinstall=true
71+
;;
72+
*)
73+
echo "Invalid option: $1. Use -h for help."
74+
exit 1
75+
;;
76+
esac
77+
shift
78+
done
79+
80+
# Ensure required tools are installed
81+
ensure_tool_installed "make" "sudo apt update && sudo apt install -y make"
82+
83+
# Reinstallation condition handling
84+
reinstall_notifiarr() {
85+
sudo apt update && sudo apt install --reinstall notifiarr || handle_error "Failed to reinstall Notifiarr using apt."
86+
}
87+
88+
[[ $apt_reinstall == true ]] && reinstall_notifiarr
89+
90+
# Repository management
91+
if [[ ! -d "$repo_dir" ]]; then
92+
git clone "$repo_url" "$repo_dir" || handle_error "Failed to clone repository."
93+
else
94+
git -C "$repo_dir" fetch --all --prune || handle_error "Failed to fetch updates from remote."
95+
fi
96+
97+
# Branch handling and updating
98+
current_branch=$(git -C "$repo_dir" rev-parse --abbrev-ref HEAD)
99+
read -p "Do you want to use the current branch ($current_branch)? [Y/n] " choice
100+
if [[ "$choice" =~ ^[Nn] ]]; then
101+
branches=$(git -C "$repo_dir" branch -r | sed 's/origin\///;s/* //')
102+
echo "Available branches:"
103+
echo "$branches"
104+
while true; do
105+
read -p "Enter the branch name you want to use: " branch
106+
if [[ $branches =~ $branch ]]; then
107+
git -C "$repo_dir" checkout "$branch" || handle_error "Failed to checkout branch $branch."
108+
break
109+
else
110+
echo "Invalid choice. Please select a valid branch."
111+
fi
112+
done
113+
fi
114+
115+
git -C "$repo_dir" pull || handle_error "Failed to pull latest changes."
116+
make --directory="$repo_dir" || handle_error "Failed to compile."
117+
118+
# Service management
119+
echo "Stopping notifiarr..."
120+
sudo systemctl stop notifiarr
121+
122+
if [[ -f "$bin_path" ]]; then
123+
sudo mv "$bin_path" "$repo_dir".old && echo "Old binary moved to $repo_dir.old"
124+
fi
125+
126+
sudo mv "$repo_dir/notifiarr" "$bin_path" && echo "New binary moved to $bin_path"
127+
sudo chown root:root "$bin_path"
128+
129+
echo "Starting Notifiarr..."
130+
sudo systemctl start notifiarr
131+
132+
if sudo systemctl is-active --quiet notifiarr; then
133+
echo "Notifiarr service started and is currently running"
134+
else
135+
handle_error "Failed to start Notifiarr service"
136+
fi
137+
138+
exit 0

qbm-qbit.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# Check if lockfile command exists
4+
if ! command -v lockfile &>/dev/null; then
5+
echo "Error: lockfile command not found. Please install the procmail package." >&2
6+
exit 1
7+
fi
8+
9+
# Load environment variables from .env file if it exists
10+
if [ -f ".env" ]; then
11+
source ".env"
12+
fi
13+
14+
# Use environment variables with descriptive default values
15+
QBQBM_LOCK=${QBIT_MANAGE_LOCK_FILE_PATH:-/var/lock/qbm-qbit.lock}
16+
QBQBM_PATH_QBM=${QBIT_MANAGE_PATH:-/opt/qbit-manage}
17+
QBQBM_VENV_PATH=${QBIT_MANAGE_VENV_PATH:-/opt/qbit-manage/.venv}
18+
QBQBM_CONFIG_PATH=${QBIT_MANAGE_CONFIG_PATH:-/opt/qbit-manage/config.yml}
19+
QBQBM_QBIT_OPTIONS=${QBIT_MANAGE_OPTIONS:-"-cs -re -cu -tu -ru -sl -r"}
20+
QBQBM_SLEEP_TIME=600
21+
22+
# Function to remove the lock file
23+
remove_lock() {
24+
rm -f "$QBQBM_LOCK"
25+
}
26+
27+
# Function to handle detection of another running instance
28+
another_instance() {
29+
echo "There is another instance running, exiting."
30+
exit 1
31+
}
32+
33+
echo "Acquiring Lock"
34+
# Acquire a lock to prevent concurrent execution, with a timeout and lease time
35+
lockfile -r 0 -l "$QBQBM_SLEEP_TIME" "$QBQBM_LOCK" || another_instance
36+
37+
# Ensure the lock is removed when the script exits
38+
trap remove_lock EXIT
39+
40+
echo "sleeping for $QBQBM_SLEEP_TIME"
41+
# Pause the script to wait for any pending operations (i.e. Starr Imports)
42+
43+
sleep $QBQBM_SLEEP_TIME
44+
45+
# Execute qbit_manage with configurable options
46+
echo "Executing Command"
47+
"$QBQBM_VENV_PATH"/bin/python "$QBQBM_PATH_QBM"/qbit_manage.py "$QBQBM_QBIT_OPTIONS" --config-file "$QBQBM_CONFIG_PATH"

0 commit comments

Comments
 (0)