forked from obel1x/fedora-OEMDRV
install.sh: add existing OEMDRV reuse, git origin conflict handling, refined permissions
- Detect existing OEMDRV partition at startup; offer to reuse it instead of creating a new one (mounts if needed, sources existing setup_system.inc.sh before cloning) - When existing repo origin/branch differs from REPO_URL/REPO_BRANCH, offer to pull from existing origin, migrate to new origin (preserving gitignored local files), or fall through to fresh clone - Extract finish_install() and do_clone_and_done() helpers to share clone, permissions, and configure.sh prompt across all paths - Replace generic chmod with chown root:root + chmod ug=rwX,o=rX recursively, plus o+w on config/ and config.d/ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+131
-43
@@ -24,6 +24,51 @@ die() { echo; echo "ERROR: $*" >&2; exit 1; }
|
||||
info() { echo; echo ">>> $*"; }
|
||||
hr() { printf '%.0s─' {1..100}; echo; }
|
||||
|
||||
finish_install() {
|
||||
local dev="$1"
|
||||
|
||||
chown root:root "$MOUNT_POINT" -R
|
||||
chmod ug=rwX,o=rX "$MOUNT_POINT" -R
|
||||
chmod o+w "$MOUNT_POINT/config" "$MOUNT_POINT/config.d"
|
||||
|
||||
info "Done."
|
||||
echo
|
||||
echo " OEMDRV device : $dev"
|
||||
echo " Mounted at : $MOUNT_POINT"
|
||||
echo
|
||||
|
||||
CONF_SCRIPT="$MOUNT_POINT/system_setup/configure.sh"
|
||||
|
||||
echo
|
||||
read -r -p "Run configure.sh now to set up your environment? [y/N]: " RUN_CONF
|
||||
if [[ "${RUN_CONF,,}" == "y" ]]; then
|
||||
if [[ -n "$SUDO_USER" ]]; then
|
||||
info "Running configure.sh as user '$SUDO_USER'..."
|
||||
su - "$SUDO_USER" -c "DISPLAY='${DISPLAY}' WAYLAND_DISPLAY='${WAYLAND_DISPLAY}' bash '$CONF_SCRIPT'"
|
||||
else
|
||||
echo
|
||||
echo "configure.sh must be run as a non-root user. Please run:"
|
||||
echo " bash $CONF_SCRIPT"
|
||||
fi
|
||||
else
|
||||
echo
|
||||
echo "Next steps:"
|
||||
echo " 1. Run: bash $CONF_SCRIPT"
|
||||
echo " 2. Boot the Kickstart installer — it will detect the OEMDRV partition automatically."
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
do_clone_and_done() {
|
||||
local dev="$1"
|
||||
|
||||
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."
|
||||
source "$(dirname "$0")/setup_system.inc.sh"
|
||||
finish_install "$dev"
|
||||
}
|
||||
|
||||
require_root() {
|
||||
[[ "$EUID" -eq 0 ]] || die "This script must be run as root."
|
||||
}
|
||||
@@ -293,6 +338,90 @@ new_part_device() {
|
||||
require_root
|
||||
check_tools
|
||||
|
||||
# ── Check for existing OEMDRV partition ───────────────────────────────────────
|
||||
|
||||
EXISTING_OEMDRV_DEV=$(blkid -L "$OEMDRV_LABEL" 2>/dev/null || true)
|
||||
if [[ -n "$EXISTING_OEMDRV_DEV" ]]; then
|
||||
echo
|
||||
echo "Found existing '$OEMDRV_LABEL' partition: $EXISTING_OEMDRV_DEV"
|
||||
read -r -p " Use this partition and overwrite its install files? [y/N]: " ans
|
||||
if [[ "${ans,,}" == "y" ]]; then
|
||||
EXISTING_MNT=$(lsblk -n -o MOUNTPOINT "$EXISTING_OEMDRV_DEV" 2>/dev/null | grep -v '^$' | head -1)
|
||||
if [[ -n "$EXISTING_MNT" ]]; then
|
||||
echo " Partition is already mounted at $EXISTING_MNT — using that mountpoint."
|
||||
MOUNT_POINT="$EXISTING_MNT"
|
||||
else
|
||||
info "Mounting $EXISTING_OEMDRV_DEV to $MOUNT_POINT..."
|
||||
[[ -d "$MOUNT_POINT" ]] || mkdir -p "$MOUNT_POINT"
|
||||
mount -o "$MOUNT_OPTS" "$EXISTING_OEMDRV_DEV" "$MOUNT_POINT" || die "mount failed."
|
||||
fi
|
||||
|
||||
if [[ -f "$MOUNT_POINT/system_setup/setup_system.inc.sh" ]]; then
|
||||
info "Sourcing existing setup_system.inc.sh..."
|
||||
pushd "$MOUNT_POINT/system_setup" > /dev/null
|
||||
source setup_system.inc.sh
|
||||
popd > /dev/null
|
||||
fi
|
||||
|
||||
# ── Check existing git repository origin ──────────────────────────────
|
||||
if git -C "$MOUNT_POINT" rev-parse --git-dir >/dev/null 2>&1; then
|
||||
EXIST_URL=$(git -C "$MOUNT_POINT" remote get-url origin 2>/dev/null || true)
|
||||
EXIST_BRANCH=$(git -C "$MOUNT_POINT" symbolic-ref --short HEAD 2>/dev/null \
|
||||
|| git -C "$MOUNT_POINT" rev-parse --abbrev-ref HEAD 2>/dev/null || true)
|
||||
if [[ -n "$EXIST_URL" && ( "$EXIST_URL" != "$REPO_URL" || "$EXIST_BRANCH" != "$REPO_BRANCH" ) ]]; then
|
||||
echo
|
||||
echo " The existing repository differs from the configured values:"
|
||||
printf " %-12s %-55s %s\n" "" "Origin" "Branch"
|
||||
printf " %-12s %-55s %s\n" "Existing:" "$EXIST_URL" "$EXIST_BRANCH"
|
||||
printf " %-12s %-55s %s\n" "Configured:" "$REPO_URL" "$REPO_BRANCH"
|
||||
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."
|
||||
source "$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."
|
||||
source "$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
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "$(ls -A "$MOUNT_POINT" 2>/dev/null)" ]]; then
|
||||
info "Clearing existing content in $MOUNT_POINT before fresh clone..."
|
||||
find "$MOUNT_POINT" -mindepth 1 -delete
|
||||
fi
|
||||
|
||||
do_clone_and_done "$EXISTING_OEMDRV_DEV"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
info "Verifying repository URL..."
|
||||
check_repo_url
|
||||
case $? in
|
||||
@@ -497,47 +626,6 @@ info "Mounting $OEMDRV_DEV to $MOUNT_POINT (options: $MOUNT_OPTS)..."
|
||||
[[ -d "$MOUNT_POINT" ]] || mkdir -p "$MOUNT_POINT"
|
||||
mount -o "$MOUNT_OPTS" "$OEMDRV_DEV" "$MOUNT_POINT" || die "mount failed."
|
||||
|
||||
# ── Clone repository ──────────────────────────────────────────────────────────
|
||||
# ── Clone repository + 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."
|
||||
|
||||
# Write hardware UUID to a user-readable per-machine file
|
||||
dmidecode -t system | grep -i 'UUID' \
|
||||
| sed 's/UUID: //' | tr '[:upper:]' '[:lower:]' \
|
||||
| sed 's/[^0-9a-z]*//g' | xargs | tail -c 13 \
|
||||
> "./config.d/machine_uuid.sys"
|
||||
|
||||
chmod o=rwX . -R # to make changes to the configuration possible after install
|
||||
|
||||
# ── Done ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
info "Done."
|
||||
echo
|
||||
echo " OEMDRV device : $OEMDRV_DEV"
|
||||
echo " Mounted at : $MOUNT_POINT"
|
||||
echo
|
||||
|
||||
# ── Optionally run configure.sh ───────────────────────────────────────────────
|
||||
|
||||
CONF_SCRIPT="$MOUNT_POINT/system_setup/configure.sh"
|
||||
|
||||
echo
|
||||
read -r -p "Run configure.sh now to set up your environment? [y/N]: " RUN_CONF
|
||||
if [[ "${RUN_CONF,,}" == "y" ]]; then
|
||||
if [[ -n "$SUDO_USER" ]]; then
|
||||
info "Running configure.sh as user '$SUDO_USER'..."
|
||||
su - "$SUDO_USER" -c "DISPLAY='${DISPLAY}' WAYLAND_DISPLAY='${WAYLAND_DISPLAY}' bash '$CONF_SCRIPT'"
|
||||
else
|
||||
echo
|
||||
echo "configure.sh must be run as a non-root user. Please run:"
|
||||
echo " bash $CONF_SCRIPT"
|
||||
fi
|
||||
else
|
||||
echo
|
||||
echo "Next steps:"
|
||||
echo " 1. Run: bash $CONF_SCRIPT"
|
||||
echo " 2. Boot the Kickstart installer — it will detect the OEMDRV partition automatically."
|
||||
echo
|
||||
fi
|
||||
do_clone_and_done "$OEMDRV_DEV"
|
||||
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env sh
|
||||
# Usage: will make a tar-file from folder skel found in the directory where executed
|
||||
# If you want to change skel- content, extrakt your skel.tar.zstd to this directory, edit the files and use this script to repack
|
||||
source $(dirname "$0")/setup_system.inc.sh
|
||||
mv skel.tar.zst backup_skel.tar.zst
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Old Archive renamed to backup_skel.tar.zst"
|
||||
else
|
||||
echo "Some Errors occured, cannot continue."
|
||||
exit 1
|
||||
fi
|
||||
tar -I 'zstd -9' -cf skel.tar.zst skel
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Archive skel.tar.zst has been created"
|
||||
echo "You should now remove skel- Folder here"
|
||||
else
|
||||
echo "Some Errors occured, quit"
|
||||
exit 1
|
||||
fi
|
||||
rm backup_skel.tar.zst
|
||||
echo "Old Archive deleted"
|
||||
# TODO
|
||||
# - up file to NC - is only possible, when setup already has the webdav-token created
|
||||
#
|
||||
Binary file not shown.
Reference in New Issue
Block a user