summaryrefslogtreecommitdiffstats
path: root/openslx
diff options
context:
space:
mode:
authorSimon Rettberg2014-01-02 19:36:42 +0100
committerSimon Rettberg2014-01-02 19:36:42 +0100
commit61c9b1c97b1f5d07183987c2256637e523d1ff17 (patch)
tree5c5fa89bb09873edceae121c2222948083636972 /openslx
parent<setup_target> Add check for changed .build/.conf file of modules, autoclean ... (diff)
downloadtm-scripts-61c9b1c97b1f5d07183987c2256637e523d1ff17.tar.gz
tm-scripts-61c9b1c97b1f5d07183987c2256637e523d1ff17.tar.xz
tm-scripts-61c9b1c97b1f5d07183987c2256637e523d1ff17.zip
!! Split up 'mltk' into 'mltk' and 'openslx' !!
'mltk remote' is now 'mltk' 'mltk server' is now 'openslx' Also changed the export type (-e) stage31 to 'cpio' and stage32 and addons to 'sqfs' It should describe what it's packed as, not what the meaning of the content is; you can already tell from the file name.
Diffstat (limited to 'openslx')
-rwxr-xr-xopenslx255
1 files changed, 255 insertions, 0 deletions
diff --git a/openslx b/openslx
new file mode 100755
index 00000000..ca79800a
--- /dev/null
+++ b/openslx
@@ -0,0 +1,255 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+#
+# Copyright (c) 2011 - OpenSLX GmbH
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+#
+# OpenSLX server tool for packing up files from remote machines
+#
+# -----------------------------------------------------------------------------
+
+SELF="$(readlink -f $0)"
+ROOT_DIR="$(dirname "${SELF}")"
+OPENSLX_PID="$$"
+
+qnd_exit() {
+ unset_quiet
+ kill "$OPENSLX_PID"
+ [ $# -ge 1 ] && kill "$1"
+ exit 1
+}
+
+# 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
+ unset_quiet
+ echo "Could not source $HELPER"
+ qnd_exit
+done
+
+
+banner () {
+# (
+# ( )\ )
+# ( ` ) ))\ ( ( ((_)( /(
+# )\ /(/( /((_) )\ ) )\ _ )\())
+# ((_)((_)_\ (_)) _(_/( ((_)| |((_)\
+#/ _ \| '_ \)/ -_)| ' \))(_-<| |\ \ /
+#\___/| .__/ \___||_||_| /__/|_|/_\_\
+# |_|
+# Aus der Kategorie: Man kanns auch übertreiben
+ echo -e "\033[38;5;202m\t ( "
+ echo -e "\033[38;5;202m\t ( )\\ ) "
+ echo -e "\033[38;5;208m\t ( \` ) ))\\ ( ( ((_)( /( "
+ echo -e "\033[38;5;208m\t )\\ /(/( /((_) )\\ ) )\\ \033[38;5;220m_\033[38;5;208m )\\()) "
+ echo -e "\033[38;5;208m\t ((\033[38;5;220m_\033[38;5;208m)((\033[38;5;220m_\033[38;5;208m)\033[38;5;220m_\033[38;5;208m\\ (\033[38;5;220m_\033[38;5;208m)) \033[38;5;220m_\033[38;5;208m(\033[38;5;220m_\033[38;5;208m/( ((\033[38;5;220m_\033[38;5;208m)\033[38;5;220m| |\033[38;5;208m((\033[38;5;220m_\033[38;5;208m)\\ "
+ echo -e "\033[38;5;220m\t/ _ \\| '_ \\ \033[38;5;208m)\033[38;5;220m/ -_)| ' \\ \033[38;5;208m))\033[38;5;220m(_-<| |\\ \\ / "
+ echo -e "\033[38;5;226m\t\\___/| .__/ \\___||_||_| /__/|_|/_\\_\\ "
+ echo -e "\033[38;5;226m\t | | "
+ echo -e "\033[38;5;220m\t | | ** OpenSLX Project // 2013 **"
+ echo -e "\033[38;5;226m\t |_| http://lab.openslx.org/"
+ echo -e "\033[00m"
+}
+
+print_usage() {
+ echo -e ""
+ echo -e "Toolkit for packing mini linux generated by mltk"
+ echo -e "Usage: $(basename ${SELF}) <remotehost> [-s] [<target>] [-e cpio|sqfs] [-d] [-c] [-k config]"
+ echo -e ""
+ echo -e " Options:"
+ echo -e " -d activates debug output for the task"
+ echo -e " -e type export target as 'type'. can be 'cpio' (simple initramfs) or 'sqfs' (squashfs)"
+ echo -e " -s sync 'builds' from remote host"
+ echo -e " -c clean target in server/local_builds/ and corresponding files under boot/"
+ echo -e ""
+ echo -e " Examples:"
+ echo -e " server 1.2.3.4 -s"
+ echo -e " (sync all builds from remote system 1.2.3.4)"
+ echo -e " server 1.2.3.4 stage32 -e sqfs"
+ echo -e " (packs stage32 as squashfs from remote system 1.2.3.4)"
+ echo -e " server 1.2.3.4 stage31 -c"
+ echo -e " (clean stage31 build under server/local_builds and initramfs under server/boot)"
+ echo -e " server 1.2.3.4 addons-eexam -e sqfs -s"
+ echo -e " (pack eexam-addons as squashfs, sync from remote before packing)"
+ echo -e " server 1.2.3.4 -k <configname>"
+ echo -e " (generate config file server/boot/<remotehost>/configs/<configname>/config.tgz)"
+ echo -e ""
+ echo -e " NOTE: Use 'local' as the remote host if you're running on the same machine as mltk."
+ echo -e " (for testing only, not recommended for actual use)"
+ echo -e ""
+}
+
+
+check_devtools() {
+ # Checking for needed development tools.
+ local DEV_TOOLS="mksquashfs rsync"
+
+ # DEV_CHECK marks missing dev-tools
+ local DEV_TOOLS_MISSING=""
+ for i in $DEV_TOOLS; do
+ which "$i" 2>/dev/null 1>&2 || DEV_TOOLS_MISSING+="$i "
+ done
+
+ if [ -n "$DEV_TOOLS_MISSING" ]; then
+ pinfo "You appear to be missing following development tools."
+ pinfo "Missing tools are: $DEV_TOOLS_MISSING"
+ pinfo "For $SYS_DISTRIBUTION you probably need to run:"
+ case $SYS_DISTRIBUTION in
+ ubuntu | debian)
+ pinfo "apt-get install squashfs-tools rsync"
+ pinfo "to install missing development tools."
+ ;;
+ # FIXME: Don't know how precise this filter works so we might want to have a better matching ...
+ opensuse)
+ pinfo "zypper install squashfs rsync"
+ pinfo "to install missing development tools."
+ ;;
+ *)
+ perror "No help for $SYS_DISTRIBUTION available."
+ ;;
+ esac
+ perror "Please install missing dependencies (see above) and try again!"
+
+ fi
+}
+
+initial_checks() {
+ if [ "x$(whoami)" != "xroot" ]; then
+ perror "ERROR: You need to have root rights to install packages."
+ exit 1
+ else
+ banner
+ fi
+
+ # source the central script:
+ # export_target
+ # - pack given target as a cpio or squashfs depending on
+ # the export type:
+ # stage31 (cpio archive of the complete stage31-filesystem)
+ # stage32 (cpio archive containing the squashfs'ed stage32-filesystem)
+ SERVER_EXPORT_TARGET="${ROOT_DIR}/server/export_target"
+
+ [ ! -e "${SERVER_EXPORT_TARGET}" ] && perror "Missing script server/export_target. Exiting."
+ return 0
+}
+
+read_params() {
+ local SUBMODE=""
+
+ REMOTE_IP="$1"
+ shift
+
+ TARGET=""
+ if [[ $1 != -* ]]; then
+ TARGET="$1"
+ shift
+ elif [[ "$1" != "-s" && "$1" != "-k" ]]; then
+ perror "A target is required. None given."
+ fi
+
+ # handle rest of arguments
+ while [ "$#" -gt "0" ]; do
+ local PARAM="$1"
+ shift
+
+ # options to current target
+ if [[ "$PARAM" == "-"* ]]; then
+ case "$PARAM" in
+ -k)
+ # NOTE: check for validity of config is done in 'inital_checks' of server/export_target
+ SERVER_CONFIG_TYPE="$1"
+ SERVER_CONFIG="1"
+ shift
+ continue
+ ;;
+ -s)
+ [ "$REMOTE_IP" != "local" ] && SERVER_SYNC="1"
+ continue
+ ;;
+ -c)
+ SUBMODE="CLEAN"
+ ;;
+ -d)
+ eval SERVER_DEBUG="1"
+ continue
+ ;;
+ -e)
+ [ "$#" -lt "1" ] && perror "Missing argument to -e"
+ case "$1" in
+ cpio|stage31) # stage31 for compat
+ SERVER_EXPORT_TYPE="cpio"
+ ;;
+ sqfs|stage32|addons)
+ SERVER_EXPORT_TYPE="sqfs"
+ ;;
+ *)
+ perror "Wrong type specified. Must be either 'cpio' or 'sqfs'"
+ ;;
+ esac
+ SERVER_EXPORT="1"
+ shift
+ continue
+ ;;
+ *)
+ pwarning "Unknown flag to target: $PARAM"
+ print_usage
+ exit 1
+ ;;
+ esac
+ eval SERVER_${SUBMODE}="1"
+ continue
+ fi
+
+ pwarning "Unexpected '$PARAM'" && print_usage && exit 1
+ done
+
+ # exit if no command
+ [[ "$SERVER_CLEAN" == 0 && "$SERVER_EXPORT" == 0 && "$SERVER_SYNC" == 0 && "$SERVER_CONFIG" == 0 ]] && print_usage && exit 1
+ return 0
+}
+
+run() {
+ if [[ "$SERVER_CLEAN" == 1 || "$SERVER_EXPORT" == 1 || "$SERVER_SYNC" == 1 || "$SERVER_CONFIG" == 1 ]]; then
+ [[ "$SERVER_DEBUG" == 1 ]] && unset_quiet || set_quiet
+ . "${SERVER_EXPORT_TARGET}" || perror "Cannot source ${SERVER_EXPORT_TARGET}"
+ [[ "$SERVER_SYNC" == 1 ]] && sync_remote
+ [[ "$SERVER_CLEAN" == 1 ]] && clean_target "$TARGET"
+ [[ "$SERVER_EXPORT" == 1 ]] && export_target "$TARGET" "$SERVER_EXPORT_TYPE"
+ [[ "$SERVER_CONFIG" == 1 ]] && generate_config "$SERVER_CONFIG_TYPE"
+ pinfo "Exiting normally"
+ fi
+ return 0
+}
+
+SERVER_DEBUG="0"
+SERVER_EXPORT="0"
+SERVER_CLEAN="0"
+SERVER_EXPORT_TYPE=""
+SERVER_SYNC="0"
+SERVER_CONFIG="0"
+
+initial_checks || perror "initial_checks failed."
+read_params $@ || perror "read_params failed."
+
+check_devtools || perror "check_devtools failed."
+
+run || perror "run failed."
+exit 0
+