New commits:
commit 93594dd2baf7eecd19bc508efbe394cf20c2e95d
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>
scripts/*: ability to use sudo
All of the scripts can now make use of sudo to run superuser
privileged commands. If the UID is not 0, the scripts will attempt
sudo if sudo is found on the system, else they will prompt for the
root password and rerun themselves via su.
+SELF=$0
+SUDOCMD=""
+
+if [[ $UID -ne 0 ]]
+then
+ if [[ -x $(which sudo) ]]
+ then
+ SUDOCMD="sudo"
+ else
+ echo "Please enter the root password."
+ exec su -c "$SELF $*" root
+ fi
+fi
+
if [[ $TYPE == "bad" || -z $1 ]] ;then
usage
fi
@@ -64,19 +78,19 @@ fi >&2
# make sure we start with a clean TEMPDIR each run
-rm -rf $TEMPDIR
-mkdir -m 0700 $TEMPDIR
+$SUDOCMD rm -rf $TEMPDIR
+$SUDOCMD mkdir -m 0700 $TEMPDIR
# add the contents of base, which are files that
# should go onto both iso and system chroots
# this is mostly /etc content
-cp -a $MYDIR/base/* $TEMPDIR/
+$SUDOCMD cp -a $MYDIR/base/* $TEMPDIR/
# ISO Sauce
if [[ $TYPE == "iso" ]] ;then
# copy everything from the cauldron repo iso dir
# into the TEMPDIR staging area
- cp -a $MYDIR/iso/* $TEMPDIR/
+ $SUDOCMD cp -a $MYDIR/iso/* $TEMPDIR/
fi
# System Sauce
@@ -85,13 +99,13 @@ then
# make sure that the grub stage files are available in /boot
# by copying them from CHROOTDIR (system) into the /boot dir
# in our TEMPDIR staging area
- cp -a $CHROOTDIR/usr/lib/grub/i386-pc/* $TEMPDIR/boot/grub/
+ $SUDOCMD cp -a $CHROOTDIR/usr/lib/grub/i386-pc/* $TEMPDIR/boot/grub/
fi
# Get a list of all files we want to install
@@ -102,7 +116,7 @@ do
# This is safe even if the dir already exists
if [[ -d $i ]]
then
- mkdir -p $CHROOTDIR/$FILE
+ $SUDOCMD mkdir -p $CHROOTDIR/$FILE
continue
fi
@@ -122,12 +136,12 @@ do
echo ""
if [[ $OVERWRITE == y ]]
then
- cp -a $TEMPDIR/$FILE $CHROOTDIR/$FILE
+ $SUDOCMD cp -a $TEMPDIR/$FILE $CHROOTDIR/$FILE
fi
else
- cp -a $TEMPDIR/$FILE $CHROOTDIR/$FILE
+ $SUDOCMD cp -a $TEMPDIR/$FILE $CHROOTDIR/$FILE
fi
done
-rm -rf $TEMPDIR
+$SUDOCMD rm -rf $TEMPDIR
diff --git a/scripts/cauldronchr.sh b/scripts/cauldronchr.sh
index 7bde1c6..7220247 100755
--- a/scripts/cauldronchr.sh
+++ b/scripts/cauldronchr.sh
@@ -4,13 +4,6 @@
# assumes $CWD as chroot path and /bin/bash -l as CHROOT_CMD
# if not specified
+SELF=$0
+SUDOCMD=""
+
+if [[ $UID -ne 0 ]]
+then
+ if [[ -x $(which sudo) ]]
+ then
+ SUDOCMD="sudo"
+ else
+ echo "Please enter the root password."
+ exec su -c "$SELF $*" root
+ fi
+fi
+
# Check to make sure we have the right number of arguments
# taking the option flag into account
if [[ $# -eq 1 ]]
@@ -87,11 +101,11 @@ do
then
# chroot and clean a directory using rmdir
echo "Attempting to remove directory
$ISOCHROOT/$DIRT"
- chroot "$ISOCHROOT" rmdir "$DIRT"
+ $SUDOCMD chroot "$ISOCHROOT" rmdir
--ignore-fail-on-non-empty "$DIRT"
else
# chroot and clean an individual file
echo "Attempting to delete $ISOCHROOT/$DIRT"
- chroot "$ISOCHROOT" rm "$DIRT"
+ $SUDOCMD chroot "$ISOCHROOT" rm "$DIRT"
fi
fi
done
diff --git a/scripts/mkiso.sh b/scripts/mkiso.sh
index 6b1d8f3..5948a7c 100755
--- a/scripts/mkiso.sh
+++ b/scripts/mkiso.sh
@@ -42,13 +42,26 @@ do
done
shift $(($OPTIND - 1))
+SELF=$0
+SUDOCMD=""
+
+if [[ $UID -ne 0 ]]
+then
+ if [[ -x $(which sudo) ]]
+ then
+ SUDOCMD="sudo"
+ else
+ echo "Please enter the root password."
+ exec su -c "$SELF $*" root
+ fi
+fi
ISO_CHROOT=$1
ISO_VERSION=$2
for file in $(grep -qr '@ISO_VERSION@'
$TARGET/{etc,isolinux,usr/share/doc/smgl.install}/*)
do
- sed -i "s/@ISO_VERSION@/$VERSION/" "$file"
+ $SUDOCMD sed -i "s/@ISO_VERSION@/$VERSION/" "$file"
done
-sed -i "s/@GRIMOIRE_VERSION@/$GRIMOIRE_VER/" "$TARGET"/isolinux/isolinux.msg
+$SUDOCMD sed -i "s/@GRIMOIRE_VERSION@/$GRIMOIRE_VER/"
"$TARGET"/isolinux/isolinux.msg