Skip to content

Instantly share code, notes, and snippets.

@suedi
Last active April 17, 2016 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suedi/8897880a873d68ea05f5 to your computer and use it in GitHub Desktop.
Save suedi/8897880a873d68ea05f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Base code produced by 01micko
# Guest Star L18L with code borrowed from yapi
# Promotion by bigpup
# Scooby-Hacked for starhawk 2016-04-05
RUN_LEGACY="true"
[ "$1" = "-n" -o "$1" = "--nolegacy" ] && RUN_LEGACY="false"
fatal() {
echo "$@" && exit
}
echo "I assume you have formatted the drive to ext(2,3,4)"
echo "I'm not babysitting so if it isn't do it now!"
while [ 1 ];do
echo "Is it? (y or n + [Enter/Return])"
read isit
case $isit in
n|N) echo "Bye" && exit;;
*) echo "Assuming you are not stupid..." && break ;;
esac
done
echo "OK, remember.. I'm not responsible here..."
echo "Proceeding..."
echo
echo "Insert your drive and mount it."
echo "Then tell me the target drive partition (eg: sdc1, sdd1 etc)"
echo "GET IT RIGHT!"
while [ 1 ];do
echo "what is the drive partition?"
read DESTPART
case "$DESTPART" in
sd[a-z][0-9]) echo "Seems sane.." && break;;
*) echo "Not sane! try again" && continue;;
esac
done
DESTMNTPT="/mnt/$DESTPART"
ATADRIVES="$DESTPART "
[ -d "$DESTMNTPT" ] || fatal "The mountpoint $DESTMNTPT does not exist."
echo "Ok, $DESTMNTPT exists. Good."
echo
echo "Now we need some source files"
echo "either mount a CD/DVD or an ISO file"
echo "THEN, tell me the mount point path"
echo "EXAMPLE: /mnt/sr0 or /mnt/+mnt+sda5+iso+tahr64-6.0.3.9.iso"
echo "An easy way to do that is enter the mounted folder and type 'pwd' in a terminal"
while [ 1 ];do
echo "Type the source mount point path."
read SRCPATH
case "$SRCPATH" in
/mnt/*) echo "Seems sane.." && break;;
*) echo "Not sane! try again" && continue;;
esac
done
[ -d "$SRCPATH" ] || fatal "The mountpoint $DESTMNTPT does not exist."
echo
echo "Install from $SRCPATH to $DESTMNTPT"
echo "Press y + [Enter/Return] to continue"
read go_on
[ "$go_on" = 'y' -o "$go_on" = 'Y' ] || fatal "Ok, aborting at your request."
echo "---------------------------------------------------------------"
# Set up variables to hook into stolen yapi code
chosenPARTITION="$DESTPART"
ISO="$SRCPATH"
# Actually stolen yapi code
[[ "$DEBUG" ]] && echo cp $ISO/vmlinuz /mnt/${chosenPARTITION}
cp $ISO/vmlinuz /mnt/${chosenPARTITION}
for F in $(ls $ISO/*.sfs); do
echo
echo "Decompressing: ${F}"
echo "To target: /mnt/${chosenPARTITION}"
echo
echo "please have patience."
echo
[[ "$DEBUG" ]] && echo unsquashfs -f -d /mnt/${chosenPARTITION} ${F}
unsquashfs -f -d /mnt/${chosenPARTITION} ${F}
done
mkdir -p /mnt/${chosenPARTITION}/boot
mv /mnt/${chosenPARTITION}/vmlinuz /mnt/${chosenPARTITION}/boot/
sync
# End of stolen yapi code
(cd "$DESTMNTPT"/; ln -sf tmp run)
mkdir -p $DESTMNTPT/sys 2>/dev/null
if [ "$RUN_LEGACY" = "true" ]; then
# LEGACY - pre woof-CE
# OBS! a later call to rc-upate option2hdinstall needs DISTRO_PUPPYSFS to be mounted on $DESTMNTPT/srcmntpt
DISTRO_PUPPYSFS=`ls $SRCPATH|grep '^puppy'|grep 'sfs$'`
#loop-device mount ${DISTRO_PUPPYSFS} in DESTPART, copy contents of ${DISTRO_PUPPYSFS} to DESTPART...
FREE_LOOPDEV="$(losetup-FULL -f)"
[[ "$DEBUG" ]] && echo losetup-FULL "$FREE_LOOPDEV" $SRCPATH/$DISTRO_PUPPYSFS
losetup-FULL "$FREE_LOOPDEV" $SRCPATH/$DISTRO_PUPPYSFS
mkdir "$DESTMNTPT"/srcmntpt
mount -r -t squashfs "$FREE_LOOPDEV" $DESTMNTPT/srcmntpt
KERNELVER=`uname -r`
if [ -d /lib/modules/"$KERNELVER"/initrd ];then
#note, important to not have 'initrd' folder in full hd installation, messes up rc.sysinit.
[[ "$DEBUG" ]] && echo cp -af /lib/modules/"$KERNELVER/initrd"/* "$DESTMNTPT"/lib/modules/$KERNELVER/
cp -af /lib/modules/"$KERNELVER/initrd"/* "$DESTMNTPT"/lib/modules/$KERNELVER/
depmod -b "$DESTMNTPT"
fi
# /bin/TARGETEXES has list of executables that were copied from initrd (and not in main f.s.)...
if [ -f /bin/TARGETEXES ];then
for ONEEXE in `cat /bin/TARGETEXES` #ex: sbin/e2fsck
do
DIREXE="`dirname $ONEEXE`"
[[ "$DEBUG" ]] && echo cp -a -f --remove-destination /${ONEEXE} ${DESTMNTPT}/${DIREXE}/
cp -a -f --remove-destination /${ONEEXE} ${DESTMNTPT}/${DIREXE}/
done
fi
#same thing here...
if [ -d /lib/keymaps ];then
mkdir -p ${DESTMNTPT}/lib/keymaps
[[ "$DEBUG" ]] && echo cp -a -f /lib/keymaps/* ${DESTMNTPT}/lib/keymaps/
cp -a -f /lib/keymaps/* ${DESTMNTPT}/lib/keymaps/
mkdir -p ${DESTMNTPT}/lib/consolefonts
[[ "$DEBUG" ]] && echo cp -a -f /lib/consolefonts/* ${DESTMNTPT}/lib/consolefonts/
cp -a -f /lib/consolefonts/* ${DESTMNTPT}/lib/consolefonts/
fi
# END LEGACY
rm -f $DESTMNTPT/var/log/modprobes.log 2>/dev/null #v2.13 see /sbin/modprobe script.
#...not necessary, not using this any more.
echo '#ATADRIVES is all internal ide/pata/sata drives...' >> $DESTMNTPT/etc/rc.d/PUPSTATE
echo "ATADRIVES='$ATADRIVES'" >> $DESTMNTPT/etc/rc.d/PUPSTATE
sync
# run rc.update
if [ -f "$DESTMNTPT"/etc/puppyversion ];then #historical file, old installations.
[[ "$DEBUG" ]] && echo echo -n "0.0" > $DESTMNTPT/etc/puppyversion #set it back to what it was.
echo -n "0.0" > $DESTMNTPT/etc/puppyversion #set it back to what it was.
fi
if [ -f "$DESTMNTPT"/etc/DISTRO_SPECS ];then
vPATTERN="s%^DISTRO_VERSION=.*%DISTRO_VERSION='0.0'%" #110422
sed -e "$vPATTERN" $DESTMNTPT/etc/DISTRO_SPECS > /tmp/distro_specs_old
[[ "$DEBUG" ]] && echo cp -f /tmp/distro_specs_old $DESTMNTPT/etc/DISTRO_SPECS #set DISTRO_VERSION back to what it was.
cp -f /tmp/distro_specs_old $DESTMNTPT/etc/DISTRO_SPECS #set DISTRO_VERSION back to what it was.
fi
#busybox chroot does not have -c ...
FLAGDEVMISS=0
if [ ! -e "$DESTMNTPT"/dev/null ];then #1 recent pups have empty /dev. rc.update may need these...
[[ "$DEBUG" ]] && echo cp -a /dev/console $DESTMNTPT/dev/
cp -a /dev/console $DESTMNTPT/dev/
cp -a /dev/null $DESTMNTPT/dev/
FLAGDEVMISS=1
fi
[[ "$DEBUG" ]] && echo chroot $DESTMNTPT /etc/rc.d/rc.update option2hdinstall
chroot $DESTMNTPT /etc/rc.d/rc.update option2hdinstall
if [ "$FLAGDEVMISS" -eq 1 ];then #130613
[[ "$DEBUG" ]] && echo rm -f $DESTMNTPT/dev/console
rm -f $DESTMNTPT/dev/console
rm -f $DESTMNTPT/dev/null
fi
#(need to tell rc.update where src files are, as passed param)
sync
mv -f $DESTMNTPT/etc/fstab $DESTMNTPT/etc/fstab.bak
echo "/dev/$DESTPART / $DESTFS defaults 0 1" > $DESTMNTPT/etc/fstab
echo "none /proc proc defaults 0 0" >> $DESTMNTPT/etc/fstab
echo "none /sys sysfs defaults 0 0" >> $DESTMNTPT/etc/fstab
echo "none /dev/pts devpts gid=2,mode=620 0 0" >> $DESTMNTPT/etc/fstab
echo "/dev/fd0 /mnt/floppy auto noauto,rw 0 0" >> $DESTMNTPT/etc/fstab
sync
[[ "$DEBUG" ]] && echo umount $DESTMNTPT/srcmntpt
[[ "$DEBUG" ]] && umount $DESTMNTPT/srcmntpt || umount $DESTMNTPT/srcmntpt 2>/dev/null
[[ "$DEBUG" ]] && rmdir $DESTMNTPT/srcmntpt || rmdir $DESTMNTPT/srcmntpt 1>/dev/null 2>&1
fi
echo "---------------------------------------------------------------"
echo
echo "Hopefully we're done ..."
echo
echo "To make this install bootable you need to run grub4dosconfig to"
echo "install a bootloader to the USB drive. In Grub4dosconfig -choose"
echo "to install to the USB drive and choose selection: search only"
echo "within this device."
echo
echo "If your target is a USB drive then don'"'t forget to add "rootwait"'
echo "in the Options textbox, it'"'s the one that has the value "ro"'
echo "in it by default."
echo
echo "That would be in the grub4dosconfig window with title:"
echo
echo '"Grub4DosConfig - List of detected operating systems"'
echo
echo "This is essential for a successful boot."
echo
echo "Now proceed by running grub4dosconfig to complete the install"
echo "and making it bootable."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment