|
#!/bin/bash |
|
|
|
# --- Configuration --- |
|
GTS_TARGET="linux_amd64" |
|
INSTALL_DIR="/gotosocial" |
|
BACKUP_DIR="$INSTALL_DIR/backups" |
|
GTS_DB_PATH="/var/lib/gotosocial/gts.db" |
|
|
|
# Move into the installation directory |
|
cd "$INSTALL_DIR" || exit 1 |
|
|
|
# --- Argument Parsing --- |
|
APPROVED=false |
|
FORCE=false |
|
|
|
for arg in "$@"; do |
|
case $arg in |
|
--approved) APPROVED=true ;; |
|
--force) FORCE=true ;; |
|
esac |
|
done |
|
|
|
# Function to handle execution logic |
|
run() { |
|
local desc=$1 |
|
local cmd=$2 |
|
if [ "$APPROVED" = true ]; then |
|
echo -e "\e[32m[EXECUTING]\e[0m $desc" |
|
if ! eval "$cmd"; then |
|
echo -e "\e[31m[ERROR]\e[0m Command failed: $desc. Aborting." |
|
exit 1 |
|
fi |
|
else |
|
echo -e "\e[33m[DRY RUN]\e[0m $desc" |
|
echo -e " Command: \e[2m$cmd\e[0m" |
|
fi |
|
} |
|
|
|
echo "--- Checking for Updates ---" |
|
|
|
# 1. Fetch Latest Version from Codeberg |
|
RAW_VERSION=$(curl -s https://codeberg.org/api/v1/repos/superseriousbusiness/gotosocial/releases/latest | jq -r .tag_name) |
|
GTS_VERSION="${RAW_VERSION#v}" |
|
|
|
if [[ -z "$GTS_VERSION" || "$GTS_VERSION" == "null" ]]; then |
|
echo "Error: Could not retrieve version from Codeberg." |
|
exit 1 |
|
fi |
|
|
|
# 2. Check Local Version |
|
if [[ -f "./gotosocial" ]]; then |
|
LOCAL_VERSION=$(./gotosocial --version | awk '{print $3}') |
|
echo "Local Version: $LOCAL_VERSION" |
|
echo "Remote Version: $GTS_VERSION" |
|
|
|
if [[ "$LOCAL_VERSION" == *"$GTS_VERSION"* ]]; then |
|
if [ "$FORCE" = true ]; then |
|
echo -e "\e[35m[FORCE]\e[0m Version match detected, but --force is active. Proceeding..." |
|
else |
|
echo -e "\e[32m✔ You are already running the latest version ($GTS_VERSION).\e[0m" |
|
exit 0 |
|
fi |
|
fi |
|
else |
|
echo "Local binary not found. Proceeding with fresh install." |
|
fi |
|
|
|
# Filenames |
|
ARCHIVE_NAME="gotosocial_${GTS_VERSION}_${GTS_TARGET}.tar.gz" |
|
CHECKSUM_FILE="checksums.txt" |
|
TIMESTAMP=$(date +%Y-%m-%d_%H-%M-%S) |
|
BACKUP_FILE="$BACKUP_DIR/gts.db_$TIMESTAMP.db" |
|
|
|
if [ "$APPROVED" = false ]; then |
|
echo -e "\n\e[1m*** UPGRADE PLAN: DRY RUN MODE ***\e[0m" |
|
echo -e "Review commands below, then run with \e[32m--approved\e[0m to execute.\n" |
|
fi |
|
|
|
# 3. Upgrade Steps |
|
run "Downloading archive" "wget -q --show-progress -O $ARCHIVE_NAME https://codeberg.org/superseriousbusiness/gotosocial/releases/download/v${GTS_VERSION}/${ARCHIVE_NAME}" |
|
run "Downloading checksums" "wget -q -O $CHECKSUM_FILE https://codeberg.org/superseriousbusiness/gotosocial/releases/download/v${GTS_VERSION}/checksums.txt" |
|
run "Verifying SHA256" "grep '$ARCHIVE_NAME' '$CHECKSUM_FILE' | sha256sum -c -" |
|
run "Creating backup directory" "mkdir -p '$BACKUP_DIR'" |
|
run "Backing up database" "sqlite3 '$GTS_DB_PATH' \".backup '$BACKUP_FILE'\"" |
|
run "Stopping service" "sudo systemctl stop gotosocial" |
|
run "Extracting binary" "tar -xzf '$ARCHIVE_NAME' gotosocial" |
|
run "Setting permissions" "chown root:root gotosocial && chmod +x gotosocial" |
|
run "Cleaning up files" "rm '$ARCHIVE_NAME' '$CHECKSUM_FILE'" |
|
run "Restarting service" "sudo systemctl start gotosocial" |
|
run "Verifying status" "sudo systemctl status gotosocial --no-pager" |