You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
298 lines
8.2 KiB
298 lines
8.2 KiB
#!/bin/bash |
|
|
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" |
|
|
|
ask() { |
|
USER_ANSWER="?"; |
|
while [ "$USER_ANSWER" != "n" ] && [ "$USER_ANSWER" != "y" ] ; do |
|
echo -n "$1 ? [y/n] " |
|
read -r -n 1 USER_ANSWER |
|
echo ""; |
|
done |
|
if [ "$USER_ANSWER" == "y" ] ; then |
|
return 0 |
|
else |
|
return 1 |
|
fi |
|
} |
|
|
|
check_tools() |
|
{ |
|
package_list='xorriso isolinux python3-apt apt-utils python3-requests rsync wget' |
|
# shellcheck disable=SC2086 |
|
if apt-get -s install ${package_list} |grep ^Inst |
|
then |
|
echo "Some tools are needed :" |
|
echo "apt install ${package_list}" |
|
exit 0 |
|
fi |
|
} |
|
|
|
check_tools |
|
|
|
usage() { |
|
cat <<EOF |
|
|
|
Upgrade an existant official debian iso to last revision. |
|
|
|
options: |
|
-c|--configfile Specify a config file |
|
-h|--help Show this message. |
|
-i|--isofile Isofile to upgrade |
|
-o|--offline Build a offline capable iso |
|
-v Show more output. |
|
|
|
Configfile contents example: |
|
ISOFILE=$HOME/debian-13.0.0-amd64-netinst.iso |
|
PRESEED=$HOME/preseed.cfg |
|
NEWFLAVOR=custom |
|
MYFILES=$HOME/myfiles |
|
WANTED=$HOME/wanted.txt |
|
SUGGESTED=false |
|
POPCON=false |
|
EXTRA_SCRIPT=$HOME/mycustom.sh |
|
OFFLINE=1 |
|
EOF |
|
} |
|
|
|
main() { |
|
|
|
cd "$SCRIPT_DIR" || exit 1 |
|
|
|
ISOFILE="" |
|
VERBOSITY=0 |
|
OFFLINE=0 |
|
|
|
while [[ $# -gt 0 ]]; do |
|
case $1 in |
|
-c|--configfile) |
|
CONFIGFILE=$2 |
|
[[ -z ${CONFIGFILE} ]] && echo "missing argument $1" && exit 1 |
|
if [ -e "${CONFIGFILE}" ] |
|
then |
|
# shellcheck source=/dev/null |
|
source "${CONFIGFILE}" |
|
else |
|
echo "ERROR: specified configfile not found"* |
|
exit 1 |
|
fi |
|
shift |
|
shift |
|
;; |
|
-h|--help) |
|
usage |
|
exit 0 |
|
;; |
|
-i|--isofile) |
|
ISOFILE=$2 |
|
[[ -z ${ISOFILE} ]] && echo "missing argument $1" && exit 1 |
|
shift |
|
shift |
|
;; |
|
-o|--offline) |
|
OFFLINE=1 |
|
shift |
|
;; |
|
*) |
|
echo "ERROR: unknown option: $1" |
|
usage |
|
exit 1 |
|
;; |
|
esac |
|
done |
|
|
|
# default initialisation of vars |
|
preseed=${PRESEED:-${SCRIPT_DIR}/preseed.cfg} |
|
newflavor=${NEWFLAVOR:-custom} |
|
myfiles=${MYFILES:-${HOME}/myfiles} |
|
wantedfile=${WANTED:-${HOME}/wanted.txt} |
|
excludedfile=${EXCLUDED:-${SCRIPT_DIR}/excluded.txt} |
|
extra_script=${EXTRA_SCRIPT:-${HOME}/mycustom.sh} |
|
|
|
# debian-13.0.0-amd64-netinst.iso |
|
bnfile=$(basename "${ISOFILE}") |
|
distribution=$( echo "${bnfile}" |cut --delimiter='-' --fields=1 ) |
|
majorversion=$( echo "${bnfile}" |cut --delimiter='-' --fields=2 |cut --delimiter='.' --fields=1 ) |
|
minorversion=$( echo "${bnfile}" |cut --delimiter='-' --fields=2 |cut --delimiter='.' --fields=2 ) |
|
incrementalversion=$( echo "${bnfile}" |cut --delimiter='-' --fields=2 |cut --delimiter='.' --fields=3 ) |
|
architecture=$( echo "${bnfile}" |cut --delimiter='-' --fields=3) |
|
# flavor=$( echo "${bnfile}" |cut --delimiter='-' --fields=4 |cut --delimiter='.' --fields=1 ) |
|
# extension=$( echo "${bnfile}" |cut --delimiter='-' --fields=4 |cut --delimiter='.' --fields=2 ) |
|
destination=${distribution}-${majorversion}.${minorversion}.${incrementalversion}-${architecture}-${newflavor}.iso |
|
|
|
if [ ! -e "${ISOFILE}" ] |
|
then |
|
echo "image not found : ${ISOFILE}" |
|
exit 1 |
|
fi |
|
|
|
if [ ! -e "${wantedfile}" ] |
|
then |
|
cat > "${wantedfile}" <<EOF |
|
local-apt-repository |
|
rsync |
|
EOF |
|
fi |
|
|
|
if [ ! -e "${excludedfile}" ] |
|
then |
|
cat > "${excludedfile}" <<EOF |
|
gdm3 |
|
chromium |
|
firefox |
|
EOF |
|
fi |
|
|
|
# create working dir (iso loop in /tmp) |
|
temp_file=/tmp/tmp_iso_directory.txt |
|
if [ -e ${temp_file} ] |
|
then |
|
temp_dir=$(cat ${temp_file}) |
|
else |
|
temp_dir=$(mktemp -d) |
|
echo "${temp_dir}" > ${temp_file} |
|
fi |
|
|
|
echo "##### extracting iso" |
|
if [ ! -e "${temp_dir}"/md5sum.txt ] |
|
then |
|
echo "extracting iso to ${temp_dir}" |
|
xorriso -osirrox on -indev "${ISOFILE}" -extract / "${temp_dir}" |
|
chmod -R +w "${temp_dir}" |
|
fi |
|
|
|
if [ ! -d "${myfiles}" ] |
|
then |
|
mkdir -p "${myfiles}" |
|
fi |
|
|
|
echo "### download wanted packages" |
|
if [ -e "${wantedfile}" ] && [ -e "${excludedfile}" ] |
|
then |
|
if python3 download_myfiles.py --isodir "${temp_dir}" \ |
|
--wanted "${wantedfile}" --excluded "${excludedfile}" \ |
|
--files "${myfiles}" --quiet |
|
then |
|
echo "### myfiles generation ok" |
|
else |
|
echo "### myfiles generation failure !!!" |
|
exit 1 |
|
fi |
|
else |
|
echo "download_myfiles.py disabled" |
|
fi |
|
|
|
echo "### add extra script content" |
|
if [ -e "${extra_script}" ] |
|
then |
|
eval "$(cat "${extra_script}")" |
|
fi |
|
|
|
if [[ ${OFFLINE} -gt 0 ]] |
|
then |
|
if ! grep local-apt-repository "${wantedfile}" |
|
then |
|
echo "ERROR: local-apt-repository is required in wanted file for offline mode" |
|
exit 1 |
|
else |
|
cat > "${myfiles}"/local-apt-repository.sh <<"EOEF" |
|
#!/usr/bin/env bash |
|
echo "### Activate apt cdrom" |
|
sed --expression "s/^[#]*deb cdrom:/deb [trusted=yes] cdrom:/" /etc/apt/sources.list |
|
sed --expression="s/^[#]*deb cdrom:/deb [trusted=yes] cdrom:/" --in-place /etc/apt/sources.list |
|
echo "### Prepare for local-apt-repository usage" |
|
local_apt_repository=/srv/local-apt-repository |
|
source_directory=/media/cdrom0 |
|
original_list=/tmp/original_list.txt |
|
cat > ${original_list} <<EOF |
|
EOF |
|
mkdir -p "${local_apt_repository}" |
|
find ${source_directory} -name Packages.gz |
|
while IFS= read -r -d '' gzlist |
|
do |
|
echo "### Scan ${gzlist}" |
|
zgrep pool "${gzlist}" | cut --delimiter=' ' --fields=2 >> ${original_list} |
|
done < <(find ${source_directory} -name Packages.gz -print0) |
|
pushd ${source_directory} || return 1 |
|
while IFS= read -r -d '' packagepath |
|
do |
|
if ! grep "^${packagepath}$" ${original_list} |
|
then |
|
echo "### Package $(basename "${packagepath}") not in original cd. Copy in /local-apt-repository." |
|
mkdir --parents --verbose ${local_apt_repository}/"$(dirname "${packagepath}")" |
|
cp --verbose "${packagepath}" ${local_apt_repository}"/$(dirname "${packagepath}")"/"$(basename "${packagepath}")" |
|
fi |
|
done < <(find pool -name "*.deb" -print0) |
|
popd || return 1 |
|
apt --yes install "$(find ${local_apt_repository} -name "local-apt-repository*.deb")" |
|
apt clean |
|
apt update |
|
apt upgrade |
|
EOEF |
|
fi |
|
fi |
|
|
|
cat > "${myfiles}"/README.custom <<"EOF" |
|
=== |
|
In offline mode, |
|
Mount cdrom ( mount /dev/sr0 ) |
|
And execute local-apt-repository.sh |
|
=== |
|
|
|
EOF |
|
|
|
chmod -R +w "${temp_dir}" |
|
|
|
echo "### customize initrd with preseed" |
|
if [ -e "${preseed}" ] |
|
then |
|
# cpio on "out mode" don't allow to rename/basename file on the fly |
|
# so we need to put the file somewhere with the target name |
|
# and go (pushd) to the directoy considered as root (/) of the initrd |
|
cp --verbose "${preseed}" /tmp/preseed.cfg |
|
pushd /tmp || return 1 |
|
case $(uname -m) in |
|
i686) |
|
echo "### Detected install.386" |
|
gunzip --verbose "${temp_dir}/install.386/initrd.gz" |
|
echo preseed.cfg | cpio --format=newc --create --append --verbose --file="${temp_dir}"/install.386/initrd |
|
gzip --verbose "${temp_dir}"/install.386/initrd |
|
ls -l "${temp_dir}"/install.386/initrd.gz |
|
;; |
|
x86_64) |
|
echo "### Detected install.amd" |
|
gunzip --verbose "${temp_dir}/install.amd/initrd.gz" |
|
echo preseed.cfg | cpio --format=newc --create --append --verbose --file="${temp_dir}"/install.amd/initrd |
|
gzip --verbose "${temp_dir}"/install.amd/initrd |
|
ls -l "${temp_dir}"/install.amd/initrd.gz |
|
;; |
|
*) |
|
echo "Platform not implemented" |
|
exit 1 |
|
;; |
|
esac |
|
popd || return 1 |
|
fi |
|
|
|
echo "### Add content of myfiles" |
|
rsync --verbose --recursive "${myfiles}"/ "${temp_dir}" |
|
|
|
echo "### Calculate md5sum.txt" |
|
chmod +w "${temp_dir}"/md5sum.txt |
|
pushd "${temp_dir}" || return 1 |
|
find . -follow -type f ! -name "md5sum.txt" -print0 | xargs -0 md5sum > md5sum.txt |
|
popd || return 1 |
|
chmod -R -w "${temp_dir}" |
|
|
|
echo "### Create iso" |
|
xorriso -as mkisofs -o "${destination}" \ |
|
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \ |
|
-c isolinux/boot.cat -b isolinux/isolinux.bin \ |
|
-no-emul-boot -boot-load-size 4 \ |
|
-boot-info-table "${temp_dir}" |
|
|
|
} |
|
|
|
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then |
|
main "$@" |
|
fi
|
|
|