305 lines
8.0 KiB
Bash
Executable File
305 lines
8.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
START_DIR_DONT_CHANGE=`pwd`
|
|
SELF=$(basename "$0")
|
|
|
|
# required config items
|
|
CONFFILE=$HOME/.libburnia-releng/${SELF}.conf
|
|
GEN_DATA_DIR=releng_generated_data/${SELF}
|
|
TMP_DATA_DIR=releng_generated_data
|
|
IMG_EXTRACT_DIR=${GEN_DATA_DIR}/${SELF}_extracted_tree
|
|
|
|
# to be set by the config file
|
|
RELENG_XORRISO=""
|
|
|
|
RELENG_DIR="${IMG_EXTRACT_DIR}"
|
|
RELENG_ISOLINUX_BIN="isolinux/isolinux.bin"
|
|
RELENG_BOOT_CAT="isolinux/boot.cat"
|
|
RELENG_IMG=t1
|
|
|
|
KEEP=0
|
|
RES=""
|
|
|
|
REMOTE_URL="http://cdimage.debian.org/cdimage/daily-builds/daily/current/i386/iso-cd"
|
|
REMOTE_IMG="debian-testing-i386-businesscard.iso"
|
|
|
|
#####
|
|
print_help() {
|
|
cat << HLP
|
|
Usage:
|
|
${SELF} -help
|
|
|
|
# using a config file ${CONFFILE}
|
|
${SELF} -rc [-keep]
|
|
|
|
# without using a config file
|
|
${SELF} /absolute/or/relative/path/to/xorriso [-keep]
|
|
|
|
# cleanup test generated data directory and exit
|
|
${SELF} -cleanup
|
|
HLP
|
|
}
|
|
|
|
#####
|
|
cleanup() {
|
|
if [ ${KEEP} -eq 0 ]; then
|
|
# safety net, just in case -> we want to be in the starting
|
|
# directory before removing whatever self-generated stuff
|
|
if [ -d "${GEN_DATA_DIR}" ]; then
|
|
cd "${START_DIR_DONT_CHANGE}" || exit 15
|
|
chmod +w -R ${GEN_DATA_DIR}
|
|
rm -rf ${GEN_DATA_DIR}
|
|
printf "${SELF}: Removed (self-generated) %s\n" ${GEN_DATA_DIR}
|
|
else
|
|
printf "${SELF}: ${GEN_DATA_DIR} does not exist. Nothing to clean.\n"
|
|
fi
|
|
else
|
|
printf "${SELF}: Leaving (self-generated) %s\n" ${GEN_DATA_DIR}
|
|
fi
|
|
}
|
|
|
|
# cleanup
|
|
if [ "${1}" == "-cleanup" ]; then
|
|
cleanup
|
|
exit 0
|
|
fi
|
|
|
|
# help
|
|
if [ ! "${1}" ]; then
|
|
print_help && exit 3
|
|
# config file
|
|
elif [ "${1}" == "-rc" -a "${2}" == "-keep" ]; then
|
|
KEEP=1
|
|
if [ -e ${CONFFILE} ]; then
|
|
. ${CONFFILE}
|
|
printf "${SELF}: Using config file %s\n" ${CONFFILE}
|
|
else
|
|
echo -e "\n${SELF}: Config file ${CONFFILE} not found.\n" && exit 4
|
|
fi
|
|
elif [ "${1}" == "-rc" -a ! "${2}" ]; then
|
|
KEEP=0
|
|
if [ -e ${CONFFILE} ]; then
|
|
. ${CONFFILE}
|
|
printf "${SELF}: Using config file %s\n" ${CONFFILE}
|
|
else
|
|
echo -e "\n${SELF}: Config file ${CONFFILE} not found.\n" && exit 4
|
|
fi
|
|
# cmdline option
|
|
elif [ -x "${1}" -a "${2}" == "-keep" ]; then
|
|
RELENG_XORRISO="${1}"
|
|
KEEP=1
|
|
elif [ -x "${1}" ]; then
|
|
RELENG_XORRISO="${1}"
|
|
KEEP=0
|
|
# the rest
|
|
else
|
|
print_help && exit 5
|
|
fi
|
|
|
|
#
|
|
if [ "${RELENG_XORRISO}" == "" -o "${RELENG_DIR}" == "" -o "${RELENG_IMG}" == "" ]; then
|
|
echo -e "\n${SELF}: xorriso_cmd IN_dir and OUT_image are required\n"
|
|
exit 6
|
|
fi
|
|
|
|
if [ ! -x "${RELENG_XORRISO}" ]; then
|
|
printf "${SELF}: $RELENG_XORRISO not found or not an executable.\n"
|
|
exit 7
|
|
fi
|
|
|
|
# data dir
|
|
if [ -d "${GEN_DATA_DIR}" ]; then
|
|
printf "\n${SELF}: directory %s exists!" ${GEN_DATA_DIR}
|
|
printf "\n${SELF}: use '${SELF} -cleanup' to remove.\n"
|
|
exit 8
|
|
else
|
|
mkdir "${GEN_DATA_DIR}"
|
|
fi
|
|
|
|
# All must be set at this point
|
|
printf "${SELF}: Config items:"
|
|
printf "\n\txorriso_cmd=${RELENG_XORRISO}\n\tIN_dir=${RELENG_DIR}\n\tOUT_image=${RELENG_IMG}.iso"
|
|
printf "\n\tIN_isolinux=${RELENG_ISOLINUX_BIN}\n\tOUT_bootcat=${RELENG_BOOT_CAT}\n"
|
|
RES="${RELENG_IMG}.iso ${RELENG_IMG}.new ${RELENG_IMG}.md5 ${RELENG_IMG}.jigdo ${RELENG_IMG}.template"
|
|
|
|
# xorriso version details, incl. underlying libraries
|
|
"${RELENG_XORRISO}" -version
|
|
if ! "${RELENG_XORRISO}" -version | grep libjte >/dev/null 2>&1; then
|
|
printf "\n${SELF}: JTE not supported with this xorriso build. Install jigit >=1.18 and rebuild."
|
|
printf "\n${SELF}: http://www.einval.com/~steve/software/JTE/\n"
|
|
cleanup
|
|
exit 9
|
|
fi
|
|
|
|
# remove cruft from previous runs
|
|
# rm -f ${RES}
|
|
|
|
# grab remote ISO image, to decompose
|
|
if [ ! -f "${TMP_DATA_DIR}"/"${REMOTE_IMG}" ]; then
|
|
printf "\n${SELF}: Downloading ${REMOTE_URL}/${REMOTE_IMG}\n"
|
|
wget --no-check-certificate -T20 -t3 -O \
|
|
"${TMP_DATA_DIR}"/"${REMOTE_IMG}" "${REMOTE_URL}"/"${REMOTE_IMG}"
|
|
WGET_RET="$?"
|
|
case ${WGET_RET} in
|
|
0)
|
|
echo -e "\n${SELF}: Downloading successfully completed.\n"
|
|
;;
|
|
*)
|
|
echo -e "\n${SELF}: FAIL: wget returned code: $WGET_RET\n"
|
|
cleanup
|
|
exit 10
|
|
;;
|
|
esac
|
|
else
|
|
printf "\n${SELF}: Found ISO image: ${TMP_DATA_DIR}/${REMOTE_IMG}\n"
|
|
fi
|
|
|
|
# check for extraction directory existence
|
|
if [ -d "${IMG_EXTRACT_DIR}" ]; then
|
|
printf "\n${SELF}: Found ${IMG_EXTRACT_DIR}. Please cleanup.\n"
|
|
cleanup
|
|
exit 11
|
|
else
|
|
mkdir "${IMG_EXTRACT_DIR}"
|
|
fi
|
|
|
|
# extract image content
|
|
CMD_EXTRACT="${RELENG_XORRISO} -indev ${TMP_DATA_DIR}/${REMOTE_IMG} \
|
|
-osirrox on:auto_chmod_on \
|
|
-extract / ${IMG_EXTRACT_DIR} \
|
|
"
|
|
|
|
# TODO: drop set +e|-e block, catch exit code instead when
|
|
# the boot catalog warnings get completely resolved.
|
|
echo -e "${SELF}: Extracting ISO image:\n${CMD_EXTRACT}\n"
|
|
set +e
|
|
${CMD_EXTRACT}
|
|
set -e
|
|
|
|
# grab an MBR
|
|
ISOHYBRID_MBR="${GEN_DATA_DIR}/isohybrid.mbr"
|
|
dd if="${TMP_DATA_DIR}/${REMOTE_IMG}" bs=1K count=32 of="${ISOHYBRID_MBR}"
|
|
|
|
# create FAT partition
|
|
APPEND_PART="${GEN_DATA_DIR}/fatpart.fat"
|
|
MKFS_MSDOS="/sbin/mkfs.msdos"
|
|
if [ -x "${MKFS_MSDOS}" ]; then
|
|
"${MKFS_MSDOS}" -n Bla -C "${APPEND_PART}" 8192
|
|
else
|
|
printf "\n${SELF}: Not found: "${MKFS_MSDOS}". Install dosfstools."
|
|
printf "\n${SELF}: http://www.daniel-baumann.ch/software/dosfstools/\n"
|
|
cleanup
|
|
exit 12
|
|
fi
|
|
|
|
# GENERAL section
|
|
CMD="${RELENG_XORRISO} \
|
|
-as mkisofs \
|
|
-quiet \
|
|
-o ${GEN_DATA_DIR}/${RELENG_IMG}.iso \
|
|
-R \
|
|
-V ISOJIGDO \
|
|
-partition_offset 16 \
|
|
-J -joliet-long \
|
|
"
|
|
|
|
# BOOT section
|
|
if [ -f "${IMG_EXTRACT_DIR}"/"${RELENG_ISOLINUX_BIN}" -a -f "${ISOHYBRID_MBR}" -a -f "${APPEND_PART}" ]; then
|
|
CMD+="\
|
|
-b ${RELENG_ISOLINUX_BIN} \
|
|
-c ${RELENG_BOOT_CAT} \
|
|
-no-emul-boot -boot-load-size 4 -boot-info-table \
|
|
-isohybrid-mbr ${ISOHYBRID_MBR} \
|
|
-partition_offset 16 \
|
|
-append_partition 2 0x01 ${APPEND_PART} \
|
|
"
|
|
else
|
|
printf "\n${SELF}: FAIL to compose the boot section.\n"
|
|
cleanup
|
|
exit 13
|
|
fi
|
|
|
|
# JIGDO section
|
|
JIGDO_JIGDO=${GEN_DATA_DIR}/${RELENG_IMG}.jigdo
|
|
JIGDO_TEMPLATE=${GEN_DATA_DIR}/${RELENG_IMG}.template
|
|
JIGDO_MAP_RHV=`readlink -e ${RELENG_DIR}`
|
|
JIGDO_MAP="Debian=${JIGDO_MAP_RHV}/"
|
|
|
|
# create jigdo MD5 list in base64 format
|
|
JIGDO_GEN_MD5=${GEN_DATA_DIR}/${RELENG_IMG}.md5
|
|
if which jigdo-gen-md5-list >/dev/null 2>&1; then
|
|
printf "${SELF}: Creating MD5 list in hex format in ${JIGDO_GEN_MD5}..."
|
|
jigdo-gen-md5-list ${RELENG_DIR} > ${JIGDO_GEN_MD5}
|
|
printf "Done.\n"
|
|
else
|
|
printf "\n${SELF}: Not found: jigdo-gen-md5-list. Install jigit >= 1.18."
|
|
printf "\n${SELF}: http://www.einval.com/~steve/software/JTE/\n"
|
|
cleanup
|
|
exit 14
|
|
fi
|
|
|
|
CMD+="\
|
|
-jigdo-template-compress gzip \
|
|
-checksum_algorithm_iso md5,sha1,sha256,sha512 \
|
|
-checksum_algorithm_template md5,sha1,sha256,sha512 \
|
|
-jigdo-jigdo ${JIGDO_JIGDO} \
|
|
-jigdo-template ${JIGDO_TEMPLATE} \
|
|
-jigdo-map ${JIGDO_MAP} \
|
|
-md5-list ${JIGDO_GEN_MD5} \
|
|
-jigdo-min-file-size 1024 \
|
|
"
|
|
|
|
CMD+="${RELENG_DIR}"
|
|
|
|
# Run the whole compound command
|
|
echo -e "${SELF}: Creating ISO and jigdo representations:\n$CMD\n"
|
|
${CMD}
|
|
|
|
# Create another imange this time from jigdo files
|
|
if which jigit-mkimage >/dev/null 2>&1; then
|
|
printf "${SELF}: Creating new ISO from jigdo files..."
|
|
jigit-mkimage \
|
|
-t ${JIGDO_TEMPLATE} \
|
|
-j ${JIGDO_JIGDO} \
|
|
-m ${JIGDO_MAP} \
|
|
-o ${GEN_DATA_DIR}/${RELENG_IMG}.new
|
|
printf "Done.\n"
|
|
else
|
|
printf "\n${SELF}: Not found: jigit-mkimage. Install jigit."
|
|
printf "\n${SELF}: http://www.einval.com/~steve/software/JTE/\n"
|
|
cleanup
|
|
exit 15
|
|
fi
|
|
|
|
# trap the exit code of diff and let the Universe explode
|
|
diff ${GEN_DATA_DIR}/${RELENG_IMG}.iso ${GEN_DATA_DIR}/${RELENG_IMG}.new
|
|
DIFF_RET="$?"
|
|
case ${DIFF_RET} in
|
|
0)
|
|
echo -e "${SELF}: Match: diff ${GEN_DATA_DIR}/${RELENG_IMG}.iso ${GEN_DATA_DIR}/${RELENG_IMG}.new"
|
|
;;
|
|
*)
|
|
echo -e "${SELF}: FAIL: diff returned code: $DIFF_RET\n"
|
|
;;
|
|
esac
|
|
|
|
# sort out the cruft
|
|
cleanup
|
|
|
|
# warn about downloaded image left behind
|
|
if [ -f "${TMP_DATA_DIR}"/"${REMOTE_IMG}" ]; then
|
|
printf "${SELF}: Leaving "
|
|
ls -sh "${TMP_DATA_DIR}"/"${REMOTE_IMG}"
|
|
fi
|
|
|
|
# last hints
|
|
printf "\n${SELF}: HINT: manual checks remained to be done:\n"
|
|
printf " * ${GEN_DATA_DIR}/${RELENG_IMG}.iso boots from USB stick and/or optical media.\n"
|
|
printf " * appended FAT partition is mountable.\n"
|
|
printf " * xorriso -indev ${GEN_DATA_DIR}/${RELENG_IMG}.iso -pvd_info\n"
|
|
printf " * fdisk -lu ${GEN_DATA_DIR}/${RELENG_IMG}.iso\n"
|
|
|
|
exit 0
|