archiso/archiso2dual/archiso2dual
Gerardo Exequiel Pozzi 85d2ddd762 Unify scheme of sed replacements.
Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
2010-12-07 23:48:24 -03:00

415 lines
13 KiB
Bash
Executable File

#!/bin/bash
#
# Join two Arch Linux iso images of i686 and x86_64 architecture.
# Contributed for archiso by Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
#
set -e -u
publisher="Arch Linux <http://www.archlinux.org>"
application="Arch Linux Live/Rescue disk"
label="ARCH_$(date +%Y%m)"
isofile_i686=""
isofile_x86_64=""
imgname=""
quiet="y"
profile_type="basic"
work_dir="/tmp/archiso2dual"
isomounts_file="/usr/share/archiso2dual/isomounts"
syslinuxcfg_dir="/usr/share/archiso2dual/syslinux"
removefiles_file="/usr/share/archiso2dual/removefiles.lst"
compression="gzip"
install_dir="arch"
appname=${0##*/}
_error="0"
_confirm="n"
_v=""
_iscoreiso=n
iso_umount() {
echo "Executing: ${FUNCNAME}"
trap - 0 1 2 15
umount ${_v} ${work_dir}/i686/mnt
umount ${_v} ${work_dir}/x86_64/mnt
}
iso_mount() {
echo "Executing: ${FUNCNAME}"
trap 'iso_umount' 0 1 2 15
mount ${_v} -t udf -o ro,loop ${isofile_i686} ${work_dir}/i686/mnt
mount ${_v} -t udf -o ro,loop ${isofile_x86_64} ${work_dir}/x86_64/mnt
}
kernel_copy() {
echo "Executing: ${FUNCNAME}"
for _arch in i686 x86_64; do
cp ${_v} ${work_dir}/${_arch}/mnt/${install_dir}/boot/${_arch}/archiso.img ${work_dir}/iso/${install_dir}/boot/${_arch}/archiso.img
cp ${_v} ${work_dir}/${_arch}/mnt/${install_dir}/boot/${_arch}/vmlinuz26 ${work_dir}/iso/${install_dir}/boot/${_arch}/vmlinuz26
done
}
syslinux_copy() {
echo "Executing: ${FUNCNAME}"
cp ${_v} ${work_dir}/i686/mnt/${install_dir}/boot/{memtest*,splash.png} ${work_dir}/iso/${install_dir}/boot/
cp ${_v} ${work_dir}/i686/mnt/syslinux/*.c32 ${work_dir}/iso/syslinux/
cp ${_v} ${work_dir}/i686/mnt/syslinux/poweroff.com ${work_dir}/iso/syslinux/
cp ${_v} ${work_dir}/i686/mnt/syslinux/memdisk ${work_dir}/iso/syslinux/
cp ${_v} ${work_dir}/i686/mnt/syslinux/isolinux.bin ${work_dir}/iso/syslinux/
cp ${_v} ${work_dir}/i686/mnt/syslinux/pxelinux.0 ${work_dir}/iso/syslinux/
cp ${_v} ${work_dir}/i686/mnt/syslinux/gpxelinux.0 ${work_dir}/iso/syslinux/
cp ${_v} -r ${work_dir}/i686/mnt/syslinux/hdt ${work_dir}/iso/syslinux/
}
syslinuxcfg_copy() {
echo "Executing: ${FUNCNAME}"
for _cfg in ${syslinuxcfg_dir}/*.cfg; do
sed "s|%ARCHISO_LABEL%|${label}|g;
s|%INSTALL_DIR%|${install_dir}|g" ${_cfg} > ${work_dir}/iso/syslinux/$(basename ${_cfg})
done
}
isomounts_copy() {
echo "Executing: ${FUNCNAME}"
cp ${_v} ${isomounts_file} ${work_dir}/iso/${install_dir}/
}
squashfs_copy() {
echo "Executing: ${FUNCNAME}"
for _arch in i686 x86_64; do
cp ${_v} ${work_dir}/${_arch}/mnt/${install_dir}/${_arch}/*.sqfs ${work_dir}/iso/${install_dir}/${_arch}/
done
}
make_iso() {
echo "Executing: ${FUNCNAME}"
if [ "${quiet}" = "y" ]; then
_qflag="-quiet"
else
_qflag=""
fi
mkisofs ${_v} ${_qflag} -r -l \
-b syslinux/isolinux.bin -c syslinux/boot.cat \
-uid 0 -gid 0 \
-udf -allow-limited-size -iso-level 3 \
-input-charset utf-8 -p "prepared by archiso2dual" \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-publisher "${publisher}" \
-A "${application}" \
-V "${label}" \
-o "${imgname}" "${work_dir}/iso/"
isohybrid "${imgname}"
}
unsquashfs_image() {
echo "Executing: ${FUNCNAME}"
img=${1}
arch=${2}
rm -rf ${work_dir}/tmp/${arch}/${img}
if [ "${quiet}" = "y" ]; then
unsquashfs -d ${work_dir}/tmp/${arch}/${img} ${work_dir}/iso/${install_dir}/${arch}/${img}.sqfs > /dev/null
else
unsquashfs -d ${work_dir}/tmp/${arch}/${img} ${work_dir}/iso/${install_dir}/${arch}/${img}.sqfs
fi
}
mksquashfs_image() {
echo "Executing: ${FUNCNAME}"
img=${1}
arch=${2}
rm -f ${work_dir}/iso/${install_dir}/${arch}/${img}.sqfs
if [ "${quiet}" = "y" ]; then
mksquashfs ${work_dir}/tmp/${arch}/${img} ${work_dir}/iso/${install_dir}/${arch}/${img}.sqfs -comp ${compression} > /dev/null
else
mksquashfs ${work_dir}/tmp/${arch}/${img} ${work_dir}/iso/${install_dir}/${arch}/${img}.sqfs -comp ${compression}
fi
}
usrshare_make_image() {
echo "Executing: ${FUNCNAME}"
mkdir -p ${work_dir}/tmp/any/usrshare/usr
cp -a ${work_dir}/tmp/i686/root-image/usr/share ${work_dir}/tmp/any/usrshare/usr
mksquashfs_image usrshare any
}
libmodules_make_image() {
echo "Executing: ${FUNCNAME}"
for _arch in i686 x86_64; do
mkdir -p ${work_dir}/tmp/${_arch}/libmodules/lib
cp -a ${work_dir}/tmp/${_arch}/root-image/lib/modules ${work_dir}/tmp/${_arch}/libmodules/lib
mksquashfs_image libmodules ${_arch}
done
}
core_pkgs_make_image() {
echo "Executing: ${FUNCNAME}"
mkdir -p ${work_dir}/tmp/any/core-any-pkgs/src/core/pkg
cp -a ${work_dir}/tmp/i686/core-pkgs/src/core/pkg/*-any.pkg.* ${work_dir}/tmp/any/core-any-pkgs/src/core/pkg
for _arch in i686 x86_64; do
rm -rf ${work_dir}/tmp/${_arch}/core-pkgs/src/core/pkg/*-any.pkg.*
mksquashfs_image core-pkgs ${_arch}
done
mksquashfs_image core-any-pkgs any
}
core_pkgs_extract() {
echo "Executing: ${FUNCNAME}"
for _arch in i686 x86_64; do
unsquashfs_image core-pkgs ${_arch}
done
}
check_if_core_medium() {
echo "Executing: ${FUNCNAME}"
if [ -f ${work_dir}/iso/${install_dir}/i686/core-pkgs.sqfs ] && [ -f ${work_dir}/iso/${install_dir}/x86_64/core-pkgs.sqfs ]; then
_iscoreiso=y
fi
}
root_image_extract() {
echo "Executing: ${FUNCNAME}"
for _arch in i686 x86_64; do
unsquashfs_image root-image ${_arch}
done
}
root_image_purge() {
echo "Executing: ${FUNCNAME}"
while read _file; do
[ "${_file#"#"}" != "${_file}" ] && continue
for _arch in i686 x86_64; do
rm -rf "${work_dir}/tmp/${_arch}/root-image/${_file}"
done
done < "${removefiles_file}"
}
root_image_list_purge() {
while read _file; do
[ "${_file#"#"}" != "${_file}" ] && continue
for _arch in i686 x86_64; do
echo "${work_dir}/tmp/${_arch}/root-image/${_file}"
done
done < "${removefiles_file}"
}
root_image_make_image() {
echo "Executing: ${FUNCNAME}"
for _arch in i686 x86_64; do
rm -rf ${work_dir}/tmp/${_arch}/root-image/usr/share
rm -rf ${work_dir}/tmp/${_arch}/root-image/lib/modules
mksquashfs_image root-image ${_arch}
done
}
make_workspace() {
echo "Executing: ${FUNCNAME}"
for _arch in i686 x86_64; do
mkdir ${_v} -p ${work_dir}/iso/${install_dir}/${_arch}
mkdir ${_v} -p ${work_dir}/iso/${install_dir}/boot/${_arch}
mkdir ${_v} -p ${work_dir}/${_arch}/mnt
mkdir ${_v} -p ${work_dir}/tmp/${_arch}
done
mkdir ${_v} -p ${work_dir}/iso/syslinux
mkdir ${_v} -p ${work_dir}/iso/${install_dir}/any
mkdir ${_v} -p ${work_dir}/tmp/any
}
show_help()
{
exitvalue=${1}
echo
echo "${appname} [options] -3 <i686.iso> -6 <x86_64.iso> -o <output.iso>"
echo
echo " needed options:"
echo " -3 <i686.iso> Path to i686 source iso image"
echo " -6 <x86_64.iso> Path to x86_64 source iso image"
echo " -o <output.iso> Path to dual target iso image"
echo
echo " general options:"
echo " -M <isomounts> Path to isomounts file
(default to '${isomounts_file}'"
echo " -S <syslinux> Path to syslinux.cfg file
(default to '${syslinuxcfg_dir}'"
echo " -R <removefiles> Path to removefiles file
(default to '${removefiles_file}'"
echo " -w <workdir> Set work directory
(default to '${work_dir}')"
echo " -T <profile> Type of target image (work is done on root-image.sqfs):
basic: join both images, no changes in root-image
split: 'basic' + split out usr/share/ and lib/modules/ from root-image
full: 'split' + remove specified directories (with -R) from root-image
(default to '${profile_type}')"
echo " -L <label> Set a label for the disk [max 11 chars]
(default to '${label}')"
echo " -P <publisher> Set a publisher for the disk
(default to '${publisher}')"
echo " -A <application> Set an application name for the disk
(default to '${application}')"
echo " -c <compressor> Set SquashFS compression type: gzip, lzma or lzo
(default to '${compression}')"
echo " NOTES:"
echo " lzma: not officially supported yet by Linux (2.6.36)"
echo " lzo: needs Linux >= 2.6.36"
echo " -D <install_dir> Set an install_dir
(default to '${install_dir}')"
echo " NOTES:"
echo " Must match install_dir from both .iso sources"
echo " Max 8 characters, use only [a-z0-9]"
echo " -y Confirm execution (otherwise only show configuration)"
echo " -v Enable verbose output"
echo " -h This message"
exit ${exitvalue}
}
show_config() {
echo
echo "${appname} : Configuration settings"
echo " source iso i686 image: ${isofile_i686}"
echo " source iso x86_64 image: ${isofile_x86_64}"
echo " target iso image: ${imgname}"
echo " install directory on ISO: ${install_dir}"
echo " isomounts file: ${isomounts_file}"
echo " syslinux.cfg path: ${syslinuxcfg_dir}"
echo " removefiles.lst file: ${removefiles_file}"
echo " working directory: ${work_dir}"
echo " profile: ${profile_type}"
echo " label: ${label}"
echo " publisher: ${publisher}"
echo " application: ${application}"
echo " compression: ${compression}"
echo
if [ "${profile_type}" = "full" ]; then
echo "These files will be deleted (selected via -R option)"
root_image_list_purge
fi
}
options_check() {
if [ "x${isofile_i686}" = "x" ]; then
echo "*ERROR*: -3 <i686.iso> must be specified"
_error="1"
fi
if [ "x${isofile_x86_64}" = "x" ]; then
echo "*ERROR*: -6 <x86_64.iso> must be specified"
_error="1"
fi
if [ "x${imgname}" = "x" ]; then
echo "*ERROR*: -o <output.iso> must be specified"
_error="1"
fi
if [ ${_error} = "1" ]; then
show_help 1
fi
}
sanity_check() {
echo
if [ ! -f "${isofile_i686}" ]; then
echo "*ERROR*: ${isofile_i686} does not exist"
_error="1"
fi
if [ ! -f "${isofile_x86_64}" ]; then
echo "*ERROR*: ${isofile_x86_64} does not exist"
_error="1"
fi
if [ -f "${imgname}" ]; then
echo "*ERROR*: ${imgname} already exists, aborting"
_error="1"
fi
if [ ! -f "${isomounts_file}" ]; then
echo "*ERROR*: ${isomounts_file} does not exist, , specify one with -M option"
_error="1"
fi
if [ ! -f "${syslinuxcfg_dir}/syslinux.cfg" ]; then
echo "*ERROR*: ${syslinuxcfg_dir}/syslinux.cfg does not exist, specify one with -S option"
_error="1"
fi
if [ ! -f "${removefiles_file}" ]; then
echo "*ERROR*: ${removefiles_file} does not exist, specify one with -R option"
_error="1"
fi
if [ -d "${work_dir}" ]; then
echo "*ERROR*: work directory ${work_dir} is present, first delete it"
_error="1"
fi
if [ ${_error} = "1" ]; then
exit 1
fi
}
if [ "$EUID" != "0" ]; then
echo "*ERROR*: This script must be run as root."
exit 1
fi
while getopts '3:6:o:T:M:S:R:L:P:A:c:D:yvh' arg; do
case "${arg}" in
3) isofile_i686="${OPTARG}" ;;
6) isofile_x86_64="${OPTARG}" ;;
o) imgname="${OPTARG}" ;;
T) case "${OPTARG}" in
"basic"|"split"|"full") profile_type="${OPTARG}" ;;
*) echo; echo "*ERROR*: invalid argument in -T option: ${profile_type}"; show_help 1 ;;
esac
;;
M) isomounts_file="${OPTARG}" ;;
S) syslinuxcfg_dir="${OPTARG}" ;;
R) removefiles_file="${OPTARG}" ;;
L) label="${OPTARG}" ;;
P) publisher="${OPTARG}" ;;
A) application="${OPTARG}" ;;
c) compression="${OPTARG}" ;;
D) install_dir="${OPTARG}" ;;
w) work_dir="${OPTARG}" ;;
y) _confirm="y" ;;
v) quiet="n"; _v="-v" ;;
h|?) show_help 0 ;;
*) echo; echo "*ERROR*: invalid argument '${arg}'"; show_help 1 ;;
esac
done
options_check
sanity_check
show_config
if [ "${_confirm}" != "y" ]; then
echo
echo "If configuration is correct, re-execute with -y"
exit 1
fi
make_workspace
iso_mount
kernel_copy
syslinux_copy
squashfs_copy
check_if_core_medium
iso_umount
syslinuxcfg_copy
isomounts_copy
if [ ${profile_type} = "full" ] || [ ${profile_type} = "split" ]; then
root_image_extract
if [ ${profile_type} = "full" ]; then
root_image_purge
fi
if [ ${_iscoreiso} = "y" ]; then
core_pkgs_extract
fi
usrshare_make_image
libmodules_make_image
root_image_make_image
if [ ${_iscoreiso} = "y" ]; then
core_pkgs_make_image
fi
fi
make_iso