diff options
author | Simon Rettberg | 2014-07-27 00:10:16 +0200 |
---|---|---|
committer | Simon Rettberg | 2014-07-27 00:10:16 +0200 |
commit | 62d78729a32dd136feddede21a5dc6e9c3dbe2d7 (patch) | |
tree | dccd7c833bb33825c45922397dd84d629d25f05f /remote | |
parent | [rfs-s31] fix busybox copying v2 (diff) | |
download | tm-scripts-62d78729a32dd136feddede21a5dc6e9c3dbe2d7.tar.gz tm-scripts-62d78729a32dd136feddede21a5dc6e9c3dbe2d7.tar.xz tm-scripts-62d78729a32dd136feddede21a5dc6e9c3dbe2d7.zip |
helpers/includes now should include an __init function and not just do stuff right away when being sourced
Diffstat (limited to 'remote')
-rw-r--r-- | remote/includes/binutil.inc | 3 | ||||
-rw-r--r-- | remote/includes/chroot.inc | 10 | ||||
-rw-r--r-- | remote/includes/cleanup.inc | 6 | ||||
-rw-r--r-- | remote/includes/distribution.inc | 1 | ||||
-rw-r--r-- | remote/includes/paths.inc | 43 | ||||
-rw-r--r-- | remote/includes/system.inc | 63 | ||||
-rw-r--r-- | remote/includes/useradd.inc | 4 | ||||
-rw-r--r-- | remote/includes/versioncompare.inc | 2 |
8 files changed, 64 insertions, 68 deletions
diff --git a/remote/includes/binutil.inc b/remote/includes/binutil.inc index 73371c25..ae173deb 100644 --- a/remote/includes/binutil.inc +++ b/remote/includes/binutil.inc @@ -1,4 +1,3 @@ -#!/bin/bash # # Common functions to copy binaries and their dependancies. # @@ -19,7 +18,7 @@ ############################################################ # We use a blacklist mechanism to exclude common libraries. # This improves runtime quite a bit... -BLACKLIST="ld-linux linux-gate linux-vdso libc.so" +declare -rg BLACKLIST="ld-linux linux-gate linux-vdso libc.so" # Initialise flag and path for local search LOCALSEARCH=0 diff --git a/remote/includes/chroot.inc b/remote/includes/chroot.inc index 4a8a350f..146d7e7e 100644 --- a/remote/includes/chroot.inc +++ b/remote/includes/chroot.inc @@ -15,11 +15,11 @@ # # ----------------------------------------------------------------------------- -CHROOT_TEMPDIR="${ROOT_DIR}/remote/chroot.tmp" -CHROOT_MOUNTDIR="${CHROOT_TEMPDIR}/rootmount" -CHROOT_BINDDIR="${CHROOT_TEMPDIR}/rootbind" -CHROOT_LOWERDIR="/" -CHROOT_BINDMOUNTS="/dev /proc /sys /run" +declare -rg CHROOT_TEMPDIR="${ROOT_DIR}/remote/chroot.tmp" +declare -rg CHROOT_MOUNTDIR="${CHROOT_TEMPDIR}/rootmount" +declare -rg CHROOT_BINDDIR="${CHROOT_TEMPDIR}/rootbind" +declare -rg CHROOT_LOWERDIR="/" +declare -rg CHROOT_BINDMOUNTS="/dev /proc /sys /run" # Helper function to setup the directory structure chroot_prepare_dirs() { diff --git a/remote/includes/cleanup.inc b/remote/includes/cleanup.inc index 1b161444..9716c841 100644 --- a/remote/includes/cleanup.inc +++ b/remote/includes/cleanup.inc @@ -15,8 +15,10 @@ # # ----------------------------------------------------------------------------- -# run 'cleanexit' when CTRL-c is pressed, an abrupt program termination or exit happens -trap cleanexit SIGINT SIGTERM +__init () { + # run 'cleanexit' when CTRL-c is pressed, an abrupt program termination or exit happens + trap cleanexit SIGINT SIGTERM +} # main cleaner function cleanexit() { diff --git a/remote/includes/distribution.inc b/remote/includes/distribution.inc index 485d1224..560dcd4d 100644 --- a/remote/includes/distribution.inc +++ b/remote/includes/distribution.inc @@ -1,5 +1,4 @@ - detect_distribution () { # Set up distribution and package management [ -z "$SYS_DISTRIBUTION" ] && perror "SYS_DISTRIBUTION not set (should be done by helper/distribution.inc)" diff --git a/remote/includes/paths.inc b/remote/includes/paths.inc index ca692adb..928ca964 100644 --- a/remote/includes/paths.inc +++ b/remote/includes/paths.inc @@ -4,29 +4,28 @@ # by different modules instead of each module determining them on its own. # +__init () { + # Location of PAM-modules + for CANDIDATE in $(strings "$(ldd "$(which login)" | grep libpam.so | head -n 1 | awk '{print $3}')" | grep /lib); do + [ -f "$CANDIDATE/pam_unix.so" ] && declare -rg SYS_PAM_MODULES_PATH="$CANDIDATE" && break + done -# Location of PAM-modules -for CANDIDATE in $(strings "$(ldd "$(which login)" | grep libpam.so | head -n 1 | awk '{print $3}')" | grep /lib); do - [ -f "$CANDIDATE/pam_unix.so" ] && declare -rg SYS_PAM_MODULES_PATH="$CANDIDATE" && break -done + [ -z "$SYS_PAM_MODULES_PATH" ] && perror "Failed to find pam_unix.so on this system." -[ -z "$SYS_PAM_MODULES_PATH" ] && perror "Failed to find pam_unix.so on this system." + # + # Figure out if we have split usr + if [ -L "/bin" -a -L "/lib" ]; then + declare -rg USR_SPLIT="no" + else + declare -rg USR_SPLIT="yes" + fi + pdebug "/bin and /lib are split from /usr/bin and /usr/lib (they are not symlinks): $USR_SPLIT" -# -# Figure out if we have split usr -if [ -L "/bin" -a -L "/lib" ]; then - declare -rg USR_SPLIT="no" -else - declare -rg USR_SPLIT="yes" -fi -pdebug "/bin and /lib are split from /usr/bin and /usr/lib (they are not symlinks): $USR_SPLIT" - -SYS_LIB_PATHS="" -for DIR in /lib /lib32 /lib64 /usr/lib /usr/lib32 /usr/lib64; do - [ -d "$DIR" -a ! -L "$DIR" ] && SYS_LIB_PATHS+=" $DIR" -done -declare -rg SYS_LIB_PATHS=$SYS_LIB_PATHS -pdebug "System lib paths: $SYS_LIB_PATHS" - -true + SYS_LIB_PATHS="" + for DIR in /lib /lib32 /lib64 /usr/lib /usr/lib32 /usr/lib64; do + [ -d "$DIR" -a ! -L "$DIR" ] && SYS_LIB_PATHS+=" $DIR" + done + declare -rg SYS_LIB_PATHS=$SYS_LIB_PATHS + pdebug "System lib paths: $SYS_LIB_PATHS" +} diff --git a/remote/includes/system.inc b/remote/includes/system.inc index 23a5f18b..ea953d69 100644 --- a/remote/includes/system.inc +++ b/remote/includes/system.inc @@ -1,36 +1,37 @@ # Helper to determine various system information -# -# determine architecture triplet from the path of libc needed by the executing shell. -# please try not to use this to find/fetch libs in /lib or /usr/lib. -# Use ARCH_LIB_DIR, like "$ARCH_LIB_DIR/somefile.so" or "/usr$ARCH_LIB_DIR/somefile.so" -ARCH_TRIPLET=$(ldd $SHELL|grep "libc.so" | awk -F "/" '{print $3}') -#[ -z "$ARCH_TRIPLET" ] && pwarning "Could not determine arch triplet." -[[ $ARCH_TRIPLET == *\(*\) ]] && ARCH_TRIPLET="" +__init () { + # determine architecture triplet from the path of libc needed by the executing shell. + # please try not to use this to find/fetch libs in /lib or /usr/lib. + # Use ARCH_LIB_DIR, like "$ARCH_LIB_DIR/somefile.so" or "/usr$ARCH_LIB_DIR/somefile.so" + ARCH_TRIPLET=$(ldd $SHELL|grep "libc.so" | awk -F "/" '{print $3}') + [[ $ARCH_TRIPLET == *\(*\) ]] && ARCH_TRIPLET="" -ARCH_LIB_DIR=$(ldd $SHELL | grep "libc.so" | sed -r 's#^.*(/lib.*)/libc.so.*$#\1#g') -[ -z "$ARCH_LIB_DIR" -o ! -d "$ARCH_LIB_DIR" ] && perror "Could not determine arch dependent lib dir (where libc.so resides)" + ARCH_LIB_DIR=$(ldd $SHELL | grep "libc.so" | sed -r 's#^.*(/lib.*)/libc.so.*$#\1#g') + [ -z "$ARCH_LIB_DIR" -o ! -d "$ARCH_LIB_DIR" ] && perror "Could not determine arch dependent lib dir (where libc.so resides)" -# determine number of CPU cores -CPU_CORES=$(cat /proc/cpuinfo | grep processor | wc -l) -export MAKEFLAGS="-j$CPU_CORES" + # determine number of CPU cores + declare -rg CPU_CORES=$(cat /proc/cpuinfo | grep processor | wc -l) + export MAKEFLAGS="-j$CPU_CORES" + + # Determine if we have lib64 + if [ "$(uname -m)x" = "x86_64x" ]; then + # Setting LIB64, as openSuse differentiates but Ubuntu does not: + case $SYS_DISTRIBUTION in + ubuntu | debian) LIB64="lib" ;; + opensuse | fedora | centos) LIB64="lib64" ;; + *) perror "Cannot set LIB64, SYS_DISTRIBUTION: $SYS_DISTRIBUTION unknown!" ;; + esac + AMD64_I386=amd64 + X86_64_I586=x86_64 + AMD64_X86=amd64 + ARCHREGEX="(amd64|x86[_-]64)" + else + LIB64="lib" + AMD64_I386=i386 + X86_64_I586=i586 + AMD64_X86=x86 + ARCHREGEX="(i[3456]86|x86[_-]32)" + fi +} -# Determine if we have lib64 -if [ "$(uname -m)x" = "x86_64x" ]; then - # Setting LIB64, as openSuse differentiates but Ubuntu does not: - case $SYS_DISTRIBUTION in - ubuntu | debian) LIB64="lib" ;; - opensuse | fedora | centos) LIB64="lib64" ;; - *) perror "Cannot set LIB64, SYS_DISTRIBUTION: $SYS_DISTRIBUTION unknown!" ;; - esac - AMD64_I386=amd64 - X86_64_I586=x86_64 - AMD64_X86=amd64 - ARCHREGEX="(amd64|x86[_-]64)" -else - LIB64="lib" - AMD64_I386=i386 - X86_64_I586=i586 - AMD64_X86=x86 - ARCHREGEX="(i[3456]86|x86[_-]32)" -fi diff --git a/remote/includes/useradd.inc b/remote/includes/useradd.inc index a8f407f7..2beaaeae 100644 --- a/remote/includes/useradd.inc +++ b/remote/includes/useradd.inc @@ -14,9 +14,7 @@ # IDs will be generated in the range of 5-999 if not explicitly given # TODO: Make it possible to pass a range of IDs if you don't want one <1000 but don't care about the exact ID -. "${ROOT_DIR}/helper/string.inc" - -declare -r NAME_REGEX='^[a-z][-a-z0-9]*$' +declare -rg NAME_REGEX='^[a-z][-a-z0-9]*$' # Generate a UID for a given USERNAME. Return existing UID if possible, generate new one otherwise generate_uid() diff --git a/remote/includes/versioncompare.inc b/remote/includes/versioncompare.inc index 75f59456..f49a404f 100644 --- a/remote/includes/versioncompare.inc +++ b/remote/includes/versioncompare.inc @@ -59,5 +59,3 @@ version_eq () { return $? } -version_eq "1.0" "1" && ! version_eq "1.0" "1.1" && version_ge "1.1" "1.0" - |