summaryrefslogtreecommitdiffstats
path: root/mltk
diff options
context:
space:
mode:
authorSimon Rettberg2014-07-27 00:10:16 +0200
committerSimon Rettberg2014-07-27 00:10:16 +0200
commit62d78729a32dd136feddede21a5dc6e9c3dbe2d7 (patch)
treedccd7c833bb33825c45922397dd84d629d25f05f /mltk
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
Diffstat (limited to 'mltk')
-rwxr-xr-xmltk51
1 files changed, 26 insertions, 25 deletions
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