lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 8e2ced7 03/10: Improve 'lmi_setup_*.sh', nota


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 8e2ced7 03/10: Improve 'lmi_setup_*.sh', notably resolving shellcheck issues
Date: Thu, 26 Sep 2019 09:40:18 -0400 (EDT)

branch: master
commit 8e2ced7d5dea81d970c2897e007e98ce2c30eab7
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Improve 'lmi_setup_*.sh', notably resolving shellcheck issues
    
    Made all these scripts executable.
    
    Replaced zsh hashbangs with /bin/sh except where zsh is needed.
    
    Changes motivated by shellcheck include:
     - quoting even where it should "never" matter
     - avoiding pushd/popd, which are somewhat weird in scripts anyway
     - printing an error message if cd fails to change directories
---
 lmi_setup_10.sh  |  4 ++--
 lmi_setup_11.sh  | 12 ++++++------
 lmi_setup_20.sh  |  6 +++---
 lmi_setup_21.sh  |  2 +-
 lmi_setup_30.sh  |  2 +-
 lmi_setup_40.sh  |  2 +-
 lmi_setup_41.sh  | 12 +++++-------
 lmi_setup_42.sh  |  5 +++--
 lmi_setup_43.sh  | 26 +++++++++++++++-----------
 lmi_setup_inc.sh |  5 ++++-
 10 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/lmi_setup_10.sh b/lmi_setup_10.sh
old mode 100644
new mode 100755
index e1ec2a0..e91a79a
--- a/lmi_setup_10.sh
+++ b/lmi_setup_10.sh
@@ -1,4 +1,4 @@
-#!/bin/zsh
+#!/bin/sh
 
 # Create a chroot for cross-building "Let me illustrate...".
 #
@@ -29,4 +29,4 @@ apt-get install schroot debootstrap
 # Download all OS essentials. This step may be done a single time, and
 # its tarball used repeatedly. The target ('/tmp/eraseme') directory
 # will be created and erased automatically.
-debootstrap --arch=amd64 --make-tarball=/var/cache/${CODENAME}_bootstrap.tar 
${CODENAME} /tmp/eraseme
+debootstrap --arch=amd64 --make-tarball=/var/cache/"${CODENAME}"_bootstrap.tar 
"${CODENAME}" /tmp/eraseme
diff --git a/lmi_setup_11.sh b/lmi_setup_11.sh
old mode 100644
new mode 100755
index 2d7a5e7..3169808
--- a/lmi_setup_11.sh
+++ b/lmi_setup_11.sh
@@ -1,4 +1,4 @@
-#!/bin/zsh
+#!/bin/sh
 
 # Create a chroot for cross-building "Let me illustrate...".
 #
@@ -26,14 +26,14 @@
 # Unpack the OS tarball into the particular chroot being created.
 # (If the preceding apt-get and debootstrap steps have already been
 # completed once, then skip them and start here.)
-mkdir -p /srv/chroot/${CHRTNAME}
-debootstrap --arch=amd64 --unpack-tarball=/var/cache/${CODENAME}_bootstrap.tar 
\
- ${CODENAME} /srv/chroot/${CHRTNAME} >${CHRTNAME}-debootstrap-log 2>&1
+mkdir -p /srv/chroot/"${CHRTNAME}"
+debootstrap --arch=amd64 
--unpack-tarball=/var/cache/"${CODENAME}"_bootstrap.tar \
+ "${CODENAME}" /srv/chroot/"${CHRTNAME}" >"${CHRTNAME}"-debootstrap-log 2>&1
 
 # This command should produce no output:
-grep --invert-match '^I:' ${CHRTNAME}-debootstrap-log
+grep --invert-match '^I:' "${CHRTNAME}"-debootstrap-log
 
-cat >/etc/schroot/chroot.d/${CHRTNAME}.conf <<EOF
+cat >/etc/schroot/chroot.d/"${CHRTNAME}".conf <<EOF
 [${CHRTNAME}]
 aliases=lmi
 description=debian ${CODENAME} cross build ${CHRTVER}
diff --git a/lmi_setup_20.sh b/lmi_setup_20.sh
old mode 100644
new mode 100755
index 2543491..59b0bb7
--- a/lmi_setup_20.sh
+++ b/lmi_setup_20.sh
@@ -1,4 +1,4 @@
-#!/bin/zsh
+#!/bin/sh
 
 # Create a chroot for cross-building "Let me illustrate...".
 #
@@ -84,10 +84,10 @@ apt-get --assume-yes install wget g++-mingw-w64 automake 
libtool make \
  pkg-config git cvs zsh bzip2 unzip sudo wine default-jre jing trang \
  g++-multilib libxml2-utils libxslt1-dev vim-gtk vim-doc shellcheck \
  bc bsdtar xsltproc \
