-
Notifications
You must be signed in to change notification settings - Fork 8
feat: cherry-pick qbm-qbit + notifiarr-branch-builder from #37 #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,138 @@ | ||||||||||||
| #!/bin/bash | ||||||||||||
|
|
||||||||||||
| # Extend the PATH to include the go binary directory | ||||||||||||
| export PATH=$PATH:/usr/local/go/bin | ||||||||||||
|
|
||||||||||||
| # Function to display error messages and exit with status 1 | ||||||||||||
| handle_error() { | ||||||||||||
| echo "Error: $1" >&2 | ||||||||||||
| exit 1 | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| # Function to display usage information | ||||||||||||
| display_help() { | ||||||||||||
| echo "Usage: $0 [options]" | ||||||||||||
| echo "Options:" | ||||||||||||
| echo " -h, --help Display this help message" | ||||||||||||
| echo " --repo-url URL Set the repository URL (default: https://github.com/Notifiarr/notifiarr.git)" | ||||||||||||
| echo " --repo-dir DIR Set the repository directory (default: /opt/notifiarr-repo)" | ||||||||||||
| echo " --bin-path PATH Set the binary path (default: /usr/bin/notifiarr)" | ||||||||||||
| echo " --branch BRANCH Set the branch (default: master)" | ||||||||||||
| echo " --reinstall-apt Reinstall Notifiarr using apt without prompting." | ||||||||||||
| exit 0 | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| # Function to check and prompt for installation of a required tool | ||||||||||||
| ensure_tool_installed() { | ||||||||||||
| local tool=$1 | ||||||||||||
| local install_cmd=$2 | ||||||||||||
| if ! command -v "$tool" &>/dev/null; then | ||||||||||||
| read -p "$tool is not installed. Do you want to install it? [Y/n] " response | ||||||||||||
| if [[ "$response" =~ ^[Yy] ]]; then | ||||||||||||
|
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix default behavior to match prompt convention. The prompt uses 🔧 Proposed fix to accept empty input as yes- read -p "$tool is not installed. Do you want to install it? [Y/n] " response
- if [[ "$response" =~ ^[Yy] ]]; then
+ read -p "$tool is not installed. Do you want to install it? [Y/n] " response
+ if [[ -z "$response" || "$response" =~ ^[Yy] ]]; then
eval "$install_cmd" || handle_error "Failed to install $tool."📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| eval "$install_cmd" || handle_error "Failed to install $tool." | ||||||||||||
| else | ||||||||||||
| echo "$tool is required for this script. Exiting." | ||||||||||||
| exit 1 | ||||||||||||
| fi | ||||||||||||
| fi | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| # Default parameters | ||||||||||||
| repo_url="https://github.com/Notifiarr/notifiarr.git" | ||||||||||||
| repo_dir="/opt/notifiarr-repo" | ||||||||||||
| bin_path="/usr/bin/notifiarr" | ||||||||||||
| branch="master" | ||||||||||||
| apt_reinstall=false | ||||||||||||
|
|
||||||||||||
| # Parse command line options | ||||||||||||
| while [[ $# -gt 0 ]]; do | ||||||||||||
| case "$1" in | ||||||||||||
| -h | --help) | ||||||||||||
| display_help | ||||||||||||
| ;; | ||||||||||||
| --repo-url) | ||||||||||||
| repo_url="$2" | ||||||||||||
| shift | ||||||||||||
| ;; | ||||||||||||
| --repo-dir) | ||||||||||||
| repo_dir="$2" | ||||||||||||
| shift | ||||||||||||
| ;; | ||||||||||||
| --bin-path) | ||||||||||||
| bin_path="$2" | ||||||||||||
| shift | ||||||||||||
| ;; | ||||||||||||
| --branch) | ||||||||||||
| branch="$2" | ||||||||||||
| shift | ||||||||||||
| ;; | ||||||||||||
| --reinstall-apt) | ||||||||||||
| apt_reinstall=true | ||||||||||||
| ;; | ||||||||||||
| *) | ||||||||||||
| echo "Invalid option: $1. Use -h for help." | ||||||||||||
| exit 1 | ||||||||||||
| ;; | ||||||||||||
| esac | ||||||||||||
| shift | ||||||||||||
| done | ||||||||||||
|
|
||||||||||||
| # Ensure required tools are installed | ||||||||||||
| ensure_tool_installed "make" "sudo apt update && sudo apt install -y make" | ||||||||||||
|
|
||||||||||||
| # Reinstallation condition handling | ||||||||||||
| reinstall_notifiarr() { | ||||||||||||
| sudo apt update && sudo apt install --reinstall notifiarr || handle_error "Failed to reinstall Notifiarr using apt." | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| [[ $apt_reinstall == true ]] && reinstall_notifiarr | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | 💤 Low value Quote variable in conditional for consistency. While ♻️ Proposed fix-[[ $apt_reinstall == true ]] && reinstall_notifiarr
+[[ "$apt_reinstall" == true ]] && reinstall_notifiarr📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| # Repository management | ||||||||||||
| if [[ ! -d "$repo_dir" ]]; then | ||||||||||||
| git clone "$repo_url" "$repo_dir" || handle_error "Failed to clone repository." | ||||||||||||
| else | ||||||||||||
| git -C "$repo_dir" fetch --all --prune || handle_error "Failed to fetch updates from remote." | ||||||||||||
| fi | ||||||||||||
|
|
||||||||||||
| # Branch handling and updating | ||||||||||||
| current_branch=$(git -C "$repo_dir" rev-parse --abbrev-ref HEAD) | ||||||||||||
| read -p "Do you want to use the current branch ($current_branch)? [Y/n] " choice | ||||||||||||
| if [[ "$choice" =~ ^[Nn] ]]; then | ||||||||||||
| branches=$(git -C "$repo_dir" branch -r | sed 's/origin\///;s/* //') | ||||||||||||
| echo "Available branches:" | ||||||||||||
| echo "$branches" | ||||||||||||
| while true; do | ||||||||||||
| read -p "Enter the branch name you want to use: " branch | ||||||||||||
| if [[ $branches =~ $branch ]]; then | ||||||||||||
| git -C "$repo_dir" checkout "$branch" || handle_error "Failed to checkout branch $branch." | ||||||||||||
| break | ||||||||||||
| else | ||||||||||||
| echo "Invalid choice. Please select a valid branch." | ||||||||||||
| fi | ||||||||||||
| done | ||||||||||||
| fi | ||||||||||||
|
Comment on lines
+97
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix branch handling logic and --branch parameter usage. Two issues with the branch selection:
🔧 Proposed fix to honor --branch parameter and improve validation # Branch handling and updating
current_branch=$(git -C "$repo_dir" rev-parse --abbrev-ref HEAD)
-read -p "Do you want to use the current branch ($current_branch)? [Y/n] " choice
-if [[ "$choice" =~ ^[Nn] ]]; then
+
+# Honor --branch parameter if provided and different from current
+if [[ "$branch" != "master" && "$branch" != "$current_branch" ]]; then
+ # --branch was explicitly set via CLI
+ git -C "$repo_dir" checkout "$branch" || handle_error "Failed to checkout branch $branch."
+else
+ # Interactive branch selection
+ read -p "Do you want to use the current branch ($current_branch)? [Y/n] " choice
+ if [[ "$choice" =~ ^[Nn] ]]; then
branches=$(git -C "$repo_dir" branch -r | sed 's/origin\///;s/* //')
echo "Available branches:"
echo "$branches"
while true; do
read -p "Enter the branch name you want to use: " branch
- if [[ $branches =~ $branch ]]; then
+ # Use grep for exact line match instead of substring
+ if echo "$branches" | grep -qxF "$branch"; then
git -C "$repo_dir" checkout "$branch" || handle_error "Failed to checkout branch $branch."
break
else
echo "Invalid choice. Please select a valid branch."
fi
done
+ fi
fi🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| git -C "$repo_dir" pull || handle_error "Failed to pull latest changes." | ||||||||||||
| make --directory="$repo_dir" || handle_error "Failed to compile." | ||||||||||||
|
|
||||||||||||
| # Service management | ||||||||||||
| echo "Stopping notifiarr..." | ||||||||||||
| sudo systemctl stop notifiarr | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | 💤 Low value Consider adding error handling for service stop. While ♻️ Proposed fix echo "Stopping notifiarr..."
-sudo systemctl stop notifiarr
+sudo systemctl stop notifiarr || echo "Warning: Failed to stop notifiarr service" >&2📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| if [[ -f "$bin_path" ]]; then | ||||||||||||
| sudo mv "$bin_path" "$repo_dir".old && echo "Old binary moved to $repo_dir.old" | ||||||||||||
| fi | ||||||||||||
|
|
||||||||||||
| sudo mv "$repo_dir/notifiarr" "$bin_path" && echo "New binary moved to $bin_path" | ||||||||||||
| sudo chown root:root "$bin_path" | ||||||||||||
|
|
||||||||||||
| echo "Starting Notifiarr..." | ||||||||||||
| sudo systemctl start notifiarr | ||||||||||||
|
|
||||||||||||
| if sudo systemctl is-active --quiet notifiarr; then | ||||||||||||
| echo "Notifiarr service started and is currently running" | ||||||||||||
| else | ||||||||||||
| handle_error "Failed to start Notifiarr service" | ||||||||||||
| fi | ||||||||||||
|
|
||||||||||||
| exit 0 | ||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||||
| #!/bin/bash | ||||||
|
|
||||||
| # Check if lockfile command exists | ||||||
| if ! command -v lockfile &>/dev/null; then | ||||||
| echo "Error: lockfile command not found. Please install the procmail package." >&2 | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| # Load environment variables from .env file if it exists | ||||||
| if [ -f ".env" ]; then | ||||||
| source ".env" | ||||||
|
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use script directory for .env path, not current working directory. The relative path 🔧 Proposed fix to make .env path relative to script directory+# Get the script's directory
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
# Load environment variables from .env file if it exists
-if [ -f ".env" ]; then
- source ".env"
+if [ -f "$SCRIPT_DIR/.env" ]; then
+ source "$SCRIPT_DIR/.env"
fi🤖 Prompt for AI Agents |
||||||
| fi | ||||||
|
|
||||||
| # Use environment variables with descriptive default values | ||||||
| QBQBM_LOCK=${QBIT_MANAGE_LOCK_FILE_PATH:-/var/lock/qbm-qbit.lock} | ||||||
| QBQBM_PATH_QBM=${QBIT_MANAGE_PATH:-/opt/qbit-manage} | ||||||
| QBQBM_VENV_PATH=${QBIT_MANAGE_VENV_PATH:-/opt/qbit-manage/.venv} | ||||||
| QBQBM_CONFIG_PATH=${QBIT_MANAGE_CONFIG_PATH:-/opt/qbit-manage/config.yml} | ||||||
| QBQBM_QBIT_OPTIONS=${QBIT_MANAGE_OPTIONS:-"-cs -re -cu -tu -ru -sl -r"} | ||||||
| QBQBM_SLEEP_TIME=600 | ||||||
|
|
||||||
| # Function to remove the lock file | ||||||
| remove_lock() { | ||||||
| rm -f "$QBQBM_LOCK" | ||||||
| } | ||||||
|
|
||||||
| # Function to handle detection of another running instance | ||||||
| another_instance() { | ||||||
| echo "There is another instance running, exiting." | ||||||
| exit 1 | ||||||
| } | ||||||
|
|
||||||
| echo "Acquiring Lock" | ||||||
| # Acquire a lock to prevent concurrent execution, with a timeout and lease time | ||||||
| lockfile -r 0 -l "$QBQBM_SLEEP_TIME" "$QBQBM_LOCK" || another_instance | ||||||
|
|
||||||
| # Ensure the lock is removed when the script exits | ||||||
| trap remove_lock EXIT | ||||||
|
|
||||||
| echo "sleeping for $QBQBM_SLEEP_TIME" | ||||||
| # Pause the script to wait for any pending operations (i.e. Starr Imports) | ||||||
|
|
||||||
| sleep $QBQBM_SLEEP_TIME | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | 💤 Low value Quote variable expansion for consistency. While numeric values don't require quoting for word-splitting safety, quoting all variable expansions is a shell scripting best practice. ♻️ Proposed fix-sleep $QBQBM_SLEEP_TIME
+sleep "$QBQBM_SLEEP_TIME"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| # Execute qbit_manage with configurable options | ||||||
| echo "Executing Command" | ||||||
| "$QBQBM_VENV_PATH"/bin/python "$QBQBM_PATH_QBM"/qbit_manage.py "$QBQBM_QBIT_OPTIONS" --config-file "$QBQBM_CONFIG_PATH" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Consider using an array for options to handle edge cases. The unquoted ♻️ More robust approach using arraysReplace the variable definition (line 19) and usage (line 47): -QBQBM_QBIT_OPTIONS=${QBIT_MANAGE_OPTIONS:-"-cs -re -cu -tu -ru -sl -r"}
+# shellcheck disable=SC2206
+QBQBM_QBIT_OPTIONS=(${QBIT_MANAGE_OPTIONS:-"-cs -re -cu -tu -ru -sl -r"})-"$QBQBM_VENV_PATH"/bin/python "$QBQBM_PATH_QBM"/qbit_manage.py "$QBQBM_QBIT_OPTIONS" --config-file "$QBQBM_CONFIG_PATH"
+"$QBQBM_VENV_PATH"/bin/python "$QBQBM_PATH_QBM"/qbit_manage.py "${QBQBM_QBIT_OPTIONS[@]}" --config-file "$QBQBM_CONFIG_PATH"Note: The 🤖 Prompt for AI Agents |
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial | 💤 Low value
Quote PATH expansion for robustness.
While PATH rarely contains spaces, quoting variable expansions is a shell scripting best practice.
♻️ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents