summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-07-27 00:10:16 +0200
committerSimon Rettberg2014-07-27 00:10:16 +0200
commit62d78729a32dd136feddede21a5dc6e9c3dbe2d7 (patch)
treedccd7c833bb33825c45922397dd84d629d25f05f
parent[rfs-s31] fix busybox copying v2 (diff)
downloadtm-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
-rw-r--r--helper/fileutil.inc5
-rw-r--r--helper/logging.inc32
-rw-r--r--helper/string.inc6
-rwxr-xr-xmltk51
-rwxr-xr-xopenslx30
-rw-r--r--remote/includes/binutil.inc3
-rw-r--r--remote/includes/chroot.inc10
-rw-r--r--remote/includes/cleanup.inc6
-rw-r--r--remote/includes/distribution.inc1
-rw-r--r--remote/includes/paths.inc43
-rw-r--r--remote/includes/system.inc63
-rw-r--r--remote/includes/useradd.inc4
-rw-r--r--remote/includes/versioncompare.inc2
-rw-r--r--server/blacklists/desktop-sessions/filter1
14 files changed, 129 insertions, 128 deletions
diff --git a/helper/fileutil.inc b/helper/fileutil.inc
index 10b4bbc7..9dc2c07b 100644
--- a/helper/fileutil.inc
+++ b/helper/fileutil.inc
@@ -31,4 +31,9 @@ tarcopy () {
[ "x${PS[1]}" != "x0" ] && perror "unpacking-part of tar-copy from '$SHORT' to '$TO' failed. (${PS[1]})"
}
+# usage: CANONICALIZED_PATH=$(canonalize <path>)
+# usage with relative path requires you to be in the correct directory.
+canonicalize() {
+ cd -P -- "$(dirname -- "$1")" && printf '%s\n' "$(pwd -P)/$(basename -- "$1")"
+}
diff --git a/helper/logging.inc b/helper/logging.inc
index 8b102d4c..2e8eeeb7 100644
--- a/helper/logging.inc
+++ b/helper/logging.inc
@@ -1,22 +1,14 @@
+[ -n "$MLTK_QUIET" ] && return 0
-if [ "x$MLTK_QUIET" == "x" ]; then #ifndef _MLTK_QUIET
-#define _MLTK_QUIET
-
-MLTK_QUIET=0
-
-exec 6>&2
-
-LOG_DIR=${ROOT_DIR}/logs
-
-mkdir -p "$LOG_DIR"
-
-exec 8>&0 # This redirection is used for chroot debugging
+# This module is an exception, it doesn't use __init but runs commands directly...
+# Otherwise we cannot ensure that other module's init functions won't run first
+# and mess up the fds
set_quiet () {
if [ "x$MLTK_QUIET" != "x1" ]; then
exec 6>&1 > "$LOG_DIR/stdout.log"
exec 7>&2 2> "$LOG_DIR/stderr.log"
- MLTK_QUIET="1"
+ MLTK_QUIET=1
fi
}
@@ -25,7 +17,7 @@ unset_quiet () {
exec 1>&6 6>&-
exec 2>&7 7>&-
exec 6>&2
- MLTK_QUIET="0"
+ MLTK_QUIET=0
fi
}
@@ -34,7 +26,7 @@ pinfo () {
echo -e "\033[38;5;10m[info]\033[0m $TOOL_STR $@" >&6
}
-perror () {
+perror () {
echo -e "\033[38;5;9m[error]\033[0m $TOOL_STR $@" >&6
qnd_exit
}
@@ -51,5 +43,11 @@ pdebug () {
fi
}
-#endif
-fi
+exec 6>&2
+exec 8>&0 # This redirection is used for chroot debugging
+
+MLTK_QUIET=0
+declare -rg LOG_DIR=${ROOT_DIR}/logs
+mkdir -p "$LOG_DIR" || perror "Could not create '$LOG_DIR'"
+true
+
diff --git a/helper/string.inc b/helper/string.inc
index 75baf2ca..077f1719 100644
--- a/helper/string.inc
+++ b/helper/string.inc
@@ -12,12 +12,6 @@ itrim () {
sed -r 's/^\s+//g;s/\s+$//g'
}
-# usage: CANONICALIZED_STRING=$(canonalize <path>)
-# usage with relative path requires you to be in the correct directory.
-canonicalize() {
- cd -P -- "$(dirname -- "$1")" && printf '%s\n' "$(pwd -P)/$(basename -- "$1")"
-}
-
escape_search() {
sed -e 's/[]\/()$*.^|[]/\\&/g'
diff --git a/mltk b/mltk
index ffa857a6..2a42a103 100755
--- a/mltk
+++ b/mltk
@@ -16,10 +16,12 @@
#
# -----------------------------------------------------------------------------
-ARG0="$0"
-SELF="$(readlink -f "$ARG0")"
-ROOT_DIR="$(dirname "${SELF}")"
-MLTK_PID="$$"
+declare -rg ARG0="$0"
+declare -rg SELF="$(readlink -f "$ARG0")"
+declare -rg ROOT_DIR="$(dirname "${SELF}")"
+declare -rg MLTK_PID="$$"
+declare -rg REMOTE_SETUP_TARGET="${ROOT_DIR}/remote/setup_target"
+
# Make apt-get install non-interactive when it comes to postinstall questions
# ie. kdm asking which dm you want to set as default
@@ -33,21 +35,26 @@ qnd_exit() {
}
# source all helper unit files that are found under helper/*.inc
-# these are general and used by "mltk" and "openslx"
-for HELPER in "$ROOT_DIR"/helper/*.inc; do
- . "$HELPER" && continue
- unset_quiet
- echo "Could not source $HELPER"
- qnd_exit
-done
-
-# source specific units only used by mltk
-for HELPER in "$ROOT_DIR"/remote/includes/*.inc; do
- . "$HELPER" && continue
+# or remote/includes/*.inc
+# a helper unit may contain a function called "__init" which will be called
+# after all helpers have been sourced.
+for HELPER in "$ROOT_DIR"/helper/*.inc "$ROOT_DIR"/remote/includes/*.inc; do
+ SHORT=${HELPER%.inc}
+ SHORT="_init_${SHORT##*/}"
+ . <(sed "s/^__init/$SHORT/" "$HELPER") && continue
unset_quiet
echo "Could not source $HELPER"
qnd_exit
done
+# called below, after initial_checks
+init_helpers () {
+ # in case the helers have init functions, call them now
+ for HELPER in "$ROOT_DIR"/helper/*.inc "$ROOT_DIR"/remote/includes/*.inc; do
+ SHORT=${HELPER%.inc}
+ SHORT="_init_${SHORT##*/}"
+ type -t "$SHORT" | grep -q '^function$' && "$SHORT"
+ done
+}
# Support sourcing a "config" where you can set up stuff like 'export http_proxy=...'
[ -e "$ROOT_DIR/config" ] && . "$ROOT_DIR/config"
@@ -133,18 +140,11 @@ check_devtools() {
initial_checks() {
if [ "x$(whoami)" != "xroot" ]; then
- perror "ERROR: You need to have root rights to install packages."
+ perror "ERROR: You need to have root rights to install packages and do various other things."
exit 1
else
banner
fi
- pdebug "Arch triplet of this machine: $ARCH_TRIPLET"
-
- # source the central script:
- # setup_target
- # - builds all modules activated under the target directory
- # (basic targets are 'stage31' and 'stage32')
- REMOTE_SETUP_TARGET="${ROOT_DIR}/remote/setup_target"
[ ! -e "${REMOTE_SETUP_TARGET}" ] && perror "Missing script remote/setup_target. Exiting."
}
@@ -257,8 +257,8 @@ run() {
if [[ $REMOTE_CLEAN == 1 || $REMOTE_BUILD == 1 || $REMOTE_EXPORT == 1 ]]; then
[[ $REMOTE_DEBUG == 1 ]] && unset_quiet || set_quiet
. "${REMOTE_SETUP_TARGET}" || perror "Cannot source ${REMOTE_SETUP_TARGET}"
- [[ $REMOTE_CLEAN == 1 ]] && clean_modules $TARGET $REMOTE_LIST_CLEAN
- [[ $REMOTE_BUILD == 1 ]] && generate_target $TARGET $REMOTE_LIST_BUILD
+ [[ $REMOTE_CLEAN == 1 ]] && clean_modules $TARGET $REMOTE_LIST_CLEAN
+ [[ $REMOTE_BUILD == 1 ]] && generate_target $TARGET $REMOTE_LIST_BUILD
[[ $REMOTE_EXPORT == 1 ]] && export_builds
fi
}
@@ -273,6 +273,7 @@ REMOTE_AUTOMATIC_BUILD=0
initial_checks
read_params $@
+init_helpers
check_devtools
diff --git a/openslx b/openslx
index 6f683757..e4039dd3 100755
--- a/openslx
+++ b/openslx
@@ -28,21 +28,26 @@ qnd_exit() {
}
# source all helper unit files that are found under helper/*.inc
-# these are general and used by "mltk" and "openslx"
-for HELPER in "$ROOT_DIR"/helper/*.inc; do
- . "$HELPER" && continue
- unset_quiet
- echo "Could not source $HELPER"
- qnd_exit
-done
-
-# source specific units only used by openslx
-for HELPER in "$ROOT_DIR"/server/includes/*.inc; do
- . "$HELPER" && continue
+# or remote/includes/*.inc
+# a helper unit may contain a function called "__init" which will be called
+# after all helpers have been sourced.
+for HELPER in "$ROOT_DIR"/helper/*.inc "$ROOT_DIR"/server/includes/*.inc; do
+ SHORT=${HELPER%.inc}
+ SHORT="_init_${SHORT##*/}"
+ . <(sed "s/^__init/$SHORT/" "$HELPER") && continue
unset_quiet
echo "Could not source $HELPER"
qnd_exit
done
+# called below, after initial_checks
+init_helpers () {
+ # in case the helers have init functions, call them now
+ for HELPER in "$ROOT_DIR"/helper/*.inc "$ROOT_DIR"/server/includes/*.inc; do
+ SHORT=${HELPER%.inc}
+ SHORT="_init_${SHORT##*/}"
+ type -t "$SHORT" | grep -q '^function$' && "$SHORT"
+ done
+}
banner () {
@@ -134,7 +139,7 @@ check_devtools() {
initial_checks() {
if [ "x$(whoami)" != "xroot" ]; then
- perror "ERROR: You need to have root rights to install packages."
+ perror "ERROR: You need to have root rights for proper rsync/mksquashfs."
exit 1
else
banner
@@ -255,6 +260,7 @@ SERVER_CONFIG="0"
initial_checks || perror "initial_checks failed."
read_params $@ || perror "read_params failed."
+init_helpers
check_devtools || perror "check_devtools failed."
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"
-
diff --git a/server/blacklists/desktop-sessions/filter b/server/blacklists/desktop-sessions/filter
index 7fae71d0..2b35e80f 100644
--- a/server/blacklists/desktop-sessions/filter
+++ b/server/blacklists/desktop-sessions/filter
@@ -3,6 +3,7 @@
+ /usr/share/xsessions/xfce.desktop
+ /usr/share/xsessions/gnome.desktop
++ /usr/share/xsessions/deepin.desktop
+ /usr/share/xsessions/i3.desktop