Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions data/ci/bootstrap-github.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"

Expand Down Expand Up @@ -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"

Expand Down
38 changes: 34 additions & 4 deletions src/Ci/Setup/SudoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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)
);
Expand All @@ -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)
Expand All @@ -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)
);
Expand Down
Loading