[PATCH 2/7] Clean up chroot.sh and setcrossarch.sh

Jon Severinsson <[email protected]>
Newsgroups gmane.linux.debian.devel.embedded
Message-ID <[email protected]>
---
 cross/setcrossarch.sh |   41 +++++++++++++++++++++------------------
 examples/chroot.sh    |   51 +++++++++++++++++++++++++++++--------------------
 2 filer ändrade, 52 tillägg(+), 40 borttagningar(-)

diff --git a/cross/setcrossarch.sh b/cross/setcrossarch.sh
index 756c2e6c..f6afdd10 100755
--- a/cross/setcrossarch.sh
+++ b/cross/setcrossarch.sh
@@ -18,42 +18,45 @@ set -e
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # meant to be called from multistrap with directory arch variables.
-dir=$1
-hostarch=$2
 
-if [ -z "$dir" ]; then
+TARGET="$1"
+HOSTARCH="$2"
+
+if [ -z "${TARGET}" ]; then
 	echo "No directory specified."
 	exit 1
 fi
 
 #run chroot script to ensure no unwanted system interactions (e.g. startup scripts)
 if [ -x /usr/share/multistrap/chroot.sh ]; then
-   /usr/share/multistrap/chroot.sh $dir $hostarch
+   /usr/share/multistrap/chroot.sh "${TARGET}" "${HOSTARCH}"
 fi
 
-cfg="/etc/pdebuild-cross/pdebuild-cross.rc"
-if [ -f $cfg ]; then
-	. $cfg
+CFG="/etc/pdebuild-cross/pdebuild-cross.rc"
+if [ -f "${CFG}" ]; then
+	. "${CFG}"
 fi
 
-if [ -z "$CROSSARCH" ]; then
+if [ -z "${CROSSARCH}" ]; then
 	# get crossarch from dpkg-cross - check if it is not None
 	if [ -f /etc/dpkg-cross/cross-compile ]; then
-		DEFARCH=`grep "^default_arch" /etc/dpkg-cross/cross-compile|sed -e 's/default_arch *= *\(.*\)/\1/'`
-		if [ -n "$DEFARCH" -a "$DEFARCH" != "None" ]; then
-			CROSSARCH="$DEFARCH"
+		DEFARCH="$(grep "^default_arch" /etc/dpkg-cross/cross-compile | sed -e 's/default_arch *= *\(.*\)/\1/')"
+		if [ -n "${DEFARCH}" -a "${DEFARCH}" != "None" ]; then
+			CROSSARCH="${DEFARCH}"
 		fi
 	else
-		echo "No CROSSARCH set in '$cfg' and no dpkg-cross default: using armel."
+		echo "No CROSSARCH set in '${CFG}' and no dpkg-cross default: using armel."
 		CROSSARCH="armel"
 	fi
 fi
 
 # set the value inside the chroot
-echo "#!/bin/sh" > $dir/tmp/set.sh
-echo >> $dir/tmp/set.sh
-echo "export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C" >> $dir/tmp/set.sh
-echo "echo debconf dpkg-cross/default-arch select $CROSSARCH|debconf-set-selections" >> $dir/tmp/set.sh
-echo "Setting debconf dpkg-cross/default-arch to $CROSSARCH"
-sudo chroot $dir sh /tmp/set.sh
-sudo rm $dir/tmp/set.sh
+echo "Setting debconf dpkg-cross/default-arch to ${CROSSARCH}"
+cat > "${TARGET}"/tmp/setcrossarch.sh << EOF
+#!/bin/sh
+export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C
+echo debconf dpkg-cross/default-arch select "${CROSSARCH}" | debconf-set-selections
+EOF
+chmod 0755 "${TARGET}"/tmp/setcrossarch.sh
+sudo chroot "${TARGET}" /tmp/setcrossarch.sh
+rm "${TARGET}"/tmp/setcrossarch.sh
diff --git a/examples/chroot.sh b/examples/chroot.sh
index e8f84c72..006fe34d 100755
--- a/examples/chroot.sh
+++ b/examples/chroot.sh
@@ -2,40 +2,49 @@
 
 set -e
 