- >${CHRTNAME}-apt-get-log 2>&1
+ >"${CHRTNAME}"-apt-get-log 2>&1
 
 # This command should produce little output:
-<${CHRTNAME}-apt-get-log tr -d '\r' | sed \
+<"${CHRTNAME}"-apt-get-log tr -d '\r' | sed \
  -e'0,/^Preconfiguring/d' \
  -e'/^Fetched\|^Preparing\|^Unpacking\|^Configuring\|^Selecting/d' \
  -e'/^Setting up\|^Processing\|^Adding\|^update-alternatives\|^[Dd]one./d' \
diff --git a/lmi_setup_21.sh b/lmi_setup_21.sh
old mode 100644
new mode 100755
index 70b5506..9e9092f
--- a/lmi_setup_21.sh
+++ b/lmi_setup_21.sh
@@ -1,4 +1,4 @@
-#!/bin/zsh
+#!/bin/sh
 
 # Create a chroot for cross-building "Let me illustrate...".
 #
diff --git a/lmi_setup_30.sh b/lmi_setup_30.sh
old mode 100644
new mode 100755
index 65eb2a8..30a2a8a
--- a/lmi_setup_30.sh
+++ b/lmi_setup_30.sh
@@ -1,4 +1,4 @@
-#!/bin/zsh
+#!/bin/sh
 
 # Create a chroot for cross-building "Let me illustrate...".
 #
diff --git a/lmi_setup_40.sh b/lmi_setup_40.sh
old mode 100644
new mode 100755
index 858c8da..da96663
--- a/lmi_setup_40.sh
+++ b/lmi_setup_40.sh
@@ -1,4 +1,4 @@
-#!/bin/zsh
+#!/bin/sh
 
 # Create a chroot for cross-building "Let me illustrate...".
 #
diff --git a/lmi_setup_41.sh b/lmi_setup_41.sh
old mode 100644
new mode 100755
index 44c9656..f907f26
--- a/lmi_setup_41.sh
+++ b/lmi_setup_41.sh
@@ -1,4 +1,4 @@
-#!/bin/zsh
+#!/bin/sh
 
 # Create a chroot for cross-building "Let me illustrate...".
 #
@@ -30,20 +30,18 @@
 #   https://lists.nongnu.org/archive/html/lmi/2017-05/msg00018.html
 
 mkdir -p ~/.wine/drive_c/users/greg/opt/
-pushd ~/.wine/drive_c/users/greg/opt/
+cd ~/.wine/drive_c/users/greg/opt/ || { printf 'failed: cd\n'; exit 3; }
 ln --symbolic --relative --force --no-dereference /opt/lmi/ ./lmi
-popd
 
 mkdir -p ~/.wine/drive_c/users/greg/etc/opt/
-pushd ~/.wine/drive_c/users/greg/etc/opt/
+cd ~/.wine/drive_c/users/greg/etc/opt/ || { printf 'failed: cd\n'; exit 3; }
 ln --symbolic --relative --force --no-dereference /etc/opt/lmi/ ./lmi
-popd
 
 mkdir -p ~/.wine/drive_c/users/greg/var/opt/
-pushd ~/.wine/drive_c/users/greg/var/opt/
+cd ~/.wine/drive_c/users/greg/var/opt/ || { printf 'failed: cd\n'; exit 3; }
 ln --symbolic --relative --force --no-dereference /var/opt/lmi/ ./lmi
-popd
 
+cd ~ || { printf 'failed: cd\n'; exit 3; }
 # Rebuild vim spellfile (as was done above for root)
 vim -es -c ':mkspell! ~/.vim/spell/en.utf-8.add' -c ':q'
 
diff --git a/lmi_setup_42.sh b/lmi_setup_42.sh
old mode 100644
new mode 100755
index 160a994..2968ffa
--- a/lmi_setup_42.sh
+++ b/lmi_setup_42.sh
@@ -1,4 +1,4 @@
-#!/bin/zsh
+#!/bin/sh
 
 # Create a chroot for cross-building "Let me illustrate...".
 #
@@ -25,6 +25,7 @@
 
 # Install lmi for wine.
 
+cd ~ || { printf 'failed: cd\n'; exit 3; }
 wget -N 'http://git.savannah.gnu.org/cgit/lmi.git/plain/install_msw.sh'
 chmod +x install_msw.sh
 ./install_msw.sh >log 2>&1
@@ -33,5 +34,5 @@ chmod +x install_msw.sh
 # msw program, prefix its command line with 'wine'. Test the chroot by
 # running the lmi binary built in the preceding step:
 
-pushd /opt/lmi/bin
+cd /opt/lmi/bin || { printf 'failed: cd\n'; exit 3; }
 wine ./lmi_wx_shared.exe --ash_nazg --data_path=../data
