2 # Simple script to download a Grml ISO image to use with grml-rescueboot
3 # Needs the Debian keyring, gpgv + wget
4 # Licensed under GPL v2+
14 declare -A bin_to_pkg=( [update-grub]=grub-pc [wget]=wget [gpgv]=gpgv )
15 declare -a missing_packages=()
16 for binary in "${!bin_to_pkg[@]}" ; do
17 if ! which "${binary}" &>/dev/null ; then
18 echo "ERROR: Binary $binary not found." >&2
19 missing_packages+=( ${bin_to_pkg[$binary]} )
23 if ! [ -r /usr/share/keyrings/debian-keyring.gpg ] ; then
24 echo "ERROR: File /usr/share/keyrings/debian-keyring.gpg not found." >&2
25 missing_packages+=( debian-keyring )
28 if [ ${#missing_packages[@]} -ne 0 ] ; then
29 echo "TIP: Try running \`apt install ${missing_packages[*]}\` to fix this." >&2
34 echo "Usage: $(basename "$0") [-f] [-a <32|64|96>] [-t <small|full>]"
37 while getopts ":a::t::f:h" opt ; do
40 if [ "${OPTARG}" = 32 ] || [ "${OPTARG}" = 64 ] || [ "${OPTARG}" = 96 ] ; then
43 echo "ERROR: Invalid value '${OPTARG}'. Supported values: 32, 64, 96" >&2
48 if [ "${OPTARG}" = "full" ] || [ "${OPTARG}" = "small" ] ; then
51 echo "ERROR: Invalid value '${OPTARG}'. Supported values: small, full" >&2
62 echo "ERROR: Invalid Option: -${OPTARG}" >&2
66 echo "ERROR: Option -${OPTARG} requires an argument." >&2
71 if [ "${bitwidth}" = auto ] ; then
81 echo "ERROR: Unknown architecture '${arch}', please specify -a flag." >&2
88 echo "Finding out latest ISO image..."
89 date=$(wget --quiet -O- http://download.grml.org/ | sed --regex -n 's/.*grml[0-9]{2}-(full|small)_([0-9]{4}\.[0-9]{2})\.iso.*/\2/p' | sort | tail -1)
91 if [ -z "${date}" ] ; then
92 echo "ERROR: Could not find out latest ISO." >&2
96 output_directory="/boot/grml"
97 mkdir -p "${output_directory}"
99 diskfree=$(df --output=avail /boot/grml | tail -1)
100 if [ -z "${diskfree}" ] ; then
101 echo "ERROR: couldn't calculate free disk space in /boot." >&2
105 if [ "${isotype}" = "full" ] && [ "${diskfree}" -lt 1048576 ] ; then
106 if [ "${force}" = "1" ] ; then
107 echo "WARN: There might not be enough free disk space in /boot, continuing anyway as requested via -f."
109 echo "ERROR: there doesn't seem to be enough free disk space in /boot." >&2
110 echo "Note: >=1GB for grml-full recommended (use -f to force download anyway)."
113 elif [ "${isotype}" = "small" ] && [ "${diskfree}" -lt 524288 ] ; then
114 if [ "${force}" = "1" ] ; then
115 echo "WARN: There might not be enough free disk space in /boot, continuing anyway as requested via -f."
117 echo "ERROR: there doesn't seem to be enough free disk space in /boot." >&2
118 echo "Note: >=512MB for grml-small recommended (use -f to force download anyway)."
123 isoname="grml${bitwidth}-${isotype}_${date}.iso"
125 if [ "${force}" = "1" ] || ! [ -f "${output_directory}/${isoname}" ] ; then
126 echo "Downloading Grml ISO to '${output_directory}/${isoname}'."
127 wget -O "${output_directory}/${isoname}" "http://download.grml.org/${isoname}"
129 elif [ -f "${output_directory}/${isoname}" ] ; then
130 echo "Found local ${output_directory}/${isoname}, skipping download (use -f to force download)."
133 if [ "${retrieved_iso}" = "1" ] ; then
135 echo "Verifying ISO..."
136 wget --quiet -O "${sig}" "http://download.grml.org/${isoname}.asc"
138 if ! gpgv --keyring /usr/share/keyrings/debian-keyring.gpg "${sig}" "${output_directory}/${isoname}" ; then
139 echo "ERROR: ISO file will be left in '${output_directory}/${isoname}.untrusted'." >&2
140 mv "${output_directory}/${isoname}" "${output_directory}/${isoname}.untrusted"
147 echo "ISO file is OK."
150 echo "Invoking 'update-grub' now."
153 echo "Successfully finished grml-rescueboot integration."