legacy/libisoburn/trunk/releng/releng_build_isojigdo

193 lines
5.0 KiB
Bash
Executable File

#!/bin/bash
set -e
START_DIR_DONT_CHANGE=`pwd`
# required config items
XOR=""
DIR=""
IMG=""
# optional config items
ISOLINUX_BIN=""
BOOT_CAT=""
CONFFILE=$HOME/releng_build_isojigdo.conf
CLEAN=0
GEN_DATA_DIR=$0.result
RES=""
print_help() {
cat << HLP
Usage:
$0 -help
# using a config file ${CONFFILE}
$0 -rc [-clean]
# without using a config file
$0 xorriso_cmd IN_dir OUT_image [IN_isolinux] [OUT_bootcat] [-clean]
HLP
}
#####################################################################
if [ -d "${GEN_DATA_DIR}" ]; then
printf "\n$0: %s exists!\n" ${GEN_DATA_DIR}
exit 2
else
mkdir "${GEN_DATA_DIR}"
fi
# help
if [ ! "${1}" ]; then print_help && exit 10; fi
# config file
if [ "${1}" == "-rc" ]; then
if [ -e ${CONFFILE} ]; then
. ${CONFFILE}
printf "$0: Using config file %s\n" ${CONFFILE}
else
echo -e "\n$0: Config file ${CONFFILE} not found.\n" && exit 20
fi
if [ "${2}" == "-clean" ]; then CLEAN=1; fi
# command line args
elif [ "${3}" ]; then
XOR="${1}"
DIR="${2}"
IMG="${3}"
if [ "${4}" ]; then
ISOLINUX_BIN="${4}"
if [ "${5}" ]; then BOOT_CAT="${5}"; fi
if [ "${4}" == "-clean" -o "${5}" == "-clean" -o "${6}" == "-clean" ]; then CLEAN=1; fi
fi
# the rest
else
print_help && exit 30
fi
if [ "${XOR}" == "" -o "${DIR}" == "" -o "${IMG}" == "" ]; then
echo -e "\n$0: xorriso_cmd IN_dir and OUT_image are required\n"
exit 40
fi
if [ ! -x "${XOR}" ]; then
printf "$0: Not found or not an executable: $XOR\n"
exit 50
fi
# all must be set at this point
printf "$0: Config items:"
printf "\n\txorriso_cmd=${XOR}\n\tIN_dir=${DIR}\n\tOUT_image=${IMG}.iso"
printf "\n\tIN_isolinux=${ISOLINUX_BIN}\n\tOUT_bootcat=${BOOT_CAT}\n"
RES="${IMG}.iso ${IMG}.new ${IMG}.md5 ${IMG}.jigdo ${IMG}.template"
# xorriso version details, incl. underlying libraries
"${XOR}" -version
if ! "${XOR}" -version | grep libjte >/dev/null 2>&1; then
printf "\n$0: JTE not supported with this xorriso build. Install jigit and rebuild."
printf "\n$0: See http://www.einval.com/~steve/software/JTE/\n"
exit 51
fi
# remove cruft from previous runs
# rm -f ${RES}
# grab an MBR
# dd if=some.iso bs=1K count=32 of=somembr.sysarea
# create FAT partition
# /sbin/mkfs.msdos -n Bla -C fatpart.fat 8192
# create MD5 list in base64 format
if which jigdo-gen-md5-list >/dev/null 2>&1; then
printf "$0: Creating MD5 list in hex format..."
jigdo-gen-md5-list ${DIR} > ${GEN_DATA_DIR}/${IMG}.md5
printf "Done.\n"
else
printf "\n$0: Not found: jigdo-gen-md5-list. Install jigit."
printf "\n$0: See http://www.einval.com/~steve/software/JTE/\n"
exit 60
fi
# build the command - general section
CMD="${XOR} \
-as mkisofs \
-quiet \
-o ${GEN_DATA_DIR}/${IMG}.iso \
-R \
-V ISOJIGDO \
-partition_offset 16 \
-J -joliet-long \
"
# boot section TODO
#if [ "${ISOLINUX_BIN}" -a "${BOOT_CAT}" ]; then
#CMD+=\
# -b ${ISOLINUX_BIN} \ # NOTE: boot/isolinux/isolinux.bin
# -c ${BOOT_CAT} \ # NOTE: boot/boot.cat
# -no-emul-boot -boot-load-size 4 -boot-info-table \
# -isohybrid-mbr somembr.sysarea \ # TODO: figure out where to grab one
# -partition_offset 16 \
# -append_partition 2 0x01 fatpart.fat \ # TODO: create one unconditionally?
#fi
# jigdo section
CMD+="\
-jigdo-template-compress gzip \
-checksum_algorithm_iso md5,sha1,sha256,sha512 \
-checksum_algorithm_template md5,sha1,sha256,sha512 \
-jigdo-jigdo ${GEN_DATA_DIR}/${IMG}.jigdo \
-jigdo-template ${GEN_DATA_DIR}/${IMG}.template \
-jigdo-map Debian=${DIR} \
-md5-list ${GEN_DATA_DIR}/${IMG}.md5 \
-jigdo-min-file-size 1024 \
"
CMD+="${DIR}"
# run it
echo -e "$0: Creating ISO and jigdo representations:\n$CMD\n"
${CMD}
# create another one from jigdo files
if which jigit-mkimage >/dev/null 2>&1; then
printf "$0: Creating new ISO from jigdo files..."
jigit-mkimage \
-t ${GEN_DATA_DIR}/${IMG}.template \
-j ${GEN_DATA_DIR}/${IMG}.jigdo \
-m Debian=${DIR} \
-o ${GEN_DATA_DIR}/${IMG}.new
printf "Done.\n"
else
printf "\n$0: Not found: jigit-mkimage. Install jigit."
printf "\n$0: See http://www.einval.com/~steve/software/JTE/\n"
exit 70
fi
# trap the exit code of diff and let the Universe explode
diff ${GEN_DATA_DIR}/${IMG}.iso ${GEN_DATA_DIR}/${IMG}.new
DIFF_RET="$?"
case ${DIFF_RET} in
0)
echo -e "$0: diff ${GEN_DATA_DIR}/${IMG}.iso ${GEN_DATA_DIR}/${IMG}.new matched.\n"
;;
*)
echo -e "$0: FAIL: diff returned code: $DIFF_RET\n"
;;
esac
# sort out the cruft
if [ ${CLEAN} -eq 1 ]; then
# safety net, just in case -> we want to be in the starting
# directory before removing whatever self-generated stuff
cd "${START_DIR_DONT_CHANGE}" || exit 80
rm -rf ${GEN_DATA_DIR}
printf "$0: removed %s\n" ${GEN_DATA_DIR}
else
printf "$0: left %s\n" ${GEN_DATA_DIR}
fi
# last hints
printf "\n$0: HINT: manual checks remained to be done:\n"
printf " * ${IMG}.img boots from USB stick and/or optical media.\n"
printf " * appended FAT partition is mountable.\n"
printf " * xorriso -indev ${IMG}.iso -pvd_info\n"
printf " * fdisk -lu ${IMG}.iso\n"
exit 0