<span style="font-family: courier new,monospace;">[Patch 4/5]<br>Author: Frederick Grose <<a href="mailto:fgrose@sugarlabs.org">fgrose@sugarlabs.org</a>><br>Date: Thu Apr 14 10:53:09 2011 -0400<br><br> Support installation of customized builds with --copy-home and<br>
--include options.<br> <br> Custom isos may package home.img and extra files or directories.<br> <br> Fix logic on unmounting and removing SRCMNT & TGTMNT.<br> Include uncompressed ext3fs.img in detectsrctype() logic.<br>
Use loop mount for SRCMNT on running Live images.<br> Add error messages and disc space estimation adjustments.<br> Tolerate user changes to 'quiet rhgb' in configuration file.<br> Support F15-style rd.luks=0 in configuration file adjustment.<br>
<br>diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh<br>index 5261aab..de48ec4 100755<br>--- a/tools/livecd-iso-to-disk.sh<br>+++ b/tools/livecd-iso-to-disk.sh<br>@@ -33,6 +33,7 @@ shortusage() {<br>
[--compress] [--skipcompress] [--swap-size-mb <size>]<br> [--overlay-size-mb <size>] [--home-size-mb <size>]<br> [--delete-home] [--crypted-home] [--unencrypted-home]<br>
+ [--copy-home] [--include <file s>]<br> <source> <target device><br> <br> (Enter livecd-iso-to-disk --help on the command line for more information.)"<br>
@@ -242,6 +243,20 @@ usage() {<br> --unencrypted-home<br> Prevents the default option to encrypt a new persistent home directory.<br> <br>+ --copy-home<br>+ This option allows one to copy a persistent home folder from one LiveOS<br>
+ image to the target image. Changes already made in the source home<br>+ directory will be propagated to the new image.<br>+ WARNING: User-sensitive information, such as password cookies and<br>
+ user and application data, will be copied to the new image! Scrub<br>+ this information before using this option.<br>+<br>+ --include <path s><br>+ This option allows one to copy one or more file or directory paths from<br>
+ the outer source filesystem to the same path on the target.<br>+ Multiple paths should be specified in one string, i.e.,<br>+ --include "path1 path2 ..."<br>+<br> CONTRIBUTORS<br>
<br>
livecd-iso-to-disk: David Zeuthen, Jeremy Katz, Douglas McClendon,<br>@@ -272,8 +287,14 @@ usage() {<br> <br> cleanup() {<br> sleep 2<br>- [ -d "$SRCMNT" ] && umount $SRCMNT && rmdir $SRCMNT<br>
- [ -d "$TGTMNT" ] && umount $TGTMNT && rmdir $TGTMNT<br>+ if [[ -d $SRCMNT ]]; then<br>+ umount $SRCMNT<br>+ rmdir $SRCMNT<br>+ fi<br>+ if [[ -d $TGTMNT ]]; then<br>+ umount $TGTMNT<br>
+ rmdir $TGTMNT<br>+ fi<br> }<br> <br> exitclean() {<br>@@ -594,7 +615,8 @@ if [ $(id -u) != 0 ]; then<br> fi<br> <br> detectsrctype() {<br>- if [[ -e $SRCMNT/LiveOS/squashfs.img ]]; then<br>+ if [[ -e $SRCMNT/LiveOS/squashfs.img ||<br>
+ -e $SRCMNT/LiveOS/ext3fs.img ]]; then<br> srctype=live<br> return<br> fi<br>@@ -652,6 +674,8 @@ shopt -s extglob<br> <br> cryptedhome=1<br> keephome=1<br>+copyhome=<br>+copyhomesize=0<br> homesizemb=0<br>
swapsizemb=0<br> overlaysizemb=0<br>@@ -659,6 +683,7 @@ srctype=<br> imgtype=<br> LIVEOS=LiveOS<br> HOMEFILE="home.img"<br>+includes=<br> <br> if [[ "$*" =~ "--help" ]]; then<br> usage<br>
@@ -747,6 +772,14 @@ while [ $# -gt 2 ]; do<br> --delete-home)<br> keephome=""<br> ;;<br>+ --copy-home)<br>+ copyhome=1<br>+ cryptedhome=""<br>
+ ;;<br>+ --include)<br>+ includes=($2)<br>+ shift<br>+ ;;<br> *)<br> echo "invalid arg -- $1"<br> shortusage<br>@@ -795,6 +828,7 @@ fi<br>
<br> # do some basic sanity checks.<br> checkMounted $TGTDEV<br>+! [[ /dev/live == $1 || /dev/sr0 == $1 ]] && checkMounted $SRC<br> <br> # Format the device<br> if [ -n "$format" -a -z "$skipcopy" ]; then<br>
@@ -850,10 +884,13 @@ fi<br> <br> # FIXME: would be better if we had better mountpoints<br> SRCMNT=$(mktemp -d /media/srctmp.XXXXXX)<br>-if [ -b $SRC ]; then<br>- mount -o ro "$SRC" $SRCMNT || exitclean<br>-elif [ -f $SRC ]; then<br>
+if [[ -f $SRC || /dev/live == $1 || /dev/sr0 == $1 ]]; then<br> mount -o loop,ro "$SRC" $SRCMNT || exitclean<br>+ imgtype='iso'<br>+ [[ /dev/live == $1 ]] && imgtype='live'<br>
+elif [[ -b $SRC ]]; then<br>+ mount -o ro "$SRC" $SRCMNT || exitclean<br>+ imgtype='blk'<br> else<br> echo "$SRC is not a file or block device."<br> exitclean<br>@@ -865,11 +902,53 @@ trap exitclean SIGINT SIGTERM<br>
<br> detectsrctype<br> <br>-if [ -f "$TGTMNT/$LIVEOS/$HOMEFILE" -a -n "$keephome" -a "$homesizemb" -gt 0 ]; then<br>- echo "ERROR: Requested keeping existing /home and specified a size for /home"<br>
- echo "Please either don't specify a size or specify --delete-home"<br>+if [[ -d $SRCMNT/LiveOS ]]; then<br>+ SRCLIVEOSDIR=$SRCMNT/LiveOS<br>+else<br>+ SRCLIVEOSDIR=$SRCMNT<br>+fi<br>+if [[ ! -f $SRCMNT/$LIVEOS/$HOMEFILE && -n $copyhome ]]; then<br>
+ echo -e "ERROR: There appears to be no persistent /home.img on the source<br>+ Please check your inputs.\n"<br>+ exitclean<br>+fi<br>+if [[ -f $SRCMNT/$LIVEOS/$HOMEFILE && -n $copyhome && -n $cryptedhome ]]; then<br>
+ echo -e "WARNING: You asked for an --encrypted-home and to copy the source's<br>+ /home.img to your target device. The --encrypted-home option is only<br>+ available for newly-created /home directories. (If the /home.img on<br>
+ the source is encrypted, that feature will carry over.)\n<br>+ Press Enter to continue, or Ctrl-c to abort.\n"<br>+ read<br>+fi<br>+if [[ -f $TGTMNT/$LIVEOS/$HOMEFILE && -n $keephome && $homesizemb -gt 0 ]]; then<br>
+ echo -e "ERROR: The target has an existing /home and you requested that a<br>+ new /home.img be created.<br>+ To remove an existing /home on the target, you must explicitly specify<br>+ --delete-home.<br>
+ Please adjust your home options.\n"<br>+ exitclean<br>+fi<br>+if [[ -f $TGTMNT/$LIVEOS/$HOMEFILE && -n $keephome && -n $copyhome && \<br>+ -s $SRCMNT/$LIVEOS/$HOMEFILE ]]; then<br>
+ echo -e "ERROR: The target has an existing /home and you requested that one<br>+ from the source be copied to the target device.<br>+ To remove an existing /home on the target, you must explicitly specify<br>
+ --delete-home.<br>+ Please adjust your home options.\n"<br> exitclean<br> fi<br>+if [[ -s $SRCMNT/$LIVEOS/$HOMEFILE && -n $copyhome && $homesizemb -gt 0 ]]; then<br>+ echo -e "ERROR: You requested a new home AND a copy of one from the source.<br>
+ Please request only one of these options.\n"<br>+ exitclean<br>+fi<br>+if [[ ! -s $SRCLIVEOSDIR/$HOMEFILE && -n $copyhome && $overlaysizemb -gt 0 ]]; then<br>+ echo -e "NOTICE: There appears to be no persistent /home.img on this image.<br>
+ Would you LIKE to continue with just the persistent overlay?\n<br>+ Press Enter to continue, or Ctrl-c to abort.\n"<br>+ read<br>+ copyhome=""<br>+fi<br> <br> if [ -n "$efi" ]; then<br>
if [ -d $SRCMNT/EFI/BOOT ]; then<br>@@ -894,11 +973,11 @@ else<br> fi<br> <br> if [[ live == $srctype ]]; then<br>- targets="$TGTMNT/$SYSLINUXPATH"<br>- [[ -n $efi ]] && targets+=" $TGTMNT$EFI_BOOT"<br>
- [[ -n $xo ]] && targets+=" $TGTMNT/boot/olpc.fth"<br>- duTable=($(du -c -B 1M $targets 2> /dev/null || :))<br>- tbd=$((tbd + ${duTable[*]: -2:1}))<br>+ targets="$TGTMNT/$SYSLINUXPATH"<br>
+ [[ -n $efi ]] && targets+=" $TGTMNT$EFI_BOOT"<br>+ [[ -n $xo ]] && targets+=" $TGTMNT/boot/olpc.fth"<br>+ duTable=($(du -c -B 1M $targets 2> /dev/null || :))<br>+ tbd=$((tbd + ${duTable[*]: -2:1}))<br>
fi<br> <br> if [[ -n $skipcompress ]] && [[ -s $SRCMNT/LiveOS/squashfs.img ]]; then<br>@@ -931,22 +1010,52 @@ if [[ live == $srctype ]]; then<br> [[ -n $xo ]] && sources+=" $SRCMNT/boot/olpc.fth"<br>
duTable=($(du -c -B 1M "$thisScriptpath" $sources 2> /dev/null || :))<br> livesize=$((livesize + ${duTable[*]: -2:1}))<br>+ [[ -s $SRCLIVEOSDIR/$HOMEFILE && -n $copyhome ]] && \<br>
+ copyhomesize=($(du -s -B 1M $SRCLIVEOSDIR/$HOMEFILE))<br>+ if [[ 'iso' == $imgtype ]]; then<br>+ [[ -e $SRCMNT/boot ]] && findargs=$SRCMNT/boot<br>+ findargs+=" $SRCMNT"' -xdev -mindepth 1 -maxdepth 1<br>
+ ( -type d -o -type f )<br>+ ! ( -name isolinux -o -name LiveOS -o -name EFI -o -name olpc.fth )<br>+ -print0'<br>+ fi<br>+ if [[ -n $includes ]]; then<br>+ includes=(${includes[@]/#/$SRCMNT})<br>
+ for i in ${!includes[*]}; do<br>+ if [[ ! -e ${includes[i]} ]]; then<br>+ echo -e "\n${includes[i]#$SRCMNT} does not exist.<br>+ Please check your input. Exiting..."; exitclean<br>
+ fi<br>+ done<br>+ fi<br>+ includes_size=0<br>+ if [[ -n $includes || -n $findargs ]]; then<br>+ duTable=($(find ${includes[*]} $findargs | \<br>+ du -cs -B 1M --files0-from=-))<br>
+ includes_size=${duTable[*]: -2:1}<br>+ fi<br> fi<br> <br> freespace=($(df -B 1M --total $TGTDEV))<br> freespace=${freespace[*]: -2:1}<br> <br> if [[ live == $srctype ]]; then<br>- tba=$((overlaysizemb + homesizemb + livesize + swapsizemb))<br>
+ tba=$((overlaysizemb + homesizemb + copyhomesize + includes_size + \<br>+ livesize + swapsizemb))<br> if ((tba > freespace + tbd)); then<br> needed=$((tba - freespace - tbd))<br>- printf "\n The live image + overlay, home, & swap space, if requested,<br>
- \r will NOT fit in the space available on the target device.\n<br>- \r + Size of live image: %10s MiB\n" $livesize<br>+ printf "\n The live image + overlay, home, includes, & swap space,<br>
+ \r if requested, will NOT fit in the space available on the<br>+ \r target device.\n<br>+ \r + Size of live image: %10s MiB\n" $livesize<br> (($overlaysizemb > 0)) && \<br>
printf " + Overlay size: %16s\n" $overlaysizemb<br> (($homesizemb > 0)) && \<br> printf " + Home directory size: %9s\n" $homesizemb<br>+ (($copyhomesize > 0)) && \<br>
+ printf " + Copy home directory size: %4s\n" $copyhomesize<br>+ (($includes_size > 0)) && \<br>+ printf " + Included files size: %9s\n" $includes_size<br> (($swapsizemb > 0)) && \<br>
printf " + Swap overlay size: %11s\n" $swapsizemb<br> printf " = Total requested space: %6s MiB\n" $tba<br>@@ -1030,6 +1139,18 @@ if [ "$srctype" = "live" -a -z "$skipcopy" ]; then<br>
if [ -f $SRCMNT/LiveOS/osmin.img ]; then<br> copyFile $SRCMNT/LiveOS/osmin.img $TGTMNT/$LIVEOS/osmin.img || exitclean<br> fi<br>+ if [[ -s $SRCLIVEOSDIR/$HOMEFILE && -n $copyhome ]]; then<br>
+ copyFile $SRCLIVEOSDIR/$HOMEFILE $TGTMNT/$LIVEOS/$HOMEFILE || exitclean<br>
+ fi<br>+ cp_mode='-ax'<br>+ [[ 'vfat' == $TGTFS || 'msdos' == $TGTFS ]] && cp_mode='-dRx'<br>+ if [[ 'iso' == $imgtype ]]; then<br>+ find $findargs -exec cp $cp_mode -t $TGTMNT {} + 1> /dev/null ||<br>
+ exitclean<br>+ fi<br>+ if [[ -n $includes ]]; then<br>+ cp $cp_mode -t $TGTMNT ${includes[*]} || exitclean<br>+ fi<br> sync<br> fi<br> <br>@@ -1112,7 +1233,8 @@ if [[ live == $srctype ]]; then<br>
if [[ -d $SRCMNT/syslinux/ ]]; then<br> echo "Preparing boot config file."<br> sed -i -e "s/root=live:[^ ]*/root=live:CDLABEL=name/"\<br>- -e "s/liveimg .* quiet/liveimg quiet/"\<br>
+ -e "s/liveimg .* rd_NO_LUKS/liveimg quiet rhgb rd_NO_LUKS/"\<br>+ -e "s/liveimg .* rd.luks=0/liveimg quiet rhgb rd.luks=0/"\<br> $BOOTCONFIG $BOOTCONFIG_EFI<br>
sed -i -e "s/^timeout.*$/timeout\ 100/"\<br> -e "/^totaltimeout.*$/d" $BOOTCONFIG<br><br></span>