Improve scripts (debug mode, error,…)

This commit is contained in:
Jeremy Gardais 2022-01-28 19:12:54 +01:00
parent 755dd24873
commit 8853575109
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
5 changed files with 1084 additions and 166 deletions

View File

@ -1,62 +1,287 @@
#!/bin/bash
# This script do the following:
# Download Clonezilla Stable for amd64 and i686
# Make a PXE's config file (aka menu.cfg)
# Purpose {{{
# This script will download Clonezilla Stable installer for both AMD64 and i368
# and make a sample menu.cfg config file.
# }}}
# Vars {{{
readonly PROGNAME=$(basename "${0}")
readonly NBARGS="${#}"
[ -z "${DEBUG}" ] && DEBUG=1
## Export DEBUG for sub-script
export DEBUG
# Default value for TFTP's directory
if command -v in.tftpd > /dev/null; then
source /etc/default/tftpd-hpa
else
TFTP_DIRECTORY="/srv/tftp"
fi
if ! command -v unzip > /dev/null; then
apt -y install unzip
fi
CZ_INSTALLER_DIR="${TFTP_DIRECTORY}/installer/clonezilla"
CZ_CONFIG_PXE="${CZ_INSTALLER_DIR}/menu.cfg.example"
CZ_VERSION="2.5.0-5"
# Get latest version from https://clonezilla.org
CZ_VERSION_DEFAULT="$(curl --no-progress-meter https://clonezilla.org/downloads.php | sed --silent 's;.*<b>stable</b>.*<font.*>\(.*\)</font>.*;\1;p')"
# Create directories and config file
rm -rf "${CZ_INSTALLER_DIR}"
mkdir -p "${CZ_INSTALLER_DIR}"
touch "${CZ_CONFIG_PXE}"
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
for ARCH in amd64 i686; do # For available classic architecture
CZ_URL="https://osdn.jp/dl/clonezilla/clonezilla-live-${CZ_VERSION}-${ARCH}.zip"
CZ_TEMP_FILE="/tmp/clonezilla-live-${CZ_VERSION}-${ARCH}.zip "
cat <<- EOF
usage: $PROGNAME [-d|-h|-v]
# Create and go into directory
mkdir -p ${CZ_INSTALLER_DIR}/${ARCH}
pushd ${CZ_INSTALLER_DIR}/${ARCH} > /dev/null
This script will download Clonezilla Stable for both AMD64 and i368 architectures.
# Download and extract only PXE files
#wget "${CZ_URL}" -O "${CZ_TEMP_FILE}"
wget --quiet "${CZ_URL}" -O "${CZ_TEMP_FILE}"
#unzip -j "${CZ_TEMP_FILE}" live/vmlinuz live/initrd.img live/filesystem.squashfs -d .
unzip -q -j "${CZ_TEMP_FILE}" live/vmlinuz live/initrd.img live/filesystem.squashfs -d .
rm -f "${CZ_TEMP_FILE}"
EXAMPLES:
- Download Clonezilla's to default place (${TFTP_DIRECTORY}).
${PROGNAME}
popd > /dev/null
- Download a specific version of Clonezilla (default : ${CZ_VERSION_DEFAULT}).
${PROGNAME} --version "2.7.1"
# Config file
OPTIONS:
-v,--version
Define the version of Clonezilla to download.
-d,--debug
Enable debug messages.
-h,--help
Print this help message.
EOF
}
# }}}
debug_message() { # {{{
local_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_message}"
return 0
}
# }}}
error_message() { # {{{
local_error_message="${1}"
local_error_code="${2}"
## Print message
printf '%b\n' "ERROR ${PROGNAME}: ${RED}${local_error_message}${RESET}"
exit "${local_error_code:=66}"
}
# }}}
define_vars() { # {{{
# If cz_version wasn't defined (argument) {{{
if [ -z "${cz_version}" ]; then
## Use default value
cz_version="${CZ_VERSION_DEFAULT}"
fi
# }}}
}
# }}}
is_file_absent() { # {{{
local_file_absent="${1}"
## File exists by default
return_is_file_absent="1"
### Check if the file exists
# shellcheck disable=SC2086
if find ${local_file_absent} > /dev/null 2>&1; then
return_is_file_absent="1"
debug_message "is_file_absent \
The file ${RED}${local_file_absent}${COLOR_DEBUG} exists."
else
return_is_file_absent="0"
debug_message "is_file_absent \
The file ${RED}${local_file_absent}${COLOR_DEBUG} doesn't exist."
fi
return "${return_is_file_absent}"
}
# }}}
download_file() { # {{{
local_url="${1}"
local_dest_file="${2}"
debug_message "download_file \
Download ${local_url} to ${RED}${local_dest_file}${COLOR_DEBUG} ."
wget --quiet "${local_url}" --output-document="${local_dest_file}"
## Unset variables
unset local_url
unset local_dest_file
}
# }}}
is_file_empty() { # {{{
local_file="${1}"
## File is empty by default
return_is_file_empty="0"
### Check if the file is empty
if [ ! -s "${local_file}" ]; then
return_is_file_empty="0"
debug_message "is_file_empty \
The file ${RED}${local_file}${COLOR_DEBUG} is empty or doesn't exists."
else
return_is_file_empty="1"
debug_message "is_file_empty \
The file ${RED}${local_file}${COLOR_DEBUG} exists and has a size greater than zero."
fi
## Unset variables
unset local_file
return "${return_is_file_empty}"
}
# }}}
main() { # {{{
# Define all vars
define_vars
# Create directories and config file
debug_message "Main \
Create ${CZ_INSTALLER_DIR} tree."
mkdir --parents -- "${CZ_INSTALLER_DIR}" \
|| error_message "Can't create ${CZ_INSTALLER_DIR}/ directory." 1
true > "${CZ_CONFIG_PXE}"
for ARCH in amd64 i686; do # For available classic architectures
CZ_URL="https://osdn.jp/dl/clonezilla/clonezilla-live-${cz_version}-${ARCH}.zip"
CZ_TEMP_FILE="/tmp/clonezilla-live-${cz_version}-${ARCH}.zip"
## If this version is not already present on the system
if is_file_absent "${CZ_INSTALLER_DIR}/${ARCH}/${cz_version}"; then
### Recreate directory and go
rm --recursive --force -- "${CZ_INSTALLER_DIR}/${ARCH}"
mkdir --parents -- "${CZ_INSTALLER_DIR}/${ARCH}" \
|| error_message "Can't create ${CZ_INSTALLER_DIR}/${ARCH}/ directory." 1
pushd "${CZ_INSTALLER_DIR}/${ARCH}" > /dev/null \
|| error_message "Can't move to ${CZ_INSTALLER_DIR}/${ARCH} temp directory." 2
### Download and extract only PXE files {{{
download_file "${CZ_URL}" "${CZ_TEMP_FILE}"
is_file_empty "${CZ_TEMP_FILE}" \
&& error_message "${CZ_TEMP_FILE} is empty." 3
debug_message "FOR loop ${ARCH} \
Uncompress PXE files from ${CZ_TEMP_FILE} ."
unzip -qq -j "${CZ_TEMP_FILE}" live/vmlinuz live/initrd.img live/filesystem.squashfs -d .
### }}}
### Remove temp file
rm --recursive --force -- "${CZ_TEMP_FILE}" \
|| error_message "Can't remove ${CZ_TEMP_FILE} temp file."
### Add flag file to know that this version is available
true > "${CZ_INSTALLER_DIR}/${ARCH}/${cz_version}"
popd > /dev/null \
|| error_message "Can't move back from ${CZ_INSTALLER_DIR}/${ARCH}/ directory." 2
fi
## Add informations to sample config file
/bin/cat >> "${CZ_CONFIG_PXE}" << EOF
label live${ARCH}
menu label Clonezilla Live ^${ARCH}
kernel installer/clonezilla/${ARCH}/vmlinuz
APPEND initrd=installer/clonezilla/${ARCH}/initrd.img boot=live username=user union=overlay config components quiet noswap edd=on nomodeset nodmraid locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch=no net.ifnames=0 nosplash noprompt fetch=tftp://129.20.203.27/installer/clonezilla/${ARCH}/filesystem.squashfs
EOF
done
# Add separator and menu to sample config file
/bin/cat >> "${CZ_CONFIG_PXE}" << EOF
label live${ARCH}
menu label Clonezilla Live ^${ARCH}
kernel installer/clonezilla/${ARCH}/vmlinuz
APPEND initrd=installer/clonezilla/${ARCH}/initrd.img boot=live username=user union=overlay config components quiet noswap edd=on nomodeset nodmraid locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch=no net.ifnames=0 nosplash noprompt fetch=tftp://129.20.203.27/installer/clonezilla/${ARCH}/filesystem.squashfs
label separator
menu label -----
label mainmenu
menu label ^Back..
menu exit
EOF
done
}
# }}}
# Config file
/bin/cat >> "${CZ_CONFIG_PXE}" << EOF
label separator
menu label -----
label mainmenu
menu label ^Back..
menu exit
EOF
# Manage arguments # {{{
# This code can't be in a function due to argument management
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
## If the first argument is not an option
if ! printf -- '%s' "${1}" | grep -q -E -- "^-+";
then
## Print help message and exit
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
fi
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
case "${1}" in
-v|--version ) ## Define cz_version
## Move to the next argument
shift
## Define var
readonly cz_version="${1}"
;;
-d|--debug ) ## debug
DEBUG=0
;;
-h|--help ) ## help
usage
## Exit after help informations
exit 0
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "Arguments management \
${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "Arguments management \
${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "Arguments management \
No arguments/options to manage."
fi
# }}}
main
exit 0

View File

@ -1,61 +1,240 @@
#!/bin/bash
# This script do the following:
# Download Debian Stable (Bullseye)
# Download Debian oldStable (Buster)
# Download Debian oldoldStable (Stretch)
# Download Debian Unstable (Sid)
# Make an PXE's config file (aka menu.cfg)
# Purpose {{{
# This script will download Debian netboot installer for both AMD64 and i368
# 1. Debian Stable (Bullseye)
# 2. Debian oldStable (Buster)
# 3. Debian oldoldStable (Stretch)
# 4. Debian Unstable (Sid)
# and make a sample menu.cfg config file.
# }}}
# Vars {{{
readonly PROGNAME=$(basename "${0}")
readonly NBARGS="${#}"
[ -z "${DEBUG}" ] && DEBUG=1
## Export DEBUG for sub-script
export DEBUG
# Default value for TFTP's directory
if command -v in.tftpd > /dev/null; then
source /etc/default/tftpd-hpa
else
TFTP_DIRECTORY="/srv/tftp"
fi
# Where to store Debian's installers
DEBIAN_INSTALLER_DIR="${TFTP_DIRECTORY}/installer/debian"
# tftp sample config file
DEBIAN_CONFIG_PXE="${DEBIAN_INSTALLER_DIR}/menu.cfg.example"
# Create directories and config file
mkdir -p "${DEBIAN_INSTALLER_DIR}"
rm -f "${DEBIAN_CONFIG_PXE}"
touch "${DEBIAN_CONFIG_PXE}"
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
for DISTRO in bullseye buster stretch sid; do # For ALL Debian's version
for ARCH in amd64 i386; do # For all classic architecture
cat <<- EOF
usage: $PROGNAME [-d|-h]
# Create and go into directory
mkdir -p ${DEBIAN_INSTALLER_DIR}/${DISTRO}/${ARCH}
pushd ${DEBIAN_INSTALLER_DIR}/${DISTRO}/${ARCH} > /dev/null
This script will download "all" Debian's netboot installer for
tftp server for both AMD64 and i368 architectures.
# Download files
#wget http://deb.debian.org/debian/dists/${DISTRO}/main/installer-${ARCH}/current/images/netboot/debian-installer/${ARCH}/linux -O linux
#wget http://deb.debian.org/debian/dists/${DISTRO}/main/installer-${ARCH}/current/images/netboot/debian-installer/${ARCH}/initrd.gz -O initrd.gz
wget --quiet http://deb.debian.org/debian/dists/${DISTRO}/main/installer-${ARCH}/current/images/netboot/debian-installer/${ARCH}/linux -O linux
wget --quiet http://deb.debian.org/debian/dists/${DISTRO}/main/installer-${ARCH}/current/images/netboot/debian-installer/${ARCH}/initrd.gz -O initrd.gz
popd > /dev/null
EXAMPLES:
- Download Debian's installers to default place (${TFTP_DIRECTORY})
${PROGNAME}
# Config file
/bin/cat >> "${DEBIAN_CONFIG_PXE}" << EOF
OPTIONS:
-d,--debug
Enable debug messages.
-h,--help
Print this help message.
EOF
}
# }}}
debug_message() { # {{{
local_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_message}"
return 0
}
# }}}
error_message() { # {{{
local_error_message="${1}"
local_error_code="${2}"
## Print message
printf '%b\n' "ERROR ${PROGNAME}: ${RED}${local_error_message}${RESET}"
exit "${local_error_code:=66}"
}
# }}}
download_file() { # {{{
local_url="${1}"
local_dest_file="${2}"
debug_message "download_file \
Download ${local_url} to ${RED}${local_dest_file}${COLOR_DEBUG} ."
wget --quiet "${local_url}" --output-document="${local_dest_file}"
## Unset variables
unset local_url
unset local_dest_file
}
# }}}
is_file_empty() { # {{{
local_file="${1}"
## File is empty by default
return_is_file_empty="0"
### Check if the file is empty
if [ ! -s "${local_file}" ]; then
return_is_file_empty="0"
debug_message "is_file_empty \
The file ${RED}${local_file}${COLOR_DEBUG} is empty or doesn't exists."
else
return_is_file_empty="1"
debug_message "is_file_empty \
The file ${RED}${local_file}${COLOR_DEBUG} exists and has a size greater than zero."
fi
## Unset variables
unset local_file
return "${return_is_file_empty}"
}
# }}}
main() { # {{{
# Create directories and config file
debug_message "Main \
Create ${DEBIAN_INSTALLER_DIR} tree."
mkdir --parents -- "${DEBIAN_INSTALLER_DIR}" \
|| error_message "Can't create ${DEBIAN_INSTALLER_DIR} directory." "1"
debug_message "Main \
(re)Create ${DEBIAN_CONFIG_PXE} sample config file."
true > "${DEBIAN_CONFIG_PXE}"
# Parse all Debian's distribution
for DISTRO in bullseye buster stretch sid; do # For "all" Debian's version
## Then parse architecture
for ARCH in amd64 i386; do # For all classic architecture
debug_message "Main FOR loop \
Manage ${RED}${DISTRO}${COLOR_DEBUG} release with ${RED}${ARCH}${COLOR_DEBUG} architecture."
### Create destination directory
mkdir --parents -- ${DEBIAN_INSTALLER_DIR}/${DISTRO}/${ARCH} \
|| error_message "Can't create ${DEBIAN_INSTALLER_DIR}/${DISTRO}/${ARCH} tree." "1"
### Download linux file
download_file "http://deb.debian.org/debian/dists/${DISTRO}/main/installer-${ARCH}/current/images/netboot/debian-installer/${ARCH}/linux" \
"${DEBIAN_INSTALLER_DIR}/${DISTRO}/${ARCH}/linux"
is_file_empty "${DEBIAN_INSTALLER_DIR}/${DISTRO}/${ARCH}/linux" \
&& error_message "${DEBIAN_INSTALLER_DIR}/${DISTRO}/${ARCH}/linux is empty !" "2"
### Download initrd.gz
download_file "http://deb.debian.org/debian/dists/${DISTRO}/main/installer-${ARCH}/current/images/netboot/debian-installer/${ARCH}/initrd.gz" \
"${DEBIAN_INSTALLER_DIR}/${DISTRO}/${ARCH}/initrd.gz"
is_file_empty "${DEBIAN_INSTALLER_DIR}/${DISTRO}/${ARCH}/initrd.gz" \
&& error_message "${DEBIAN_INSTALLER_DIR}/${DISTRO}/${ARCH}/initrd.gz is empty !" "2"
### Config file
debug_message "Main FOR loop \
Add tftp config sample."
/bin/cat >> "${DEBIAN_CONFIG_PXE}" << EOF
label ${DISTRO}${ARCH}
menu label Debian GNU/Linux ${DISTRO} ^${ARCH} bits
kernel installer/debian/${DISTRO}/${ARCH}/linux
append vga=normal initrd=installer/debian/${DISTRO}/${ARCH}/initrd.gz -- quiet
EOF
done
done
# Config file
/bin/cat >> "${DEBIAN_CONFIG_PXE}" << EOF
label separator
menu label ---
EOF
done
done
# Config file
/bin/cat >> "${DEBIAN_CONFIG_PXE}" << EOF
/bin/cat >> "${DEBIAN_CONFIG_PXE}" << EOF
label mainmenu
menu label ^Back...
menu exit
EOF
}
# }}}
# Manage arguments # {{{
# This code can't be in a function due to argument management
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
## If the first argument is not an option
if ! printf -- '%s' "${1}" | grep -q -E -- "^-+";
then
## Print help message and exit
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
fi
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
case "${1}" in
-d|--debug ) ## debug
DEBUG=0
;;
-h|--help ) ## help
usage
## Exit after help informations
exit 0
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "Arguments management \
${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "Arguments management \
${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "Arguments management \
No arguments/options to manage."
fi
# }}}
main
exit 0

View File

@ -1,93 +1,346 @@
#!/bin/bash
# This script do the following:
# Download Memtest
# Purpose {{{
# This script will download some diagnostic tools.
# 1. Memtest
# 2. Gparted
# and make a sample menu.cfg config file.
# }}}
# Vars {{{
readonly PROGNAME=$(basename "${0}")
readonly NBARGS="${#}"
[ -z "${DEBUG}" ] && DEBUG=1
## Export DEBUG for sub-script
export DEBUG
# Default value for TFTP's directory
if command -v in.tftpd > /dev/null; then
source /etc/default/tftpd-hpa
else
TFTP_DIRECTORY="/srv/tftp"
fi
# Tools versions
MEMTEST_VERSION_DEFAULT="$(curl --no-progress-meter http://memtest.org/ \
| sed --silent 's;.*VERSION : \([[:alnum:]]*.[[:alnum:]]*\)</font>.*;\1;p')"
GPARTED_VERSION_DEFAULT="$(curl --no-progress-meter https://gparted.org/ \
| sed --silent 's;.*<a href.*sourceforge.net.*>Live \(.*\)</a>.*;\1;p')"
if ! command -v unzip > /dev/null; then
apt -y install unzip
fi
# TFTP tree
DIAG_INSTALLER_DIR="${TFTP_DIRECTORY}/installer"
CONFIG_PXE="${DIAG_INSTALLER_DIR}/menu.cfg.diag.example"
MEMTEST_INSTALLER_DIR="${DIAG_INSTALLER_DIR}/memtest"
GPARTED_INSTALLER_DIR="${DIAG_INSTALLER_DIR}/gparted"
### Memtest {{{
MEMTEST_VERSION="5.01"
MEMTEST_URL="http://www.memtest.org/download/${MEMTEST_VERSION}/memtest86+-${MEMTEST_VERSION}.bin.gz"
MEMTEST_INSTALLER_DIR="${TFTP_DIRECTORY}/installer/memtest/"
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
# (re)Create the installer directory
rm -rf ${MEMTEST_INSTALLER_DIR}
mkdir -p ${MEMTEST_INSTALLER_DIR}
pushd ${MEMTEST_INSTALLER_DIR} > /dev/null
cat <<- EOF
usage: $PROGNAME [-d|-h|-m]
# Config file
CONFIG_PXE="${TFTP_DIRECTORY}/installer/menu.cfg.diag.example"
rm -f ${CONFIG_PXE} && touch ${CONFIG_PXE}
This script will download some diagnostic tools (eg. Memtest, Gparted,…).
# Download the last version and set simpler name (without the **.bin** extension!)
#wget ${MEMTEST_URL} -O - | gzip -d > memtest86+-${MEMTEST_VERSION}.bin
wget --quiet ${MEMTEST_URL} -O - | gzip -d > memtest86+-${MEMTEST_VERSION}.bin
ln -s memtest86+-${MEMTEST_VERSION}.bin memtest86+
EXAMPLES:
- Download default diagnostic tools.
${PROGNAME}
popd > /dev/null
- Download a specific version of Gparted (default : ${GPARTED_VERSION_DEFAULT}).
${PROGNAME} --gparted "1.0.0-5"
# Config file
/bin/cat >> "${CONFIG_PXE}" << EOF
- Download a specific version of Memtest (default : ${MEMTEST_VERSION_DEFAULT}).
${PROGNAME} --memtest "3.01"
OPTIONS:
-g,--gparted
Set the version of Gparted to download.
-m,--memtest
Set the version of Memtest to download.
-d,--debug
Enable debug messages.
-h,--help
Print this help message.
EOF
}
# }}}
debug_message() { # {{{
local_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_message}"
return 0
}
# }}}
error_message() { # {{{
local_error_message="${1}"
local_error_code="${2}"
## Print message
printf '%b\n' "ERROR ${PROGNAME}: ${RED}${local_error_message}${RESET}"
exit "${local_error_code:=66}"
}
# }}}
define_vars() { # {{{
# If memtest_version wasn't defined (argument) {{{
if [ -z "${memtest_version}" ]; then
## Use default value
memtest_version="${MEMTEST_VERSION_DEFAULT}"
fi
# }}}
# If gparted_version wasn't defined (argument) {{{
if [ -z "${gparted_version}" ]; then
## Use default value
gparted_version="${GPARTED_VERSION_DEFAULT}"
fi
# }}}
}
# }}}
is_file_absent() { # {{{
local_file_absent="${1}"
## File exists by default
return_is_file_absent="1"
### Check if the file exists
# shellcheck disable=SC2086
if find ${local_file_absent} > /dev/null 2>&1; then
return_is_file_absent="1"
debug_message "is_file_absent \
The file ${RED}${local_file_absent}${COLOR_DEBUG} exists."
else
return_is_file_absent="0"
debug_message "is_file_absent \
The file ${RED}${local_file_absent}${COLOR_DEBUG} doesn't exist."
fi
return "${return_is_file_absent}"
}
# }}}
download_file() { # {{{
local_url="${1}"
local_dest_file="${2}"
debug_message "download_file \
Download ${local_url} to ${RED}${local_dest_file}${COLOR_DEBUG} ."
wget --quiet "${local_url}" --output-document="${local_dest_file}"
## Unset variables
unset local_url
unset local_dest_file
}
# }}}
is_file_empty() { # {{{
local_file="${1}"
## File is empty by default
return_is_file_empty="0"
### Check if the file is empty
if [ ! -s "${local_file}" ]; then
return_is_file_empty="0"
debug_message "is_file_empty \
The file ${RED}${local_file}${COLOR_DEBUG} is empty or doesn't exists."
else
return_is_file_empty="1"
debug_message "is_file_empty \
The file ${RED}${local_file}${COLOR_DEBUG} exists and has a size greater than zero."
fi
## Unset variables
unset local_file
return "${return_is_file_empty}"
}
# }}}
main() { # {{{
# Define all vars
define_vars
# Create diagnostic tools directory and config file
mkdir --parents -- "${DIAG_INSTALLER_DIR}" \
|| error_message "Can't create ${DIAG_INSTALLER_DIR}/ directory." 1
true > ${CONFIG_PXE}
# Memtest {{{
MEMTEST_URL="http://www.memtest.org/download/${memtest_version}/memtest86+-${memtest_version}.bin.gz"
MEMTEST_BIN="memtest86+-${memtest_version}.bin"
# If this version is not already present on the system
if is_file_absent "${MEMTEST_INSTALLER_DIR}/${memtest_version}"; then
## (re)Create the installer directory
rm --recursive --force -- "${MEMTEST_INSTALLER_DIR}"
mkdir --parents -- "${MEMTEST_INSTALLER_DIR}"
pushd "${MEMTEST_INSTALLER_DIR}" > /dev/null \
|| error_message "Can't move to ${MEMTEST_INSTALLER_DIR} directory." 2
## Download and extract the last version
wget --quiet "${MEMTEST_URL}" -O - | gzip --decompress > "${MEMTEST_BIN}"
is_file_empty "${MEMTEST_BIN}" \
&& error_message "${MEMTEST_BIN} is empty." 3
## Set simpler name (without the **.bin** extension!)
ln --symbolic -- "${MEMTEST_BIN}" memtest86+
### Add flag file to know that this version is available
true > "${MEMTEST_INSTALLER_DIR}/${memtest_version}"
popd > /dev/null \
|| error_message "Can't move back from ${MEMTEST_INSTALLER_DIR}/ directory." 2
fi
# Config file
/bin/cat >> "${CONFIG_PXE}" << EOF
label memtest
menu label ^Memory diagnostic tool (Memtest)
kernel installer/memtest/memtest86+
EOF
### }}}
# }}}
### Gparted {{{
GPARTED_VERSION="1.0.0-5"
GPARTED_INSTALLER_DIR="${TFTP_DIRECTORY}/installer/gparted"
# Gparted {{{
# (re)Create the installer directory
rm -rf ${GPARTED_INSTALLER_DIR}
mkdir -p ${GPARTED_INSTALLER_DIR}
# For available classic architecture
for ARCH in amd64 i686; do
GPARTED_URL="http://downloads.sourceforge.net/project/gparted/gparted-live-stable/${gparted_version}/gparted-live-${gparted_version}-${ARCH}.zip"
GPARTED_TEMP_FILE="gparted-live-${gparted_version}-${ARCH}.zip"
for ARCH in amd64 i686; do # For available classic architecture
GPARTED_URL="http://downloads.sourceforge.net/project/gparted/gparted-live-stable/${GPARTED_VERSION}/gparted-live-${GPARTED_VERSION}-${ARCH}.zip"
GPARTED_TEMP_FILE="gparted-live-${GPARTED_VERSION}-${ARCH}.zip"
# If this version is not already present on the system
if is_file_absent "${GPARTED_INSTALLER_DIR}/${ARCH}/${gparted_version}"; then
# Create and go into directory
mkdir -p ${GPARTED_INSTALLER_DIR}/${ARCH}
pushd ${GPARTED_INSTALLER_DIR}/${ARCH} > /dev/null
## (re)Create the installer directory for this architecture
rm --recursive --force -- "${GPARTED_INSTALLER_DIR}/${ARCH}"
mkdir --parents -- "${GPARTED_INSTALLER_DIR}/${ARCH}"
pushd "${GPARTED_INSTALLER_DIR}/${ARCH}" > /dev/null \
|| error_message "Can't move to ${GPARTED_INSTALLER_DIR}/${ARCH} directory." 2
# Download and extract only PXE files
#wget "${GPARTED_URL}" -O "${GPARTED_TEMP_FILE}"
wget --quiet "${GPARTED_URL}" -O "${GPARTED_TEMP_FILE}"
#unzip -j "${GPARTED_TEMP_FILE}" live/filesystem.squashfs live/initrd.img live/vmlinuz -d .
unzip -q -j "${GPARTED_TEMP_FILE}" live/filesystem.squashfs live/initrd.img live/vmlinuz -d .
rm -f "${GPARTED_TEMP_FILE}"
## Download and extract the last version
download_file "${GPARTED_URL}" "${GPARTED_TEMP_FILE}"
is_file_empty "${GPARTED_TEMP_FILE}" \
&& error_message "${GPARTED_TEMP_FILE} is empty." 3
unzip -qq -j "${GPARTED_TEMP_FILE}" live/filesystem.squashfs live/initrd.img live/vmlinuz -d .
popd > /dev/null
rm --force -- "${GPARTED_TEMP_FILE}"
/bin/cat >> "${CONFIG_PXE}" << EOF
### Add flag file to know that this version is available
true > "${GPARTED_INSTALLER_DIR}/${ARCH}/${gparted_version}"
/bin/cat >> "${CONFIG_PXE}" << EOF
label gpartedlive${ARCH}
menu label Partiton Manager ${ARCH} (^Gparted)
kernel installer/gparted/${ARCH}/vmlinuz
append initrd=installer/gparted/${ARCH}/initrd.img boot=live config components union=overlay username=user noswap noeject ip= vga=788 fetch=tftp://129.20.203.27/installer/gparted/${ARCH}/filesystem.squashfs
EOF
done
popd > /dev/null \
|| error_message "Can't move back from ${GPARTED_INSTALLER_DIR}/${ARCH}/ directory." 2
fi
done
### }}}
### }}}
# Config file
/bin/cat >> "${CONFIG_PXE}" << EOF
# Config file
/bin/cat >> "${CONFIG_PXE}" << EOF
label separator
menu label -----
label mainmenu
menu label ^Back..
menu exit
EOF
}
# }}}
# Manage arguments # {{{
# This code can't be in a function due to argument management
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
## If the first argument is not an option
if ! printf -- '%s' "${1}" | grep -q -E -- "^-+";
then
## Print help message and exit
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
fi
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
case "${1}" in
-g|--gparted ) ## Define gparted_version
## Move to the next argument
shift
## Define var
readonly gparted_version="${1}"
;;
-m|--memtest ) ## Define memtest_version
## Move to the next argument
shift
## Define var
readonly memtest_version="${1}"
;;
-d|--debug ) ## debug
DEBUG=0
;;
-h|--help ) ## help
usage
## Exit after help informations
exit 0
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "Arguments management \
${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "Arguments management \
${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "Arguments management \
No arguments/options to manage."
fi
# }}}
main
exit 0

View File

@ -1,76 +1,337 @@
#!/bin/bash
# This script do the following:
# Download Debian Initrd for Buster, Bullseye, Stretch, Jessie and Sid
# Download firmwares:
# bnx2
# all non-free (for tigon)
# Myricom for IBM
# qlogic
# iwlwifi (Intel WiFi for user's laptop)
# Extract all downloaded files
# Make a new initrd with the previous firmwares with XZ format
# Purpose {{{
# This script will build a new initrd with some extra firmwares.
# 1. Download Debian initrd (Bullseye, Buster, Stretch and Sid)
# 2. Download firmwares
# * bnx2
# * all non-free (for tigon)
# * Myricom for IBM
# * qlogic
# * iwlwifi (Intel WiFi for user's laptop)
# 3. Extract everything
# 4. Build a new initrd with everything and compress with XZ
# }}}
# Vars {{{
readonly PROGNAME=$(basename "${0}")
readonly NBARGS="${#}"
[ -z "${DEBUG}" ] && DEBUG=1
## Export DEBUG for sub-script
export DEBUG
# Default value for TFTP's directory
if command -v in.tftpd > /dev/null; then
source /etc/default/tftpd-hpa
else
TFTP_DIRECTORY="/srv/tftp"
fi
for DISTRO in bullseye buster stretch sid; do # For ALL Debian's version
FIRM_BNX2_DEB_URL_DEFAULT="http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-bnx2_0.43_all.deb"
FIRM_NONFREE_DEB_URL_DEFAULT="http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-linux-nonfree_0.43_all.deb"
FIRM_MYRICOM_DEB_URL_DEFAULT="http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-myricom_0.43_all.deb"
FIRM_QLOGIC_DEB_URL_DEFAULT="http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-qlogic_0.43_all.deb"
FIRM_IWLWIFI_DEB_URL_DEFAULT="http://ftp.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-iwlwifi_20210818-1_all.deb"
TEMP_DIR=$(mktemp -d)
pushd "${TEMP_DIR}" > /dev/null
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
usage() { # {{{
# Download and uncompress original initrd
#wget http://deb.debian.org/debian/dists/${DISTRO}/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz
wget --quiet http://deb.debian.org/debian/dists/${DISTRO}/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz
mkdir "${TEMP_DIR}"/mkinitrd
pushd "${TEMP_DIR}"/mkinitrd/ > /dev/null
zcat ../initrd.gz | cpio -iv
cat <<- EOF
usage: $PROGNAME [-d|-h]
popd > /dev/null
This script will build a new Debian initrd with extra firmwares for
"all" Debian's releases.
# Download bnx2's firmware and uncompress it
#wget http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-bnx2_0.43_all.deb
wget --quiet http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-bnx2_0.43_all.deb
dpkg-deb -x firmware-bnx2_0.43_all.deb "${TEMP_DIR}"/mkinitrd
EXAMPLES:
- Build Debian's initrd to default place (${TFTP_DIRECTORY})
${PROGNAME}
# Download tigon(all non-free)'s firmware and uncompress it
#wget http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-linux-nonfree_0.43_all.deb
wget --quiet http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-linux-nonfree_0.43_all.deb
dpkg-deb -x firmware-linux-nonfree_0.43_all.deb "${TEMP_DIR}"/mkinitrd
OPTIONS:
-d,--debug
Enable debug messages.
# Download myricom for IBM
#wget http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-myricom_0.43_all.deb
wget --quiet http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-myricom_0.43_all.deb
dpkg-deb -x firmware-myricom_0.43_all.deb "${TEMP_DIR}"/mkinitrd
-h,--help
Print this help message.
# Download qlogic
#wget http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-qlogic_0.43_all.deb
wget --quiet http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-qlogic_0.43_all.deb
dpkg-deb -x firmware-qlogic_0.43_all.deb "${TEMP_DIR}"/mkinitrd
EOF
# Download iwlwifi
#wget --quiet http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-iwlwifi_20210315-2_all.deb -O firmware-iwlwifi_all.deb
wget --quiet http://ftp.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-iwlwifi_20210818-1_all.deb -O firmware-iwlwifi_all.deb
dpkg-deb -x firmware-iwlwifi_all.deb "${TEMP_DIR}"/mkinitrd
}
# }}}
debug_message() { # {{{
# Make a new initrd
mv initrd.gz initrd_orig.gz
pushd "${TEMP_DIR}"/mkinitrd/ > /dev/null
find . | cpio --quiet -o -H newc | xz -c -9 --check=crc32 > ../initrd.xz
popd > /dev/null
local_message="${1}"
# Move it to PXE Debian installer
mkdir -p ${TFTP_DIRECTORY}/installer/debian/${DISTRO}/amd64/
mv initrd.xz ${TFTP_DIRECTORY}/installer/debian/${DISTRO}/amd64/initrd_firm.xz
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_message}"
popd > /dev/null
return 0
}
# }}}
error_message() { # {{{
# Clean temp file
rm -rf "${TEMP_DIR}"
local_error_message="${1}"
local_error_code="${2}"
done
## Print message
printf '%b\n' "ERROR ${PROGNAME}: ${RED}${local_error_message}${RESET}"
exit "${local_error_code:=66}"
}
# }}}
define_vars() { # {{{
# If firm_bnx2_deb_url wasn't defined (argument) {{{
if [ -z "${firm_bnx2_deb_url}" ]; then
## Use default value
firm_bnx2_deb_url="${FIRM_BNX2_DEB_URL_DEFAULT}"
fi
# }}}
# If firm_nonfree_deb_url wasn't defined (argument) {{{
if [ -z "${firm_nonfree_deb_url}" ]; then
## Use default value
firm_nonfree_deb_url="${FIRM_NONFREE_DEB_URL_DEFAULT}"
fi
# }}}
# If firm_myricom_deb_url wasn't defined (argument) {{{
if [ -z "${firm_myricom_deb_url}" ]; then
## Use default value
firm_myricom_deb_url="${FIRM_MYRICOM_DEB_URL_DEFAULT}"
fi
# }}}
# If firm_qlogic_deb_url wasn't defined (argument) {{{
if [ -z "${firm_qlogic_deb_url}" ]; then
## Use default value
firm_qlogic_deb_url="${FIRM_QLOGIC_DEB_URL_DEFAULT}"
fi
# }}}
# If firm_iwlwifi_deb_url wasn't defined (argument) {{{
if [ -z "${firm_iwlwifi_deb_url}" ]; then
## Use default value
firm_iwlwifi_deb_url="${FIRM_IWLWIFI_DEB_URL_DEFAULT}"
fi
# }}}
}
# }}}
download_file() { # {{{
local_url="${1}"
local_dest_file="${2}"
## If the destination file is empty
if [ -z "${local_dest_file}" ]; then
debug_message "download_file \
Download ${local_url} in the current directory."
wget --quiet "${local_url}"
else
debug_message "download_file \
Download ${local_url} to ${RED}${local_dest_file}${COLOR_DEBUG} ."
wget --quiet "${local_url}" --output-document="${local_dest_file}"
fi
## Unset variables
unset local_url
unset local_dest_file
}
# }}}
is_file_empty() { # {{{
local_file="${1}"
## File is empty by default
return_is_file_empty="0"
### Check if the file is empty
if [ ! -s "${local_file}" ]; then
return_is_file_empty="0"
debug_message "is_file_empty \
The file ${RED}${local_file}${COLOR_DEBUG} is empty or doesn't exists."
else
return_is_file_empty="1"
debug_message "is_file_empty \
The file ${RED}${local_file}${COLOR_DEBUG} exists and has a size greater than zero."
fi
## Unset variables
unset local_file
return "${return_is_file_empty}"
}
# }}}
main() { # {{{
if ! [ $(id -u) = 0 ]; then
# To allow creation of temp file (mknod,…)
error_message "Please run this script as root" 1
fi
define_vars
for DISTRO in bullseye buster stretch sid; do # For ALL Debian's version
debug_message "Main FOR loop \
Manage initrd and firmwares for ${RED}${DISTRO}${COLOR_DEBUG} release."
## Temp directory
TEMP_DIR=$(mktemp -d)
pushd "${TEMP_DIR}" > /dev/null \
|| error_message "Can't move to ${TEMP_DIR}/ temp directory." 2
initrd_file="${TEMP_DIR}/initrd.gz"
## Download original initrd {{{
download_file "http://deb.debian.org/debian/dists/${DISTRO}/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz" "${initrd_file}"
is_file_empty "${initrd_file}" \
&& error_message "${initrd_file} file for ${DISTRO} is empty !" 3
## }}}
## Uncompress initrd {{{
mkdir -- "${TEMP_DIR}"/mkinitrd
pushd "${TEMP_DIR}"/mkinitrd/ > /dev/null \
|| error_message "Can't move to ${TEMP_DIR}/mkinitrd/ directory." 2
zcat "${initrd_file}" | cpio --extract --quiet --preserve-modification-time 1>/dev/null \
|| error_message "Can't extract ${initrd_file} file for ${DISTRO}." 4
popd > /dev/null \
|| error_message "Can't move back from ${TEMP_DIR}/mkinitrd/ directory." 2
## }}}
## Download bnx2's firmware and uncompress it {{{
firm_bnx2_deb_file="${TEMP_DIR}/firmware-bnx2.deb"
#wget http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-bnx2_0.43_all.deb
download_file "${firm_bnx2_deb_url}" "${firm_bnx2_deb_file}"
is_file_empty "${firm_bnx2_deb_file}" \
&& error_message "${firm_bnx2_deb_file} file for ${DISTRO} is empty !" 3
dpkg-deb --extract "${firm_bnx2_deb_file}" "${TEMP_DIR}"/mkinitrd \
|| error_message "Can't extract ${firm_bnx2_deb_file} file for ${DISTRO}." 3
## }}}
## Download nonfree firmwares (for Tigon…) and uncompress it {{{
firm_nonfree_deb_file="${TEMP_DIR}/firmware-nonfree.deb"
download_file "${firm_nonfree_deb_url}" "${firm_nonfree_deb_file}"
is_file_empty "${firm_nonfree_deb_file}" \
&& error_message "${firm_nonfree_deb_file} file for ${DISTRO} is empty !" 3
dpkg-deb --extract "${firm_nonfree_deb_file}" "${TEMP_DIR}"/mkinitrd \
|| error_message "Can't extract ${firm_nonfree_deb_file} file for ${DISTRO}." 3
## }}}
## Download myricom's firmware (for IBM) and uncompress it {{{
firm_myricom_deb_file="${TEMP_DIR}/firmware-myricom.deb"
download_file "${firm_myricom_deb_url}" "${firm_myricom_deb_file}"
is_file_empty "${firm_myricom_deb_file}" \
&& error_message "${firm_myricom_deb_file} file for ${DISTRO} is empty !" 3
dpkg-deb --extract "${firm_myricom_deb_file}" "${TEMP_DIR}"/mkinitrd \
|| error_message "Can't extract ${firm_myricom_deb_file} file for ${DISTRO}." 3
## }}}
## Download qlogic's firmware and uncompress it {{{
firm_qlogic_deb_file="${TEMP_DIR}/firmware-qlogic.deb"
download_file "${firm_qlogic_deb_url}" "${firm_qlogic_deb_file}"
is_file_empty "${firm_qlogic_deb_file}" \
&& error_message "${firm_qlogic_deb_file} file for ${DISTRO} is empty !" 3
dpkg-deb --extract "${firm_qlogic_deb_file}" "${TEMP_DIR}"/mkinitrd \
|| error_message "Can't extract ${firm_qlogic_deb_file} file for ${DISTRO}." 3
## }}}
## Download iwlwifi's firmware (for user's laptop) and uncompress it {{{
firm_iwlwifi_deb_file="${TEMP_DIR}/firmware-iwlwifi.deb"
#wget http://deb.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-iwlwifi_0.43_all.deb
download_file "${firm_iwlwifi_deb_url}" "${firm_iwlwifi_deb_file}"
is_file_empty "${firm_iwlwifi_deb_file}" \
&& error_message "${firm_iwlwifi_deb_file} file for ${DISTRO} is empty !" 3
dpkg-deb --extract "${firm_iwlwifi_deb_file}" "${TEMP_DIR}"/mkinitrd \
|| error_message "Can't extract ${firm_iwlwifi_deb_file} file for ${DISTRO}." 3
## }}}
## Make a new initrd {{{
new_initrd_file="${TEMP_DIR}/initrd.xz"
mv "${initrd_file}" initrd_orig.gz
pushd "${TEMP_DIR}"/mkinitrd/ > /dev/null \
|| error_message "Can't move to ${TEMP_DIR}/mkinitrd/ temp directory." 2
### With a very good compression rate
find . | cpio --quiet --create --format=newc | xz --stdout -9 --check=crc32 > "${new_initrd_file}"
is_file_empty "${new_initrd_file}" \
&& error_message "New initrd ${new_initrd_file} file for ${DISTRO} is empty !" 3
popd > /dev/null \
|| error_message "Can't move back from ${TEMP_DIR}/mkinitrd/ directory." 2
## }}}
## Move new initrd to TFTP tree {{{
mkdir --parents -- "${TFTP_DIRECTORY}/installer/debian/${DISTRO}/amd64/"
mv -- "${new_initrd_file}" "${TFTP_DIRECTORY}/installer/debian/${DISTRO}/amd64/initrd_firm.xz"
## }}}
## Leave temp directory and clean it {{{
popd > /dev/null \
|| error_message "Can't move back from ${TEMP_DIR}/ directory." 2
rm --recursive --force -- "${TEMP_DIR}"
## }}}
done
}
# }}}
# Manage arguments # {{{
# This code can't be in a function due to argument management
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
## If the first argument is not an option
if ! printf -- '%s' "${1}" | grep -q -E -- "^-+";
then
## Print help message and exit
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
fi
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
case "${1}" in
-d|--debug ) ## debug
DEBUG=0
;;
-h|--help ) ## help
usage
## Exit after help informations
exit 0
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
debug_message "Arguments management \
${RED}${1}${COLOR_DEBUG} option managed."
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
debug_message "Arguments management \
${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
else
debug_message "Arguments management \
No arguments/options to manage."
fi
# }}}
main
exit 0

View File

@ -12,7 +12,7 @@ else
fi
# last Long Term Support distribution name
LTS="xenial"
LTS="focal"
for DISTRO in artful ${LTS}; do
for ARCH in amd64 i386; do