refactor the update
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2016
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
@@ -41,6 +42,62 @@ resolve_php_bin() {
|
||||
echo "php"
|
||||
}
|
||||
|
||||
resolve_configured_php_bin() {
|
||||
local configured="${1:-}"
|
||||
local current="${2:-php}"
|
||||
local trimmed="$configured"
|
||||
trimmed="${trimmed#"${trimmed%%[![:space:]]*}"}"
|
||||
trimmed="${trimmed%"${trimmed##*[![:space:]]}"}"
|
||||
|
||||
if [[ -z "$trimmed" ]]; then
|
||||
echo "$current"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "$trimmed" == "keyhelp-php-domain" ]]; then
|
||||
if command -v keyhelp-php-domain >/dev/null 2>&1; then
|
||||
echo "keyhelp-php-domain"
|
||||
return
|
||||
fi
|
||||
if command -v keyhelp-php84 >/dev/null 2>&1; then
|
||||
echo "keyhelp-php84"
|
||||
return
|
||||
fi
|
||||
if command -v php >/dev/null 2>&1; then
|
||||
echo "php"
|
||||
return
|
||||
fi
|
||||
echo "$current"
|
||||
return
|
||||
fi
|
||||
|
||||
if command -v "$trimmed" >/dev/null 2>&1; then
|
||||
echo "$trimmed"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "$trimmed" == */* && -x "$trimmed" ]]; then
|
||||
echo "$trimmed"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "$current"
|
||||
}
|
||||
|
||||
read_setting_php_bin() {
|
||||
if [[ ! -f artisan ]]; then
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
"$PHP_BIN" -r '
|
||||
require "vendor/autoload.php";
|
||||
$app = require "bootstrap/app.php";
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
$value = (string) \App\Models\Setting::where("key", "system.php_binary")->value("value");
|
||||
echo trim($value);
|
||||
' 2>/dev/null || true
|
||||
}
|
||||
|
||||
PHP_BIN="$(resolve_php_bin)"
|
||||
echo "Resolved PHP binary: $PHP_BIN"
|
||||
if command -v "$PHP_BIN" >/dev/null 2>&1; then
|
||||
@@ -55,18 +112,10 @@ if [[ -z "$COMPOSER_BIN" ]]; then
|
||||
echo "Composer not found in PATH."
|
||||
exit 1
|
||||
fi
|
||||
$PHP_BIN "$COMPOSER_BIN" install --no-dev --optimize-autoloader
|
||||
"$PHP_BIN" "$COMPOSER_BIN" install --no-dev --optimize-autoloader
|
||||
|
||||
if [[ -x "artisan" ]]; then
|
||||
CONFIGURED_PHP="$($PHP_BIN artisan tinker --execute="echo \\App\\Models\\Setting::where('key','system.php_binary')->value('value') ?? '';" 2>/dev/null || true)"
|
||||
if [[ -n "$CONFIGURED_PHP" ]]; then
|
||||
if command -v "$CONFIGURED_PHP" >/dev/null 2>&1; then
|
||||
PHP_BIN="$CONFIGURED_PHP"
|
||||
elif [[ -x "$CONFIGURED_PHP" ]]; then
|
||||
PHP_BIN="$CONFIGURED_PHP"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
CONFIGURED_PHP="$(read_setting_php_bin)"
|
||||
PHP_BIN="$(resolve_configured_php_bin "$CONFIGURED_PHP" "$PHP_BIN")"
|
||||
|
||||
echo "Final PHP binary: $PHP_BIN"
|
||||
if command -v "$PHP_BIN" >/dev/null 2>&1; then
|
||||
@@ -80,16 +129,16 @@ echo "Building assets..."
|
||||
npm run build
|
||||
|
||||
echo "Running migrations..."
|
||||
$PHP_BIN artisan migrate --force
|
||||
"$PHP_BIN" artisan migrate --force
|
||||
|
||||
echo "Syncing version/build to settings..."
|
||||
VERSION="$($PHP_BIN -r '$c=json_decode(file_get_contents("composer.json"), true); echo $c["version"] ?? "";')"
|
||||
BUILD="$($PHP_BIN -r '$c=json_decode(file_get_contents("composer.json"), true); echo $c["build"] ?? "";')"
|
||||
VERSION="$("$PHP_BIN" -r '$c=json_decode(file_get_contents("composer.json"), true); echo $c["version"] ?? "";')"
|
||||
BUILD="$("$PHP_BIN" -r '$c=json_decode(file_get_contents("composer.json"), true); echo $c["build"] ?? "";')"
|
||||
echo "Computed from composer.json: VERSION=$VERSION, BUILD=$BUILD"
|
||||
|
||||
if [[ -n "$VERSION" || -n "$BUILD" ]]; then
|
||||
echo "Updating settings version/build (VERSION=$VERSION, BUILD=$BUILD)..."
|
||||
SPEEDBB_VERSION="$VERSION" SPEEDBB_BUILD="$BUILD" $PHP_BIN -r '
|
||||
SPEEDBB_VERSION="$VERSION" SPEEDBB_BUILD="$BUILD" "$PHP_BIN" -r '
|
||||
require "vendor/autoload.php";
|
||||
$app = require "bootstrap/app.php";
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
@@ -116,7 +165,7 @@ if [[ -n "$VERSION" || -n "$BUILD" ]]; then
|
||||
echo "Updated build rows: {$updated}\n";
|
||||
}
|
||||
' \
|
||||
&& $PHP_BIN -r '
|
||||
&& "$PHP_BIN" -r '
|
||||
require "vendor/autoload.php";
|
||||
$app = require "bootstrap/app.php";
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
|
||||
Reference in New Issue
Block a user