autoinst

scripts to make installation of custom debian easier and more automated
git clone git://deadbeef.fr/autoinst.git
Log | Files | Refs | README | LICENSE

commit 89732d9c5da582bc932547d91eccfa70db5289b6
parent da82c7837a41912e677709fbd3a5653a1eaf4839
Author: Morel BĂ©renger <berengermorel76@gmail.com>
Date:   Wed, 29 Jul 2020 08:34:02 +0200

Will be ditched soon

old title was:
add sanity checks to mkiso.sh & prepare features

features in prep:

* template management
* encrypted installs

Diffstat:
Mmkiso.sh | 80++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 79 insertions(+), 1 deletion(-)

diff --git a/mkiso.sh b/mkiso.sh @@ -1,4 +1,82 @@ -#!/bin/sh +#!/bin/sh -e + +die() +{ + echo $@ + exit 1 +} + +SRC="${1:?"No source specified"}" +DST="${2:?"No destination specified"}" + +test -e "${DST}" -a \( -b "${DST}" -o -f "${DST}" \) || + die "Destination must be either a block or a normal file if already existing" +test -d "${SRC}" || + die "Source must be an existing directory" +test "$(id -u)" == "0" || + die "This script must run with root rights" + +missing_file="" +for file in "etc/fstab" +do + test -f "${SRC}/${file}" || missing_file="${missing_file} ${file}" +done +test -z "${missing_file}" || + die "Some needed files where not found in template: ${missing_file}" + +#TODO: some cmds are not needed by all usages +#TODO: some can also be provided by busybox... +missing_cmd="" +for cmd in debootstrap sfdisk awk cryptsetup +do + which "${cmd}" > /dev/null || missing_cmd="${missing_cmd} ${cmd}" +done +if test -n "${missing_cmd}" +then + echo "Some needed commands where not found: ${missing_cmd}" + echo -n "Continue anyway? (yes/no) " + read ans + test "${ans}" != "yes" || die "Aborting." +fi + +if test ! -e "${DST}" +then + die "TODO: install in a chroot" +fi + +fstab="${SRC}/etc/fstab" +ROOT_MNT="$(awk '$2=="/"{print $1}' "${fstab}")" +test -n "${ROOT_MNT}" || + die "Unable to find a line in etc/fstab describing root file system" + +#partitionning, encryption and file systems +sfdisk "${DST}" < "${SRC}"/template/partitions + +if test -f "${SRC}/etc/crypttab" +then + die "TODO: handle cryptab" +fi + +if test -d "${SRC}/template/encryption.d" +then + for cryptfs in $(find "${SRC}/template/encryption.d" -maxdepth 1 -type f) + do + . "${SRC}/template/encryption.d/${cryptfs}" + cryptsetup \ + -c "${CIPHER:?"no CIPHER"}" \ + -s "${KEYSZ:?"no KEYSZ"}" \ + -h "${HASH:?"no HASH"}" \ + luskFormat "${PART:?"no PATH"}" - < "${KEYFILE:?"no KEYFILE"}" + #TODO: close cleanly at end of operations + cryptsetup open "${PART}" "${}" + done +fi +$(awk '$3!="tmpfs" {printf "mkfs.%s %s;\n", $3, $1}' "${fstab}") + +MNT="$(mktemp -d)" +mount "${ROOT_MNT}" "${MNT}" +mkdir $(printf "${MNT}/%s\n" $(awk '$2 != "/" && $3!="tmpfs" {print $2}' /etc/fstab)) + rm -r iso_dir/* PKG_LIST="${PKG_LIST},isolinux,syslinux-common,syslinux,syslinux-efi"