From 938aafd36e2f0d38bd449c1e573357453919624c Mon Sep 17 00:00:00 2001 From: hardliner66 Date: Fri, 29 Apr 2022 09:33:51 +0200 Subject: [PATCH 1/2] change scripts to be independent from the working directory --- build/build-iso.ps1 | 15 +++++++++++++-- build/build-iso.sh | 11 ++++++++++- build/sync.ps1 | 29 ++++++++++++++++++++--------- build/sync.sh | 13 ++++++++++++- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/build/build-iso.ps1 b/build/build-iso.ps1 index dea56ad5..52b4e147 100755 --- a/build/build-iso.ps1 +++ b/build/build-iso.ps1 @@ -1,6 +1,17 @@ -if (!((Split-Path -Path (Get-Location) -Leaf) -eq "build")) +# make sure we are in the correct directory +$currentDir=Get-Location +if ("$currentDir" -ne "$PSScriptRoot") { - Write-Output "This script must be run inside the build folder. Press ENTER to exit."; Read-Host; exit + try + { + pushd "$PSScriptRoot" + . $PSCommandPath + } + finally + { + popd + } + exit } if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) diff --git a/build/build-iso.sh b/build/build-iso.sh index c5900179..6b13b8b7 100755 --- a/build/build-iso.sh +++ b/build/build-iso.sh @@ -2,7 +2,16 @@ # Build Distro ISO using AUTO.ISO minimal auto-install as bootstrap to merge codebase, recompile system, and export ISO -# Run this script inside build/ directory +# make sure we are in the correct directory +SCRIPT_DIR=$(realpath "$(dirname "$0")") +SCRIPT_NAME=$(basename "$0") +EXPECTED_DIR=$(realpath "$PWD") + +if test "${EXPECTED_DIR}" != "${SCRIPT_DIR}" +then + ( cd "$SCRIPT_DIR" || exit ; "./$SCRIPT_NAME" ); + exit +fi # Uncomment if you use doas instead of sudo #alias sudo=doas diff --git a/build/sync.ps1 b/build/sync.ps1 index 1338aee7..fb8505e6 100755 --- a/build/sync.ps1 +++ b/build/sync.ps1 @@ -1,4 +1,20 @@ -$choice = $args[0] +# make sure we are in the correct directory +$currentDir=Get-Location +if ("$currentDir" -ne "$PSScriptRoot") +{ + try + { + pushd "$PSScriptRoot" + . $PSCommandPath + } + finally + { + popd + } + exit +} + +$choice = $args[0] function print_usage() { @@ -19,11 +35,6 @@ if ($choice -ne 'repo' -and $choice -ne "vm") print_usage } -if (!((Split-Path -Path (Get-Location) -Leaf) -eq "build")) -{ - Write-Output "This script must be run inside the build folder. Press ENTER to exit."; Read-Host; exit -} - if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Output "This script must be run as Adminstrator. Press ENTER to exit."; Read-Host; exit @@ -41,9 +52,9 @@ Write-Output "QEMU installation found." # Set this $ZEALDISK="" -# Examples: -#$ZEALDISK = "$HOME\VirtualBox VMs\ZEAL\ZEAL.vdi" -#$ZEALDISK="$HOME\vmware\ZealOS\ZealOS.vmdk" +# Examples: +#$ZEALDISK = "$HOME\VirtualBox VMs\ZEAL\ZEAL.vdi" +#$ZEALDISK="$HOME\vmware\ZealOS\ZealOS.vmdk" #$ZEALDISK="ZealOS.qcow2" if ($ZEALDISK -eq "") diff --git a/build/sync.sh b/build/sync.sh index a8d4af1d..22ecc9a2 100755 --- a/build/sync.sh +++ b/build/sync.sh @@ -1,12 +1,23 @@ #!/bin/sh # # Sync VM <--> Repo. -# Run this script inside build/ directory. # # On copying from virtual disk to src/, the directory is emptied before copy. Comment out "rm -rf ../src/*" to copy onto src. # # +# make sure we are in the correct directory +SCRIPT_DIR=$(realpath "$(dirname "$0")") +SCRIPT_NAME=$(basename "$0") +EXPECTED_DIR=$(realpath "$PWD") + +if test "${EXPECTED_DIR}" != "${SCRIPT_DIR}" +then + ( cd "$SCRIPT_DIR" || exit ; "./$SCRIPT_NAME" ); + exit +fi + + # Uncomment if you use doas instead of sudo #alias sudo=doas From a401adb702d88c647899c9a5fd483fa094736c08 Mon Sep 17 00:00:00 2001 From: hardliner66 Date: Mon, 2 May 2022 11:10:49 +0200 Subject: [PATCH 2/2] pass arguments to recursive call --- build/build-iso.ps1 | 2 +- build/build-iso.sh | 2 +- build/sync.ps1 | 2 +- build/sync.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/build-iso.ps1 b/build/build-iso.ps1 index 52b4e147..78ccd4de 100755 --- a/build/build-iso.ps1 +++ b/build/build-iso.ps1 @@ -5,7 +5,7 @@ if ("$currentDir" -ne "$PSScriptRoot") try { pushd "$PSScriptRoot" - . $PSCommandPath + . $PSCommandPath $args } finally { diff --git a/build/build-iso.sh b/build/build-iso.sh index 6b13b8b7..ae6eca77 100755 --- a/build/build-iso.sh +++ b/build/build-iso.sh @@ -9,7 +9,7 @@ EXPECTED_DIR=$(realpath "$PWD") if test "${EXPECTED_DIR}" != "${SCRIPT_DIR}" then - ( cd "$SCRIPT_DIR" || exit ; "./$SCRIPT_NAME" ); + ( cd "$SCRIPT_DIR" || exit ; "./$SCRIPT_NAME" "$@" ); exit fi diff --git a/build/sync.ps1 b/build/sync.ps1 index fb8505e6..472b7838 100755 --- a/build/sync.ps1 +++ b/build/sync.ps1 @@ -5,7 +5,7 @@ if ("$currentDir" -ne "$PSScriptRoot") try { pushd "$PSScriptRoot" - . $PSCommandPath + . $PSCommandPath $args } finally { diff --git a/build/sync.sh b/build/sync.sh index 22ecc9a2..000afbf6 100755 --- a/build/sync.sh +++ b/build/sync.sh @@ -13,7 +13,7 @@ EXPECTED_DIR=$(realpath "$PWD") if test "${EXPECTED_DIR}" != "${SCRIPT_DIR}" then - ( cd "$SCRIPT_DIR" || exit ; "./$SCRIPT_NAME" ); + ( cd "$SCRIPT_DIR" || exit ; "./$SCRIPT_NAME" "$@" ); exit fi