Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ REPO="CS-Foundry/CSF-Core"
INSTALL_DIR="/opt/csf-core"
STATUS_FILE="/tmp/csf-core-update-status.json"

# Determine if we need sudo early
if [ "$EUID" -eq 0 ]; then
SUDO=""
else
SUDO="sudo"
fi

# Function to find a writable backup directory
find_backup_dir() {
local timestamp=$(date +%s)
Expand All @@ -28,13 +35,11 @@ find_backup_dir() {
fi
done

# If nothing works, return empty and we'll skip backup
# If nothing works, return empty
echo ""
return 1
}

BACKUP_DIR=$(find_backup_dir)

log() {
local message="$1"
local progress="${2:-0}"
Expand Down Expand Up @@ -76,21 +81,11 @@ if [ -z "$VERSION" ]; then
fi

log "🚀 Starting CSF-Core update to version ${VERSION}..." 5

# Check if running as root or with sudo
if [ "$EUID" -eq 0 ]; then
SUDO=""
log "✓ Running with root privileges" 10
else
SUDO="sudo"
log "✓ Running with sudo" 10
fi
log "✓ Running with $([ "$EUID" -eq 0 ] && echo 'root privileges' || echo 'sudo')" 10

# Try to find/create a writable backup directory
if [ -z "$BACKUP_DIR" ]; then
log "📦 Trying to create backup directory..." 12
BACKUP_DIR=$(find_backup_dir)
fi
log "📦 Trying to create backup directory..." 12
BACKUP_DIR=$(find_backup_dir)

if [ -z "$BACKUP_DIR" ]; then
error "Failed to create backup directory. Tried: /tmp, /var/tmp, ${HOME}, /opt. Update aborted for safety."
Expand Down
Loading