autoinst

scripts to make automated installations of debian easy
git clone git://deadbeef.fr/autoinst.git
Log | Files | Refs | README | LICENSE

mkiso.sh (3270B)


      1 #!/bin/sh -e
      2 
      3 die()
      4 {
      5 	echo $@
      6 	exit 1
      7 }
      8 
      9 SRC="${1:?"No source specified"}"
     10 DST="${2:?"No destination specified"}"
     11 
     12 test -e "${DST}" -a \( -b "${DST}" -o -f "${DST}" \) ||
     13 	die "Destination must be either a block or a normal file if already existing"
     14 test -d "${SRC}" ||
     15 	die "Source must be an existing directory"
     16 test "$(id -u)" == "0" ||
     17 	die "This script must run with root rights"
     18 
     19 missing_file=""
     20 for file in "etc/fstab"
     21 do
     22 	test -f "${SRC}/${file}" || missing_file="${missing_file} ${file}"
     23 done
     24 test -z "${missing_file}" ||
     25 	die "Some needed files where not found in template: ${missing_file}"
     26 
     27 #TODO: some cmds are not needed by all usages
     28 #TODO: some can also be provided by busybox...
     29 missing_cmd=""
     30 for cmd in debootstrap sfdisk awk cryptsetup
     31 do
     32 	which "${cmd}" > /dev/null || missing_cmd="${missing_cmd} ${cmd}"
     33 done
     34 if test -n "${missing_cmd}"
     35 then
     36 	echo "Some needed commands where not found: ${missing_cmd}"
     37 	echo -n "Continue anyway? (yes/no) "
     38 	read ans
     39 	test "${ans}" != "yes" || die "Aborting."
     40 fi
     41 
     42 if test ! -e "${DST}"
     43 then
     44 	die "TODO: install in a chroot"
     45 fi
     46 
     47 fstab="${SRC}/etc/fstab"
     48 ROOT_MNT="$(awk '$2=="/"{print $1}' "${fstab}")"
     49 test -n "${ROOT_MNT}" ||
     50 	die "Unable to find a line in etc/fstab describing root file system"
     51 
     52 #partitionning, encryption and file systems
     53 sfdisk "${DST}" < "${SRC}"/template/partitions
     54 
     55 if test -f "${SRC}/etc/crypttab"
     56 then
     57 	die "TODO: handle cryptab"
     58 fi
     59 
     60 if test -d "${SRC}/template/encryption.d"
     61 then
     62 	for cryptfs in $(find "${SRC}/template/encryption.d" -maxdepth 1 -type f)
     63 	do
     64 		. "${SRC}/template/encryption.d/${cryptfs}"
     65 		cryptsetup \
     66 			-c "${CIPHER:?"no CIPHER"}" \
     67 			-s "${KEYSZ:?"no KEYSZ"}" \
     68 			-h "${HASH:?"no HASH"}" \
     69 			luskFormat "${PART:?"no PATH"}" - < "${KEYFILE:?"no KEYFILE"}"
     70 		#TODO: close cleanly at end of operations
     71 		cryptsetup open "${PART}" "${}"
     72 	done
     73 fi
     74 $(awk '$3!="tmpfs" {printf "mkfs.%s %s;\n", $3, $1}' "${fstab}")
     75 
     76 MNT="$(mktemp -d)"
     77 mount "${ROOT_MNT}" "${MNT}"
     78 mkdir $(printf "${MNT}/%s\n" $(awk '$2 != "/" && $3!="tmpfs" {print $2}' /etc/fstab))
     79 
     80 
     81 rm -r iso_dir/*
     82 PKG_LIST="${PKG_LIST},isolinux,syslinux-common,syslinux,syslinux-efi"
     83 PKG_LIST="${PKG_LIST},busybox"
     84 PKG_LIST="${PKG_LIST},linux-image-amd64"
     85 PKG_LIST="${PKG_LIST},runit-init"
     86 PKG_LIST="${PKG_LIST},udhcpc"
     87 PKG_LIST="${PKG_LIST},lynx"
     88 PKG_LIST="${PKG_LIST},dialog"
     89 PKG_LIST="${PKG_LIST},kbd,console-data"
     90 PKG_LIST="${PKG_LIST},ntpdate"
     91 PKG_LIST="${PKG_LIST},dropbear-bin"
     92 PKG_LIST="${PKG_LIST},debootstrap"
     93 
     94 if test "${stage:=DEBUG}" = "DEBUG"
     95 then
     96 	PKG_LIST="${PKG_LIST},psmisc"
     97 	cat <<EOF
     98 ===========================
     99 == this is a debug setup ==
    100 ===========================
    101 EOF
    102 	set -x
    103 fi
    104 
    105 BOOTSTRAPOPT="--no-merged-usr --variant=minbase"
    106 
    107 debootstrap $BOOTSTRAPOPT "--include=$PKG_LIST" buster iso_dir $MIRROR
    108 
    109 cp -ar syslinux iso_dir
    110 cp -ar etc/* iso_dir/etc
    111 
    112 chpasswd -R $(pwd)/iso_dir <<EOF
    113 root:toor
    114 EOF
    115 
    116 rm -r iso_dir/var/cache/apt/* iso_dir/var/log/*
    117 
    118 ./busybox.sh iso_dir
    119 
    120 xorriso -as mkisofs \
    121 	-r -V 'CUSTOM_ISO_AMD64' \
    122 	-o custom.iso \
    123 	-J -joliet-long \
    124 	-isohybrid-gpt-basdat \
    125 	-isohybrid-mbr iso_dir/usr/lib/ISOLINUX/isohdpfx.bin \
    126 	-boot-load-size 4 -boot-info-table -eltorito-alt-boot -b usr/lib/ISOLINUX/isolinux.bin \
    127 	-no-emul-boot \
    128 	iso_dir \
    129 	2>&1 | grep -vi 'WARNING.*Symlinks'