diff --git a/lmi_setup_43.sh b/lmi_setup_43.sh
old mode 100644
new mode 100755
index 81b44f9..bf63a77
--- a/lmi_setup_43.sh
+++ b/lmi_setup_43.sh
@@ -24,7 +24,7 @@
 . ./lmi_setup_inc.sh
 
 # Symlink the repository's hooks/ directory:
-cd /opt/lmi/src/lmi
+cd /opt/lmi/src/lmi || { printf 'failed: cd\n'; exit 3; }
 mv .git/hooks .git/hooks-orig
 ln --symbolic --force --no-dereference ../hooks .git
 
@@ -35,12 +35,12 @@ git remote set-url --push origin 
address@hidden:/srv/git/lmi.git
 # Duplicate proprietary repository (if available).
 # First, copy "blessed" repository (here, 'cp' is sufficient: this
 # bare repository has no references that need to be resolved):
-cd /opt/lmi
+cd /opt/lmi || { printf 'failed: cd\n'; exit 3; }
 cp --dereference --preserve --recursive /cache_for_lmi/blessed .
 # Then create a working copy by cloning the bare repository...
 git clone -b master file:///opt/lmi/blessed/proprietary
 # ...and verify it:
-cd proprietary
+cd proprietary || { printf 'failed: cd\n'; exit 3; }
 git rev-parse HEAD
 # ...then symlink its hooks/ directory:
 mv .git/hooks .git/hooks-orig
@@ -59,30 +59,34 @@ cp -a /opt/lmi/proprietary/test/* /opt/lmi/touchstone/
 
 # Remove object files previously built without proprietary source:
 . /opt/lmi/src/lmi/set_toolchain.sh
-rm /opt/lmi/${LMI_COMPILER}_${LMI_TRIPLET}/build/ship/my*
+rm /opt/lmi/"${LMI_COMPILER}_${LMI_TRIPLET}"/build/ship/my*
 
 # Regenerate the binary database (expect the 'rm' command here to fail
 # the first time, because there are no old files to remove):
-cd /opt/lmi/data
+cd /opt/lmi/data || { printf 'failed: cd\n'; exit 3; }
 rm proprietary.dat proprietary.ndx
 wine /opt/lmi/bin/rate_table_tool --accept --file=proprietary 
--merge=/opt/lmi/proprietary/tables
 
+coefficiency="--jobs=$(nproc)"
+
 # Run a system test.
-cd /opt/lmi/src/lmi
-make $coefficiency system_test 2>&1 |less -S
+cd /opt/lmi/src/lmi || { printf 'failed: cd\n'; exit 3; }
+make "$coefficiency" system_test 2>&1 |less -S
 # That test fails the first time because no results are saved in
 # touchstone/ yet. Copy the results just generated...
 cp -a /opt/lmi/test/* /opt/lmi/touchstone
 # ...removing summaries...
 rm /opt/lmi/touchstone/analysis* /opt/lmi/touchstone/diffs* 
/opt/lmi/touchstone/md5sum*
 # ...and rerun the test, which should now succeed:
-make $coefficiency system_test 2>&1 |less -S
+make "$coefficiency" system_test 2>&1 |less -S
 
 # Create a local mirror of the gnu.org repository:
-cd /opt/lmi
+cd /opt/lmi || { printf 'failed: cd\n'; exit 3; }
 mkdir --parents free/src
-cd free/src
+cd free/src || { printf 'failed: cd\n'; exit 3; }
 git clone git://git.savannah.nongnu.org/lmi.git
-for z in **/*(D) ; do touch --reference=/opt/lmi/src/lmi/$z $z; done 2>&1 |sed 
\
+# shellcheck disable=SC2039
+#   (zsh glob qualifier: GLOB_DOTS)
+for z in **/*(D) ; do touch --reference=/opt/lmi/src/lmi/"$z" "$z"; done 2>&1 
|sed \
   -e'/\/.git\/FETCH_HEAD[^0-9A-Za-z-]/d' \
   -e'/\/.git\/hooks\/[a-z-]*\.sample[^0-9A-Za-z-]/d'
diff --git a/lmi_setup_inc.sh b/lmi_setup_inc.sh
old mode 100644
new mode 100755
index 587c343..14fbd3a
--- a/lmi_setup_inc.sh
+++ b/lmi_setup_inc.sh
@@ -1,4 +1,4 @@
-#!/bin/zsh
+#!/bin/sh
 
 # Create a chroot for cross-building "Let me illustrate...".
 #
@@ -28,3 +28,6 @@
 CODENAME=bullseye
 CHRTVER=0
 CHRTNAME=lmi_${CODENAME}${CHRTVER}
+# shellcheck disable=SC2034
+#   (this file should only be sourced)
+export CHRTNAME



reply via email to

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