From 04522d3093eb15f5dffd55b2a6f7654623d61ebe Mon Sep 17 00:00:00 2001 From: denshooter Date: Wed, 15 Oct 2025 15:10:10 +0200 Subject: [PATCH] Fix CI/CD root user error in deployment scripts - Modify root checks to allow running as root in CI environments - Add conditional check: only prevent root when not in CI (CI env var not set) - Updated scripts: - scripts/gitea-deploy.sh - scripts/gitea-deploy-simple.sh - scripts/deploy.sh - scripts/auto-deploy.sh - scripts/setup-gitea-runner.sh This fixes the 'This script should not be run as root' error in Gitea Actions where containers run as root by default. --- scripts/auto-deploy.sh | 6 +++--- scripts/deploy.sh | 6 +++--- scripts/gitea-deploy-simple.sh | 6 +++--- scripts/gitea-deploy.sh | 6 +++--- scripts/setup-gitea-runner.sh | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/auto-deploy.sh b/scripts/auto-deploy.sh index e6d3b31..19e2313 100755 --- a/scripts/auto-deploy.sh +++ b/scripts/auto-deploy.sh @@ -37,9 +37,9 @@ warning() { echo -e "${YELLOW}[WARNING]${NC} $1" | tee -a "$LOG_FILE" } -# Check if running as root -if [[ $EUID -eq 0 ]]; then - error "This script should not be run as root" +# Check if running as root (skip in CI environments) +if [[ $EUID -eq 0 ]] && [[ -z "$CI" ]]; then + error "This script should not be run as root (use CI=true to override)" exit 1 fi diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 0e3221e..cde6d1c 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -36,9 +36,9 @@ warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } -# Check if running as root -if [[ $EUID -eq 0 ]]; then - error "This script should not be run as root" +# Check if running as root (skip in CI environments) +if [[ $EUID -eq 0 ]] && [[ -z "$CI" ]]; then + error "This script should not be run as root (use CI=true to override)" exit 1 fi diff --git a/scripts/gitea-deploy-simple.sh b/scripts/gitea-deploy-simple.sh index a8577d6..f160bdb 100755 --- a/scripts/gitea-deploy-simple.sh +++ b/scripts/gitea-deploy-simple.sh @@ -37,9 +37,9 @@ warning() { echo -e "${YELLOW}[WARNING]${NC} $1" | tee -a "$LOG_FILE" } -# Check if running as root -if [[ $EUID -eq 0 ]]; then - error "This script should not be run as root" +# Check if running as root (skip in CI environments) +if [[ $EUID -eq 0 ]] && [[ -z "$CI" ]]; then + error "This script should not be run as root (use CI=true to override)" exit 1 fi diff --git a/scripts/gitea-deploy.sh b/scripts/gitea-deploy.sh index 2db54e6..9aac747 100755 --- a/scripts/gitea-deploy.sh +++ b/scripts/gitea-deploy.sh @@ -37,9 +37,9 @@ warning() { echo -e "${YELLOW}[WARNING]${NC} $1" | tee -a "$LOG_FILE" } -# Check if running as root -if [[ $EUID -eq 0 ]]; then - error "This script should not be run as root" +# Check if running as root (skip in CI environments) +if [[ $EUID -eq 0 ]] && [[ -z "$CI" ]]; then + error "This script should not be run as root (use CI=true to override)" exit 1 fi diff --git a/scripts/setup-gitea-runner.sh b/scripts/setup-gitea-runner.sh index 37148e0..418655d 100755 --- a/scripts/setup-gitea-runner.sh +++ b/scripts/setup-gitea-runner.sh @@ -35,9 +35,9 @@ warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } -# Check if running as root -if [[ $EUID -eq 0 ]]; then - error "This script should not be run as root" +# Check if running as root (skip in CI environments) +if [[ $EUID -eq 0 ]] && [[ -z "$CI" ]]; then + error "This script should not be run as root (use CI=true to override)" exit 1 fi