#!/bin/sh # Create a chroot for cross-building "Let me illustrate...". # # Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Gregory W. Chicares. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA # # https://savannah.nongnu.org/projects/lmi # email: # snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA set -evx stamp0=$(date -u +'%Y-%m-%dT%H:%M:%SZ') echo "Started: $stamp0" # A known corporate firewall blocks gnu.org even on a GNU/Linux # server, yet allows github.com: if curl https://git.savannah.nongnu.org:443 >/dev/null 2>&1 ; then GIT_URL_BASE=https://git.savannah.nongnu.org/cgit/lmi.git/plain else GIT_URL_BASE=https://github.com/let-me-illustrate/lmi/raw/master fi # Store dynamic configuration in a temporary file. This method is # simple and robust, and far better than trying to pass environment # variables across sudo and schroot barriers. NORMAL_USER=$(id -un "$(logname)") if getent group lmi; then NORMAL_GROUP=lmi NORMAL_GROUP_GID=$(getent group "$NORMAL_GROUP" | cut -d ':' -f3) CHROOT_USERS=$(getent group "$NORMAL_GROUP" | cut -d ':' -f4) else NORMAL_GROUP=$(id -gn "$(logname)") NORMAL_GROUP_GID=$(id -g "$(logname)") CHROOT_USERS=$(id -un "$(logname)") fi CHROOT_UIDS= for user in $(echo "${CHROOT_USERS}" | tr ',' ' '); do uid=$(id -u "${user}") [ -z "${uid}" ] && echo "Oops." CHROOT_UIDS="${CHROOT_UIDS},${uid}" done # Remove leading delimiter. CHROOT_UIDS=$(echo "${CHROOT_UIDS}" | sed -e's/^,//') cat >/tmp/schroot_env <"${logdir}/${flavor}-log" 2>&1 # Timestamp suffix for log file names (no colons, for portability). fstamp=$(date -u +"%Y%m%dT%H%MZ" -d "$stamp0") # Copy log files that may be useful for tracking down problems with # certain commands whose output is voluminous and often uninteresting. # Archive them for easy sharing. # # It would be easier to specify the files to be archived as # ./*"${fstamp} # but that would cause 'tar' to fail thus: # tar: [filename]: file changed as we read it # if this script's output is redirected to a file that's uniquified # by the same $fstamp method used here. (cd "${logdir}" logfiles= for z in \ "${CHRTNAME}"-debootstrap-log \ "${CHRTNAME}"-apt-get-log \ lmi-log \ "${flavor}-log" \ ; do z_stamped="${z}_${fstamp}" mv "${z}" "${z_stamped}" logfiles="${logfiles} ${z_stamped}" done # Word-splitting is definitely wanted for ${logfiles} here: # shellcheck disable=SC2086 tar -cJvf chroot-logs_"${fstamp}".tar.xz ${logfiles} ) stamp1=$(date -u +'%Y-%m-%dT%H:%M:%SZ') echo "Finished: $stamp1" seconds=$(($(date -u '+%s' -d "$stamp1") - $(date -u '+%s' -d "$stamp0"))) elapsed=$(date -u -d @"$seconds" +'%H:%M:%S') stamp=$(date -u +'%Y%m%dT%H%M%SZ') echo "$stamp $0 Installed and tested lmi." | tee /dev/tty || true echo "Elapsed: $elapsed; log suffix: $fstamp" | tee /dev/tty || true