+# This setup script is an alternative method of adjusting the tarball
+# contents immediately after multistrap has unpacked the packages.
+
+# At this stage, any operations inside the rootfs must not try to
+# execute any binaries within the rootfs.
+
 # The script is called with the following arguments:
+
 # $1 = $DIR  - the top directory of the bootstrapped system
 # $2 = $ARCH - the specified architecture, already checked with dpkg-architecture.
+
 # setup.sh needs to be executable.
 
 TARGET=$1
+
 # upstart support
-if [ -x "$TARGET/sbin/initctl" ]; then
-	echo "initctl: Trying to prevent daemons from starting in $TARGET"
-	mv "$TARGET/sbin/start-stop-daemon" "$TARGET/sbin/start-stop-daemon.REAL"
-	echo \
-"#!/bin/sh
-echo
-echo echo \"Warning: Fake start-stop-daemon called, doing nothing\"" > "$TARGET/sbin/start-stop-daemon"
-	chmod 755 "$TARGET/sbin/start-stop-daemon"
+if [ -x "${TARGET}"/sbin/initctl ]; then
+	echo "initctl: Trying to prevent daemons from starting in ${TARGET}"
+	mv "${TARGET}"/sbin/initctl "${TARGET}"/sbin/initctl.REAL
+	cat > "${TARGET}"/sbin/initctl << EOF
+#!/bin/sh
+echo "Warning: Fake initctl called, doing nothing"
+EOF
+	chmod 0755 "${TARGET}"/sbin/initctl
 fi
-if [ -x "$TARGET/sbin/initctl" ]; then
-	echo "initctl: Trying to prevent daemons from starting in $TARGET"
-	mv "$TARGET/sbin/initctl" "$TARGET/sbin/initctl.REAL"
-	echo \
-"#!/bin/sh
-echo
-echo \"Warning: Fake initctl called, doing nothing\"" > "$TARGET/sbin/initctl"
-	chmod 755 "$TARGET/sbin/initctl"
+if [ -x "${TARGET}"/sbin/initctl -a -x "${TARGET}"/sbin/start-stop-daemon ]; then
+	echo "start-stop-daemon: Trying to prevent daemons from starting in ${TARGET}"
+	mv "${TARGET}"/sbin/start-stop-daemon "${TARGET}"/sbin/start-stop-daemon.REAL
+    cat > "${TARGET}"/sbin/start-stop-daemon << EOF
+#!/bin/sh
+echo "Warning: Fake start-stop-daemon called, doing nothing"
+EOF
+	chmod 0755 "${TARGET}"/sbin/start-stop-daemon
 fi
 
 # sysvinit support - exit value of 101 is essential.
-if [ -x "$TARGET/sbin/init" -a ! -f "$TARGET/usr/sbin/policy-rc.d" ]; then
-	echo "sysvinit: Using policy-rc.d to prevent daemons from starting in $TARGET"
-	mkdir -p $TARGET/usr/sbin/
-	cat > $TARGET/usr/sbin/policy-rc.d << EOF
+if [ -x "${TARGET}"/sbin/init -a ! -f "${TARGET}"/usr/sbin/policy-rc.d ]; then
+	echo "sysvinit: Using policy-rc.d to prevent daemons from starting in ${TARGET}"
+	mkdir -p "${TARGET}"/usr/sbin/
+	cat > "${TARGET}"/usr/sbin/policy-rc.d << EOF
 #!/bin/sh
 echo "sysvinit: All runlevel operations denied by policy" >&2
 exit 101
 EOF
-	chmod a+x $TARGET/usr/sbin/policy-rc.d
+	chmod 0755 "${TARGET}"/usr/sbin/policy-rc.d
 fi
-- 
1.7.10.4


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]
Archive: http://lists.debian.org/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.