[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH] Rework SCRIPT detection



Hello,

the 4th positional argument to debootstrap is the script to use, which
hat 2 annoying properties:

1. The current code always preferres the script named the same from
"$DEBOOTSTRAP_DIR/scripts/" even when it exists in my current working
directory - except I use an absolute path.

>        if [ "$4" != "" ]; then
> -               if [ -e "$DEBOOTSTRAP_DIR/scripts/$4" ]; then
> -                       SCRIPT="$DEBOOTSTRAP_DIR/scripts/$4"
> -               else
> -                       SCRIPT="$4"
> -               fi
> -       fi

2. For every new distribution I have to add a new symbolic link to point
to "sid" - make it the default. (Ubuntu people might not like this)

Find attached a patch which does that.

Philipp
-- 
Philipp Hahn
Open Source Software Engineer

Univention GmbH
be open.
Mary-Somerville-Str. 1
D-28359 Bremen

Tel.: +49-421-22232-57
Fax : +49-421-22232-99

hahn@univention.de
https://www.univention.de/

Geschäftsführer: Peter H. Ganten
HRB 20755 Amtsgericht Bremen
Steuer-Nr.: 71-597-02876
From 3c674b65b85e1f01326de6f4a3e0470231c0d87e Mon Sep 17 00:00:00 2001
Message-Id: <3c674b65b85e1f01326de6f4a3e0470231c0d87e.1589268749.git.hahn@univention.de>
From: Philipp Hahn <hahn@univention.de>
Date: Tue, 12 May 2020 09:28:06 +0200
Subject: [PATCH] Rework SCRIPT detection

Try scripts in the following order
1. local file [Previously 2nd]
2. variant
3. relative path in scripts/ folder
4. Suite
5. Fall back to `sid` [NEW]
---
 debootstrap | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/debootstrap b/debootstrap
index 8fbf954..82eeeff 100755
--- a/debootstrap
+++ b/debootstrap
@@ -490,18 +490,21 @@ else
 		fi
 	fi
 
-	SCRIPT="$DEBOOTSTRAP_DIR/scripts/$1"
-	if [ -n "$VARIANT" ] && [ -e "${SCRIPT}.${VARIANT}" ]; then
-		SCRIPT="${SCRIPT}.${VARIANT}"
+	select_script () {
+		for SCRIPT in "$@"
+		do
+			[ -e "$SCRIPT" ] && return
+		done
+		error 1 NOSCRIPT "No such script: %s" "$*"
+	}
+	select_script \
+		${4:+"$4"} \
+		${4:+"$DEBOOTSTRAP_DIR/scripts/$4"} \
+		${VARIANT:+"$DEBOOTSTRAP_DIR/scripts/$1.$VARIANT"} \
+		"$DEBOOTSTRAP_DIR/scripts/$1" \
+		"$DEBOOTSTRAP_DIR/scripts/sid"
+	[ -n "$VARIANT" ] && [ "$SCRIPT" = "$DEBOOTSTRAP_DIR/scripts/$1.$VARIANT" ] &&
 		SUPPORTED_VARIANTS="$VARIANT"
-	fi
-	if [ "$4" != "" ]; then
-		if [ -e "$DEBOOTSTRAP_DIR/scripts/$4" ]; then
-			SCRIPT="$DEBOOTSTRAP_DIR/scripts/$4"
-		else
-			SCRIPT="$4"
-		fi
-	fi
 fi
 
 ###########################################################################
@@ -591,10 +594,6 @@ if am_doing_phase first_stage second_stage; then
 	fi
 fi
 
-if [ ! -e "$SCRIPT" ]; then
-	error 1 NOSCRIPT "No such script: %s" "$SCRIPT"
-fi
-
 ###########################################################################
 
 if [ "$TARGET" != "" ]; then
-- 
2.20.1


Reply to: