lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 2d08c59 3/3: Combine three nearly-identical s


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 2d08c59 3/3: Combine three nearly-identical scripts into one
Date: Fri, 29 May 2020 13:20:04 -0400 (EDT)

branch: master
commit 2d08c595dbe73a90992b4dee8263c16c8f3c8f65
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Combine three nearly-identical scripts into one
---
 install_centos.sh | 117 ------------------------------------------------------
 install_redhat.sh | 117 ------------------------------------------------------
 lmi_setup_00.sh   |  26 +++++++++++-
 3 files changed, 25 insertions(+), 235 deletions(-)

diff --git a/install_centos.sh b/install_centos.sh
deleted file mode 100755
index 78eb2dd..0000000
--- a/install_centos.sh
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/bin/sh
-
-# Create a chroot for cross-building "Let me illustrate..." on centos-7.
-#
-# Copyright (C) 2016, 2017, 2018, 2019, 2020 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
-#
-# http://savannah.nongnu.org/projects/lmi
-# email: <gchicares@sbcglobal.net>
-# 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/vadz/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)")
-   NORMAL_USER_UID=$(id -u  "$(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
-
-cat >/tmp/schroot_env <<EOF
-set -v
-    CHROOT_USERS=$CHROOT_USERS
-    GIT_URL_BASE=$GIT_URL_BASE
-    NORMAL_GROUP=$NORMAL_GROUP
-NORMAL_GROUP_GID=$NORMAL_GROUP_GID
-     NORMAL_USER=$NORMAL_USER
- NORMAL_USER_UID=$NORMAL_USER_UID
-set +v
-EOF
-chmod 0666 /tmp/schroot_env
-
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_00c.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_02.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_02c.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_05c.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_05r.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_07r.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_10.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_10c.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_10r.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_11.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_20.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_21.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_30.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_40.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_41.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_42.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_43.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_inc.sh
-chmod 0777 lmi_setup_*.sh
-
-. ./lmi_setup_inc.sh
-
-set -evx
-
-assert_su
-assert_not_chrooted
-
-# Timestamp suffix for log file names (no colons, for portability).
-fstamp=$(date -u +"%Y%m%dT%H%MZ" -d "$stamp0")
-
-logdir=/srv/cache_for_lmi/logs
-mkdir -p "${logdir}"
-./lmi_setup_00c.sh >"${logdir}"/chroot-log_"${fstamp}" 2>&1
-
-# 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.
-(cd "${logdir}"
-for z in "${CHRTNAME}"-apt-get-log lmi-log; do
-  mv "${z}" "${z}_${fstamp}"
-done
-tar -cJvf chroot-logs_"${fstamp}".tar.xz ./*"${fstamp}"
-)
-
-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')
-echo "Elapsed: $elapsed"
-
-echo Finished creating debian chroot. >/dev/tty
diff --git a/install_redhat.sh b/install_redhat.sh
deleted file mode 100755
index b0ce7d4..0000000
--- a/install_redhat.sh
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/bin/sh
-
-# Create a chroot for cross-building "Let me illustrate..." on redhat-7.
-#
-# Copyright (C) 2016, 2017, 2018, 2019, 2020 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
-#
-# http://savannah.nongnu.org/projects/lmi
-# email: <gchicares@sbcglobal.net>
-# 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/vadz/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)")
-   NORMAL_USER_UID=$(id -u  "$(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
-
-cat >/tmp/schroot_env <<EOF
-set -v
-    CHROOT_USERS=$CHROOT_USERS
-    GIT_URL_BASE=$GIT_URL_BASE
-    NORMAL_GROUP=$NORMAL_GROUP
-NORMAL_GROUP_GID=$NORMAL_GROUP_GID
-     NORMAL_USER=$NORMAL_USER
- NORMAL_USER_UID=$NORMAL_USER_UID
-set +v
-EOF
-chmod 0666 /tmp/schroot_env
-
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_00c.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_02.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_02c.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_05c.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_05r.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_07r.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_10.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_10c.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_10r.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_11.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_20.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_21.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_30.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_40.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_41.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_42.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_43.sh
-wget -N -nv "${GIT_URL_BASE}"/lmi_setup_inc.sh
-chmod 0777 lmi_setup_*.sh
-
-. ./lmi_setup_inc.sh
-
-set -evx
-
-assert_su
-assert_not_chrooted
-
-# Timestamp suffix for log file names (no colons, for portability).
-fstamp=$(date -u +"%Y%m%dT%H%MZ" -d "$stamp0")
-
-logdir=/srv/cache_for_lmi/logs
-mkdir -p "${logdir}"
-./lmi_setup_01r.sh >"${logdir}"/chroot-log_"${fstamp}" 2>&1
-
-# 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.
-(cd "${logdir}"
-for z in "${CHRTNAME}"-apt-get-log lmi-log; do
-  mv "${z}" "${z}_${fstamp}"
-done
-tar -cJvf chroot-logs_"${fstamp}".tar.xz ./*"${fstamp}"
-)
-
-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')
-echo "Elapsed: $elapsed"
-
-echo Finished creating debian chroot. >/dev/tty
diff --git a/lmi_setup_00.sh b/lmi_setup_00.sh
index c182c3b..03fa81f 100755
--- a/lmi_setup_00.sh
+++ b/lmi_setup_00.sh
@@ -90,12 +90,36 @@ set -evx
 assert_su
 assert_not_chrooted
 
+case "$(cat /proc/version)" in
+    (*Debian*)    flavor_guess=debian ;;
+    (*"Red Hat"*) flavor_guess=redhat ;;
+    (*)           flavor_guess=debian
+        printf '%s\n' "OS not detected--assuming debian."
+        ;;
+esac
+
+# The 'centos' flavor is extraordinary. It calls for creating a centos
+# chroot with a debian chroot inside. Override 'flavor' on the command
+# line to use it, e.g.:
+#   flavor=centos ./lmi_setup_00.sh
+# The "_01" scripts construct a debian-testing chroot. The 'centos'
+# case correctly selects a "00" script, which first constructs a
+# centos chroot, within which a debian-testing chroot is constructed.
+
+flavor=${flavor:-"$flavor_guess"}
+case "${flavor}" in
+    (debian) flavor_script=lmi_setup_01.sh  ;;
+    (centos) flavor_script=lmi_setup_00c.sh ;;
+    (redhat) flavor_script=lmi_setup_01r.sh ;;
+    (*) printf '%s\n' "Unanticipated case--exiting."; exit 3 ;;
+esac
+
 # Timestamp suffix for log file names (no colons, for portability).
 fstamp=$(date -u +"%Y%m%dT%H%MZ" -d "$stamp0")
 
 logdir=/srv/cache_for_lmi/logs
 mkdir -p "${logdir}"
-./lmi_setup_01.sh >"${logdir}"/chroot-log_"${fstamp}" 2>&1
+./"${flavor_script}" >"${logdir}/${flavor}-log_${fstamp}" 2>&1
 
 # Copy log files that may be useful for tracking down problems with
 # certain commands whose output is voluminous and often uninteresting.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]