From 8652131882d423d65c2878bfc9c1850a8aef1dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20unbrot=20P=C3=A4tzold?= Date: Sun, 3 May 2026 18:42:12 +0200 Subject: [PATCH] inc.sh: use BASH_SOURCE for path resolution; add --missingconfok; fix install.sh sourcing and git pull logic setup_system.inc.sh: replace $(dirname "$0") with $(dirname "${BASH_SOURCE[0]:-$0}") so paths resolve correctly whether the file is sourced or executed directly. Add --missingconfok flag to warn-and-continue instead of prompting+aborting when config is missing. Fix machine_uuid path (missing ../). Move `source config` into the else branch so it is not reached when missingconfok skips the exit. install.sh: source inc.sh instead of executing it as a subprocess so exported variables (REPO_URL etc.) propagate back to the caller. Fix git-origin conflict handling: when reusing an existing OEMDRV partition the user has already confirmed they want to keep it, so remove the "fresh clone / wipe" option entirely. Now always pulls (fetch+checkout) when a git repo is present; clears and fresh-clones only when no git repo exists on the partition. basic_pre_script.inc: dot-source inc.sh so INSTALLDOCS and other config vars are available. config.dist, sync_client_software.sh: rename UPGRADEURL/UPGRADEBRANCH to REPO_URL/REPO_BRANCH to match the variable names already used in install.sh. Co-Authored-By: Claude Sonnet 4.6 --- CLAUDE.md | 2 +- install.md | 2 +- ks_base_profiles/basic_pre_script.inc | 2 +- .../config.dist/setup_system.conf.dist | 6 +- system_setup/install.sh | 70 +++++++++---------- system_setup/setup_system.inc.sh | 57 ++++++++------- system_setup/sync_client_software.sh | 12 ++-- 7 files changed, 80 insertions(+), 71 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 23c46af..f7be501 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -17,7 +17,7 @@ cp /opt/sys_config/system_setup/config.dist/setup_system.conf.dist /opt/sys_conf # Edit setup_system.conf with your domain, server FQDNs, paths, etc. ``` -Local per-machine overrides go in `config.d/*.conf` (gitignored). These are sourced after `setup_system.conf` and can override any exported variable (e.g. `config.d/system_defines.conf` overrides `UPGRADEBRANCH`). +Local per-machine overrides go in `config.d/*.conf` (gitignored). These are sourced after `setup_system.conf` and can override any exported variable (e.g. `config.d/system_defines.conf` overrides `REPO_BRANCH`). `config/skel.tar.zst` (gitignored) holds the `/etc/skel` archive deployed to new installs. The `.dist` version is at `system_setup/skel/skel.tar.zst.dist`. To modify skel: extract, edit, then repack: ```sh diff --git a/install.md b/install.md index 8703b3b..a3910fa 100644 --- a/install.md +++ b/install.md @@ -52,7 +52,7 @@ Optionally add local per-machine overrides in `config.d/`: ```sh # Example: use the devel branch on this machine -echo 'export UPGRADEBRANCH="devel"' > /opt/sys_config/config.d/system_defines.conf +echo 'export REPO_BRANCH="devel"' > /opt/sys_config/config.d/system_defines.conf ``` Once configured, boot the Fedora installer from USB — Anaconda will detect the `OEMDRV` partition and run the Kickstart automatically. diff --git a/ks_base_profiles/basic_pre_script.inc b/ks_base_profiles/basic_pre_script.inc index b3fbdb9..d59a90a 100644 --- a/ks_base_profiles/basic_pre_script.inc +++ b/ks_base_profiles/basic_pre_script.inc @@ -33,7 +33,7 @@ if [ ! -f ${FQFILENAME} ]; then fi # Check if there is a Partition OEMDRV and on which Drive -/mnt/anaconda_pre/system_setup/setup_system.inc.sh +. /mnt/anaconda_pre/system_setup/setup_system.inc.sh OEMDRVINFO=$(blkid | grep 'LABEL="OEMDRV"') if [ "${OEMDRVINFO}." == "." ] ; then echo "* Error: Required partition with label 'OEMDRV' is not found." diff --git a/system_setup/config.dist/setup_system.conf.dist b/system_setup/config.dist/setup_system.conf.dist index 08b541b..9a0afc3 100644 --- a/system_setup/config.dist/setup_system.conf.dist +++ b/system_setup/config.dist/setup_system.conf.dist @@ -8,9 +8,9 @@ export SERVERFQDN_IPA=ipa.${TLDOMAIN} # Needs to be the IPA- Server export SERVERFQDN_NC=nextcloud.${TLDOMAIN} export INSTALLDOCS="https://gitea.dtext.online/obel1x/fedora-OEMDRV/src/branch/main/README.md" -#If the UPGRADEURL and branch is set, this script collection will do automatic upgrades -export UPGRADEURL="https://gitea.dtext.online/obel1x/fedora-OEMDRV.git" -export UPGRADEBRANCH="main" +#If the REPO_URL and REPO_BRANCH is set, this script collection will do automatic upgrades +export REPO_URL="https://gitea.dtext.online/obel1x/fedora-OEMDRV.git" +export REPO_BRANCH="main" #Configuration Files - maybe syned with your companies settings export SYSCONFIGPATH="/opt/sys_config" diff --git a/system_setup/install.sh b/system_setup/install.sh index 99672ce..c25ac49 100755 --- a/system_setup/install.sh +++ b/system_setup/install.sh @@ -69,7 +69,7 @@ do_clone_and_done() { info "Cloning $REPO_URL into $MOUNT_POINT..." cd "$MOUNT_POINT" || die "Cannot cd to $MOUNT_POINT." git clone --progress --depth 1 -b $REPO_BRANCH "$REPO_URL" . || die "git clone failed." - ${MOUNT_POINT}/system_setup/setup_system.inc.sh + source "$MOUNT_POINT/system_setup/setup_system.inc.sh" --missingconfok finish_install "$dev" } @@ -361,8 +361,8 @@ if [[ -n "$EXISTING_OEMDRV_DEV" ]]; then fi if [[ -f "$MOUNT_POINT/system_setup/setup_system.inc.sh" && -f "$MOUNT_POINT/config/setup_system.conf" ]]; then - info "Reading existing configuration..." - $MOUNT_POINT/system_setup/setup_system.inc.sh + info "Reading existing configuration from ${MOUNT_POINT} ..." + source "$MOUNT_POINT/system_setup/setup_system.inc.sh" fi # ── Check existing git repository origin ────────────────────────────── @@ -377,45 +377,45 @@ if [[ -n "$EXISTING_OEMDRV_DEV" ]]; then printf " %-12s %-55s %s\n" "Existing:" "$EXIST_URL" "$EXIST_BRANCH" printf " %-12s %-55s %s\n" "Configured:" "$REPO_URL" "$REPO_BRANCH" echo + echo " Hint: set REPO_URL / REPO_BRANCH env vars before running to override the configured values." + echo echo " How should this be resolved?" echo " 1) Keep existing origin/branch — pull latest from $EXIST_URL / $EXIST_BRANCH" echo " 2) Switch to configured origin — migrate to $REPO_URL / $REPO_BRANCH (preserves local files)" - echo " 3) Fresh clone from configured origin — clears all existing content" - read -r -p " Choice [1/2/3]: " GIT_CHOICE - case "${GIT_CHOICE}" in - 1) - REPO_URL="$EXIST_URL" - REPO_BRANCH="$EXIST_BRANCH" - info "Fetching latest from $REPO_URL (branch: $REPO_BRANCH)..." - git -C "$MOUNT_POINT" fetch --depth 1 origin "$REPO_BRANCH" \ - || die "git fetch failed." - git -C "$MOUNT_POINT" checkout -B "$REPO_BRANCH" FETCH_HEAD \ - || die "git checkout failed." - $MOUNT_POINT/system_setup/setup_system.inc.sh - finish_install "$EXISTING_OEMDRV_DEV" - exit 0 - ;; - 2) - info "Switching origin to $REPO_URL (branch: $REPO_BRANCH)..." - git -C "$MOUNT_POINT" remote set-url origin "$REPO_URL" \ - || die "git remote set-url failed." - git -C "$MOUNT_POINT" fetch --depth 1 origin "$REPO_BRANCH" \ - || die "git fetch failed." - git -C "$MOUNT_POINT" checkout -B "$REPO_BRANCH" FETCH_HEAD \ - || die "git checkout failed." - $MOUNT_POINT/system_setup/setup_system.inc.sh - finish_install "$EXISTING_OEMDRV_DEV" - exit 0 - ;; - *) - # Option 3 or anything else: fall through to clear + fresh clone - ;; - esac + while true; do + read -r -p " Choice [1/2]: " GIT_CHOICE + case "${GIT_CHOICE}" in + 1) + REPO_URL="$EXIST_URL" + REPO_BRANCH="$EXIST_BRANCH" + break + ;; + 2) + info "Switching origin to $REPO_URL (branch: $REPO_BRANCH)..." + git -C "$MOUNT_POINT" remote set-url origin "$REPO_URL" \ + || die "git remote set-url failed." + break + ;; + *) + echo " Please enter 1 or 2." + ;; + esac + done fi + + info "Pulling latest from $REPO_URL (branch: $REPO_BRANCH)..." + git -C "$MOUNT_POINT" fetch --depth 1 origin "$REPO_BRANCH" \ + || die "git fetch failed." + git -C "$MOUNT_POINT" checkout -B "$REPO_BRANCH" FETCH_HEAD \ + || die "git checkout failed." + source "$MOUNT_POINT/system_setup/setup_system.inc.sh" + finish_install "$EXISTING_OEMDRV_DEV" + exit 0 fi + # No git repo on the partition — clear and do a fresh clone if [[ -n "$(ls -A "$MOUNT_POINT" 2>/dev/null)" ]]; then - info "Clearing existing content in $MOUNT_POINT before fresh clone..." + info "No git repository found on $MOUNT_POINT — clearing before fresh clone..." find "$MOUNT_POINT" -mindepth 1 -delete fi diff --git a/system_setup/setup_system.inc.sh b/system_setup/setup_system.inc.sh index 590e4c2..b8c4c89 100755 --- a/system_setup/setup_system.inc.sh +++ b/system_setup/setup_system.inc.sh @@ -5,45 +5,54 @@ # SPDX-License-Identifier: AGPL-3.0-or-later # # This is not a runnig script-file. No real logic to execute. Its used for includes in other scripts. +# +# Parameters (pass as arguments to the `source` call, e.g. source setup_system.inc.sh --missingconfok): +# --missingconfok Print a warning instead of prompting and aborting when config/setup_system.conf is missing. -#Check if we are root -# Deprectaed - use if Statement itself -#check_root() -#{ -# if [ "$EUID" -ne 0 ]; then -# return 1 -# fi -# return 0 -#} +# Parse flags passed to this inc (e.g. source setup_system.inc.sh --missingconfok). +# In bash, arguments to `source` temporarily replace $@ for the duration of the sourced file. +_INC_MISSINGCONFOK=0 +for _inc_arg in "$@"; do + [[ "$_inc_arg" == "--missingconfok" ]] && _INC_MISSINGCONFOK=1 +done +unset _inc_arg -#First, get the machine_uuid wich is needed by some userspace programs. +#Get the machine_uuid wich is needed by some userspace programs. #As all Parameters that are bound to CPU or Mainboard, are only readable by root, we need to get the values at installtime. #On old installations without the file, we will write it whenever possible -if [ -f $( dirname "$0" )/config.d/machine_uuid.sys ]; then - export MACHINEID="$( cat $( dirname "$0" )/config.d/machine_uuid.sys )" +if [ -f $( dirname "${BASH_SOURCE[0]:-$0}" )/../config.d/machine_uuid.sys ]; then + export MACHINEID="$( cat $( dirname "${BASH_SOURCE[0]:-$0}" )/../config.d/machine_uuid.sys )" elif [ "$EUID" -eq 0 ]; then dmidecode -t system | grep -i 'UUID' \ | sed 's/UUID: //' | tr '[:upper:]' '[:lower:]' \ | sed 's/[^0-9a-z]*//g' | xargs | tail -c 13 \ - > "$( dirname "$0" )/config.d/machine_uuid.sys" - export MACHINEID="$( cat $( dirname "$0" )/config.d/machine_uuid.sys )" + > "$( dirname "${BASH_SOURCE[0]:-$0}" )/../config.d/machine_uuid.sys" + export MACHINEID="$( cat $( dirname "${BASH_SOURCE[0]:-$0}" )/../config.d/machine_uuid.sys )" fi -#Check for configure.conf - used for frist setup of system -if [[ -f $(dirname "$0")/../config.d/configure.conf ]]; then - echo "System in configure-mode. Will use $(dirname "$0")/../config.d/configure.conf for setup." - source $(dirname "$0")/../config.d/configure.conf +#Check for configure.conf - used for first setup of system +if [[ -f $(dirname "${BASH_SOURCE[0]:-$0}")/../config.d/configure.conf ]]; then + echo "System in configure-mode. Will use $(dirname "${BASH_SOURCE[0]:-$0}")/../config.d/configure.conf for setup." + source $(dirname "${BASH_SOURCE[0]:-$0}")/../config.d/configure.conf else #Load default system setup file - if [[ ! -f $(dirname "$0")/../config/setup_system.conf ]]; then - echo "System configuration not found. Please copy system_setup/config.dist/setup_system.conf.dist to config/setup_system.conf and adjust the settings before running." - echo "Press any key to continue" && read -n 1 -s -r && exit 1 + if [[ ! -f $(dirname "${BASH_SOURCE[0]:-$0}")/../config/setup_system.conf ]]; then + echo "System configuration not found." + echo "Please copy system_setup/config.dist/setup_system.conf.dist to config/setup_system.conf and adjust the settings before running." + if [[ $_INC_MISSINGCONFOK -eq 1 ]]; then + echo "WARNING: Continuing without system configuration (--missingconfok)." + else + echo "Press any key to continue" && read -n 1 -s -r && exit 1 + fi + else + echo "Found and use configfile $(dirname "${BASH_SOURCE[0]:-$0}")/../config/setup_system.conf" + source $(dirname "${BASH_SOURCE[0]:-$0}")/../config/setup_system.conf fi - source $(dirname "$0")/../config/setup_system.conf #Parse additional client-configs - if [[ `ls -1 $(dirname "$0")/../config.d/*.conf 2>/dev/null | wc -l ` -gt 0 ]]; then - source $(dirname "$0")/../config.d/*.conf + if [[ `ls -1 $(dirname "${BASH_SOURCE[0]:-$0}")/../config.d/*.conf 2>/dev/null | wc -l ` -gt 0 ]]; then + echo "Additional config file found $(dirname "${BASH_SOURCE[0]:-$0}")/../config.d/*.conf - using it" + source $(dirname "${BASH_SOURCE[0]:-$0}")/../config.d/*.conf fi fi diff --git a/system_setup/sync_client_software.sh b/system_setup/sync_client_software.sh index 3f4fcf3..7e6f32c 100755 --- a/system_setup/sync_client_software.sh +++ b/system_setup/sync_client_software.sh @@ -34,29 +34,29 @@ echo "" #Do an upgrade of the Base package if its configured and if there are changes chown root:${CLIENTADMINGROUP} -R ${SYSCONFIGPATH} chmod ug+rwX,o=rX -R ${SYSCONFIGPATH} -if [[ ! -z "${UPGRADEURL}" ]]; then - echo "Checking for Upgrades on ${UPGRADEURL} and Branch ${UPGRADEBRANCH}" +if [[ ! -z "${REPO_URL}" ]]; then + echo "Checking for Upgrades on ${REPO_URL} and Branch ${REPO_BRANCH}" REMOTEURL=$( git config --get remote.origin.url ) echo "Remote git URL is ${REMOTEURL}" - if [[ "${REMOTEURL}" != "${UPGRADEURL}" ]]; then + if [[ "${REMOTEURL}" != "${REPO_URL}" ]]; then echo "This Repo is not on the matching URL, so no update is possible. If you want to change this, check out the docs on how to setup from scratch." else GITBRANCH=$( git rev-parse --abbrev-ref HEAD ) echo "Current branch is ${GITBRANCH}" - if [[ "${GITBRANCH}" != "${UPGRADEBRANCH}" ]]; then + if [[ "${GITBRANCH}" != "${REPO_BRANCH}" ]]; then echo "This Repo is not on the right branch, so no update is possible." else # Doing upgrade, discarding all local changes frist (is more save than forced pull) echo "Checks have passed, we are now upgrading via git." #Fetch latest Updates and remove all history - git fetch origin && git reset --hard origin/${UPGRADEBRANCH} && git rebase HEAD^ + git fetch origin && git reset --hard origin/${REPO_BRANCH} && git rebase HEAD^ if [[ $? -ne 0 ]]; then echo "Error: Failure while updating, will continue as is." fi fi fi else - echo "UPGRADEURL is not specified in conf - No Upgrade option available." + echo "REPO_URL is not specified in conf - No Upgrade option available." fi echo ""