aboutsummaryrefslogtreecommitdiff
path: root/reproduce/software/shell/prep-source.sh
diff options
context:
space:
mode:
authorMohammad Akhlaghi <mohammad@akhlaghi.org>2024-05-03 13:07:41 +0200
committerMohammad Akhlaghi <mohammad@akhlaghi.org>2025-02-10 19:34:26 +0100
commit3c9bf3aff30f02c7d31bd86f36c4db2520f8ffa4 (patch)
treec4b6ee74518ae5256626f6888c2ceccfa66ce2a2 /reproduce/software/shell/prep-source.sh
parent8161194d68665648b93389adb333e741ba230497 (diff)
Configuration: no dependency on /bin/sh and useful run-time options
SUMMARY: no change necessary in your project, this commit only involves changes in how already-existing software are built. Some handy options have also been added to the top-level project script and the copyright years have been updated. Until now, if the host's '/bin/sh' had conflicts with the Maneage environment, the configuration of Maneage would crash as soon as we entered the building of high-level software. The full scenario is described in the comments of the newly added 'reproduce/software/shell/prep-source.sh'. This is most relevant when building older Maneage'd project in newer environments. With this commit, the following changes were made to avoid the problem above: - Maneage edits the source code of all installed software to replace '/bin/sh' with Maneage's own shell before the programs are built. Through this, we were able to solve the problem described above. - The portable '#!/usr/bin/env sh' shebangs are now used at the start of the scripts that run during configure time so it uses the first available shell that it finds in its PATH (the system's before Dash is built), then Dash, and after Dash is built, Bash. - For TeXLive, since we don't install it from source, it was necessary to add the libraries necessary for the local '/bin/sh' in LD_LIBRARY_PATH. Some high-level options have been added to the './project' script to simplify certain operations: --keep-going: do not stop upon the first crash, but keep going on to build targets until all build-able targets have been built. This is very useful for debugging large pipelines and allows you to isolate the problematic part of your project. --highlight-all: equivalent to calling both '--highlight-new' & '--highlight-notes'.
Diffstat (limited to 'reproduce/software/shell/prep-source.sh')
-rwxr-xr-xreproduce/software/shell/prep-source.sh94
1 files changed, 94 insertions, 0 deletions
diff --git a/reproduce/software/shell/prep-source.sh b/reproduce/software/shell/prep-source.sh
new file mode 100755
index 0000000..dcdc472
--- /dev/null
+++ b/reproduce/software/shell/prep-source.sh
@@ -0,0 +1,94 @@
+#!/usr/bin/env sh
+#
+# Necessary corrections in the un-packed source of programs to make them
+# portable (for example to not use '/bin/sh').
+#
+# Usage: Run in top source directory (will work on all files within the
+# directory that it is run in ):
+# ./prep-source.sh /FULL/ADDRESS/TO/DESIRED/BIN
+#
+# Copyright (C) 2024-2025 Mohammad Akhlaghi <mohammad@akhlaghi.org>
+#
+# This script is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This script 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 script. If not, see <http://www.gnu.org/licenses/>.
+
+
+
+
+
+# Abort the script in case of an error
+set -e
+
+
+
+
+# Read the first argument.
+bindir="$1"
+if [ x"$bindir" = x ]; then
+ printf "$0: no argument (location of the 'bin/' directory "
+ printf "containing the 'bash' executable)\n"
+ exit 1
+elif ! [ -d "$bindir" ]; then
+ printf "$0: the directory given as the first argument ('$bindir')"
+ printf "does not exist"
+fi
+
+
+
+
+
+# Find all the files that contain the '/bin/sh' string and correct them to
+# Maneage's own Bash. We are using 'while read' to read the file names line
+# by line. This is necessary to account file names that include the 'SPACE'
+# character (happens in CMake for example!).
+#
+# Note that dates are important in the source directory (files depend on
+# each other), so we should read the original date and after making. We are
+# also not using GNU SED's '-i' ('--in-place') option because the host OS
+# may not have GNU SED.
+#
+# Actual situation which prompted the addition of this step: a Maneage'd
+# project (with GNU Bash 5.1.8 and Readline 8.1.1) was being built on a
+# system where '/bin/sh' was GNU Bash 5.2.26 and had Readline 8.2.010. The
+# newer version of Bash needed the newer Readline library function(s) that
+# were not available in Maneage's Readline library. Therefore, as soon as
+# the basic software were built and Maneage entered the creation of
+# high-level software (where we completely close-off the host environment),
+# Maneage crashed with the following '/bin/sh' error:
+#
+# /bin/sh: symbol lookup error: /bin/sh: undefined symbol: rl_trim_arg_from_keyseq
+#
+# This lead to the discovery that through '/bin/sh' the host operating
+# system was leaking into our closed Maneage environment which needs to be
+# closed. This needs a source-level correction because '/bin/sh' is
+# hard-coded in the source code of almost all programs (their build
+# scripts); and in special programs like GNU Make, GNU M4 or CMake it is
+# actually hardcoded in the source code (not just build scripts).
+if [ -f "$bindir/bash" ]; then shpath="$bindir"/bash
+else shpath="$bindir"/dash
+fi
+grep -I -r -e'/bin/sh' $(pwd)/* \
+ | sed -e's|:|\t|' \
+ | awk 'BEGIN{FS="\t"}{print $1}' \
+ | sort \
+ | uniq \
+ | while read filename; do \
+ tmp="$filename".tmp; \
+ origtime="$(date -R -r "$filename")"; \
+ origperm=$(stat -c '%a' "$filename"); \
+ sed -e's|/bin/sh|'"$shpath"'|g' "$filename" > "$tmp"; \
+ mv "$tmp" "$filename"; \
+ chmod $origperm "$filename"; \
+ touch -d"$origtime" "$filename"; \
+ echo "Corrected /bin/sh in $filename"; \
+ done