diff --git a/data/ci/bootstrap-github.sh.template b/data/ci/bootstrap-github.sh.template index 249a981e..61869fbb 100644 --- a/data/ci/bootstrap-github.sh.template +++ b/data/ci/bootstrap-github.sh.template @@ -11,7 +11,7 @@ set -o pipefail # Configuration BOOTSTRAP_PHP_VERSION="{{PHP_VERSION}}" -COMPONENTS_PHAR_URL="{{COMPONENTS_PHAR_URL}}" +COMPONENTS_PHAR_URL="${COMPONENTS_PHAR_URL:-{{COMPONENTS_PHAR_URL}}}" COMPONENT_NAME="{{COMPONENT_NAME}}" WORK_DIR="{{WORK_DIR}}" @@ -98,19 +98,18 @@ if ! curl -sS -L -o "$COMPONENTS_PHAR" "$COMPONENTS_PHAR_URL"; then fi # Validate it's a valid phar -if ! php "$COMPONENTS_PHAR" --version &> /dev/null; then +if ! php "$COMPONENTS_PHAR" help &> /dev/null; then log_error "Downloaded phar is not valid or not executable" exit 1 fi log_info "horde-components.phar downloaded successfully" -php "$COMPONENTS_PHAR" --version # Stage 4: Handoff to PHP (horde-components ci setup) log_info "Bootstrap complete. Handing off to horde-components ci setup" php "$COMPONENTS_PHAR" ci setup \ - --mode=github \ + --ci-mode=github \ --work-dir="$WORK_DIR" \ --component="$COMPONENT_NAME" diff --git a/src/Ci/Setup/SudoHelper.php b/src/Ci/Setup/SudoHelper.php index b8591065..cb3ca813 100644 --- a/src/Ci/Setup/SudoHelper.php +++ b/src/Ci/Setup/SudoHelper.php @@ -35,6 +35,24 @@ class SudoHelper */ private const HELPER_SCRIPT = '/usr/local/bin/horde-ci-sudo-helper'; + /** + * Cached result of isRoot() check. + */ + private static ?bool $isRoot = null; + + /** + * Check if running as root user. + * + * @return bool + */ + public static function isRoot(): bool + { + if (self::$isRoot === null) { + self::$isRoot = posix_geteuid() === 0; + } + return self::$isRoot; + } + /** * Check if sudo helper is available. * @@ -52,6 +70,11 @@ public static function isAvailable(): bool */ public static function canRunPasswordless(): bool { + // Root doesn't need sudo + if (self::isRoot()) { + return true; + } + if (!self::isAvailable()) { return false; } @@ -72,7 +95,8 @@ public static function addPpa(): bool throw new Exception('Sudo helper not found: ' . self::HELPER_SCRIPT); } - $command = 'sudo ' . escapeshellarg(self::HELPER_SCRIPT) . ' add-ppa 2>&1'; + $sudo = self::isRoot() ? '' : 'sudo '; + $command = $sudo . escapeshellarg(self::HELPER_SCRIPT) . ' add-ppa 2>&1'; $output = []; $exitCode = 0; exec($command, $output, $exitCode); @@ -93,8 +117,10 @@ public static function installPhp(string $version): bool throw new Exception('Sudo helper not found: ' . self::HELPER_SCRIPT); } + $sudo = self::isRoot() ? '' : 'sudo '; $command = sprintf( - 'sudo %s install-php %s 2>&1', + '%s%s install-php %s 2>&1', + $sudo, escapeshellarg(self::HELPER_SCRIPT), escapeshellarg($version) ); @@ -120,8 +146,10 @@ public static function installExtension(string $phpVersion, string $extension): throw new Exception('Sudo helper not found: ' . self::HELPER_SCRIPT); } + $sudo = self::isRoot() ? '' : 'sudo '; $command = sprintf( - 'sudo %s install-extension %s %s 2>&1', + '%s%s install-extension %s %s 2>&1', + $sudo, escapeshellarg(self::HELPER_SCRIPT), escapeshellarg($phpVersion), escapeshellarg($extension) @@ -147,8 +175,10 @@ public static function isPhpInstalled(string $version): bool return file_exists("/usr/bin/php{$version}"); } + $sudo = self::isRoot() ? '' : 'sudo '; $command = sprintf( - 'sudo %s check-php %s 2>&1', + '%s%s check-php %s 2>&1', + $sudo, escapeshellarg(self::HELPER_SCRIPT), escapeshellarg($version) );