diff options
-rw-r--r-- | helper/README.helper | 2 | ||||
-rw-r--r-- | helper/downloader.inc | 42 | ||||
-rw-r--r-- | helper/functions.common.sh | 44 | ||||
-rw-r--r-- | helper/logging.inc | 57 | ||||
-rw-r--r-- | helper/useradd.inc | 68 | ||||
-rwxr-xr-x | mltk | 15 | ||||
-rwxr-xr-x | remote/setup_tools | 193 | ||||
-rw-r--r-- | remote/tools/policykit/policykit.build | 54 | ||||
-rw-r--r-- | remote/tools/systemd/systemd.build | 32 |
9 files changed, 293 insertions, 214 deletions
diff --git a/helper/README.helper b/helper/README.helper index e69de29b..ebe242a0 100644 --- a/helper/README.helper +++ b/helper/README.helper @@ -0,0 +1,2 @@ +Put your helper units here +Naming convention is <unitname>.inc diff --git a/helper/downloader.inc b/helper/downloader.inc new file mode 100644 index 00000000..7ded5b4f --- /dev/null +++ b/helper/downloader.inc @@ -0,0 +1,42 @@ +# helper functions for downloading files or packages + +# download a file. usage: +# download FROM [TO] +# 1. download "http://example.com/something.tar.gz" +# 2. download "http://example.com/something.tar.gz" "somename.tar.gz" +download () { + [ $# -lt 1 -o $# -gt 2 ] && perror "download called with $# arguments, need 1 or 2" + if [ $# -eq 2 ]; then + pinfo "Downloading $2 from '$1'...." + wget -O "$2" "$1" + local RET=$? + else + pinfo "Downloading '$1'...." + wget "$1" + local RET=$? + fi + [ "x$RET" != "x0" ] && perror "downloading $1 failed, wget returned exit code $RET" +} + +# download a file and untar it. usage: +# download_untar FROM TO_DIR [TEMPFILE] +# 1. download_untar "http://example.com/something.tar.gz" "src/" +# 2. download_untar "http://example.com/something.tar.gz" "src/" "temporary_name.tar.gz" +download_untar () { + [ $# -lt 2 -o $# -gt 3 ] && perror "download_untar called with $# arguments, need 2 or 3" + local URL=$1 + local DEST=$2 + if [ $# -eq 2 ]; then + local TMPFILE=dltmp.$(basename "$URL") + else + local TMPFILE=$3 + fi + download "$URL" "$TMPFILE" + mkdir -p "$DEST" + pinfo "Unpacking to '$DEST'..." + tar xf "$TMPFILE" -C "${DEST}/" + local RET=$? + [ "x$RET" != "x0" ] && perror "could not untar $TMPFILE to $DEST (tar returned $RET)" + unlink "$TMPFILE" +} + diff --git a/helper/functions.common.sh b/helper/functions.common.sh deleted file mode 100644 index de33363c..00000000 --- a/helper/functions.common.sh +++ /dev/null @@ -1,44 +0,0 @@ - -QUIET=0 - -LOG_DIR=${ROOT_DIR}/logs - -mkdir -p $LOG_DIR - -set_quiet () { - if [ "x$DEBUG" != "x1" -a "x$QUIET" != "x1" ]; then - exec 6>&1 > $LOG_DIR/stdout.log - exec 2> $LOG_DIR/stderr.log - QUIET="1" - fi -} - -unset_quiet () { - if [ "x$QUIET" = "x1" ]; then - exec 1>&6 6>&- - exec 2>&- - QUIET="0" - fi -} - - -pinfo () { - unset_quiet - echo -e "[info] $1" - set_quiet -} -perror () { - unset_quiet - echo -e "[error] $1" - set_quiet -} -pecho () { - unset_quiet - echo -e "[user] $1" - set_quiet -} -pechon () { - unset_quiet - echo -e -n "[user] $1" - set_quiet -} diff --git a/helper/logging.inc b/helper/logging.inc new file mode 100644 index 00000000..2667e5e5 --- /dev/null +++ b/helper/logging.inc @@ -0,0 +1,57 @@ + +MLTK_QUIET=0 + +LOG_DIR=${ROOT_DIR}/logs + +mkdir -p $LOG_DIR + +set_quiet () { + if [ "x$DEBUG" != "x1" -a "x$MLTK_QUIET" != "x1" ]; then + exec 6>&1 > $LOG_DIR/stdout.log + exec 7>&2 2> $LOG_DIR/stderr.log + MLTK_QUIET="1" + fi +} + +unset_quiet () { + if [ "x$MLTK_QUIET" = "x1" ]; then + exec 1>&6 6>&- + exec 2>&7 7>&- + MLTK_QUIET="0" + fi +} + + +pinfo () { + if [ "x$MLTK_QUIET" = "x1" ]; then + echo -e "\033[38;5;10m[info]\033[0m $TOOL_STR $@" >&6 + else + echo -e "\033[38;5;10m[info]\033[0m $TOOL_STR $@" + fi +} +perror () { + if [ "x$MLTK_QUIET" = "x1" ]; then + echo -e "\033[38;5;9m[error]\033[0m $TOOL_STR $@" >&6 + else + echo -e "\033[38;5;9m[error]\033[0m $TOOL_STR $@" + fi + qnd_exit +} +pwarning () { + if [ "x$MLTK_QUIET" = "x1" ]; then + echo -e "\033[38;5;11m[warning]\033[0m $TOOL_STR $@" >&6 + else + echo -e "\033[38;5;11m[warning]\033[0m $TOOL_STR $@" + fi +} + +pdebug () { + if [ "x$DEBUG" != "x1" ]; then + echo -e "[DEBUG] $TOOL_STR $@" + elif [ "x$MLTK_QUIET" = "x1" ]; then + echo -e "\033[38;5;6m[debug]\033[0m $TOOL_STR $@" >&6 + else + echo -e "\033[38;5;6m[debug]\033[0m $TOOL_STR $@" + fi +} + diff --git a/helper/useradd.inc b/helper/useradd.inc index 7d1f5909..720a847d 100644 --- a/helper/useradd.inc +++ b/helper/useradd.inc @@ -9,15 +9,15 @@ # 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 -. string.inc +. "${ROOT_DIR}/helper/string.inc" 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() { - [ $# -ne 1 ] && echo "generate_uid fail. want 1 argument." && exit 1 >&2 - [ -z "${_PASSWD}" ] && echo "passwd file not set." && exit 1 >&2 + [ $# -ne 1 ] && perror "generate_uid fail. want 1 argument." + [ -z "${_PASSWD}" ] && perror "passwd file not set." local _UID=$(grep -E "^$1:[^:]*:[0-9]+:" "${_PASSWD}" | head -1 | awk -F ':' '{print $3}') if [ "x${_UID}" = "x" ] then @@ -29,7 +29,7 @@ generate_uid() local _TEST=$(grep -E "^[^:]+:[^:]*:${_UID}:" "${_PASSWD}") [ "x${_TEST}" = "x" ] && break done - [ ${_TRIES} -ge 50 ] && echo "Generating a UID failed." && exit 1 >&2 + [ ${_TRIES} -ge 50 ] && perror "Generating a UID failed." fi echo ${_UID} } @@ -37,8 +37,8 @@ generate_uid() # Generate a UID for a given USERNAME. Return existing UID if possible, generate new one otherwise generate_gid() { - [ $# -ne 2 ] && echo "generate_gid fail. want 2 arguments." && exit 1 >&2 - [ -z "${_GROUP}" ] && echo "group file not set." && exit 1 >&2 + [ $# -ne 2 ] && perror "generate_gid fail. want 2 arguments." + [ -z "${_GROUP}" ] && perror "group file not set." local _GID=$(grep -E "^$1:[^:]*:[0-9]+:" "${_GROUP}" | head -1 | awk -F ':' '{print $3}') if [ "x${_GID}" = "x" ] then @@ -52,68 +52,73 @@ generate_gid() [ "x${_TEST}" = "x" ] && break _GID=$[ 5 + $RANDOM % 900 ] # using uid as gid not possible, generate new one done - [ ${_TRIES} -ge 50 ] && echo "Generating a GID failed." && exit 1 >&2 + [ ${_TRIES} -ge 50 ] && perror "Generating a GID failed." fi echo ${_GID} } add_user() { - [ -z "${INIT_DIR}" ] && echo "add_user: INIT_DIR not set" && exit 1 + [ -z "${INIT_DIR}" ] && perror "add_user: INIT_DIR not set" if [ -z $USER -a $# -eq 0 ] then - echo " ** add_user usage **" - echo "add_user <username>" - echo "OR" - echo "USER=<username> [GROUP=<groupname>] [USERID=<userid>] [GROUPID=<groupid>] [USERHOME=<homedir>] [USERSHELL=<shell>] [PASSWORD=<pass>] add_user" - exit 1 + pwarning " ** add_user usage **" + pwarning "add_user <username>" + pwarning "OR" + pwarning "USER=<username> [GROUP=<groupname>] [USERID=<userid>] [GROUPID=<groupid>] [USERHOME=<homedir>] [USERSHELL=<shell>] [PASSWORD=<pass>] add_user" + perror "Aborting, please fix your script." fi local _PASSWD=${INIT_DIR}/etc/passwd local _GROUP=${INIT_DIR}/etc/group local _SHADOW=${INIT_DIR}/etc/shadow - [ "x$USER" = "x" ] && local USER=$1 - USER=$(trim "$USER") - if ! [[ $USER =~ $NAME_REGEX ]] + if [ "x$1" != "x" ] then - echo "Invalid username: $USER" >&2 - exit 1 + local USER=$1 + local GROUP=$1 + local USERID="" + local GROUPID="" + local USERHOME="" + local USERSHELL="" + local PASSWORD="" + fi + USER=$(trim "$USER") + if ! [[ $USER =~ $NAME_REGEX ]]; then + perror "Invalid username: $USER" fi [ "x$GROUP" = "x" ] && local GROUP=$USER GROUP=$(trim "$GROUP") - if ! [[ $GROUP =~ $NAME_REGEX ]] - then - echo "Invalid group: $GROUP" >&2 - exit 1 + if ! [[ $GROUP =~ $NAME_REGEX ]]; then + perror "Invalid group: $GROUP" fi [ "x$USERID" = "x" ] && local USERID=$(generate_uid ${USER}) USERID=$(trim "$USERID") - [ "$USERID" -lt "1" -o "$USERID" -gt "65535" ] && echo "Invalid userid: $USERID" && exit 1 >&2 + [ "$USERID" -lt "1" -o "$USERID" -gt "65535" ] && perror "Invalid userid: $USERID" [ "x$GROUPID" = "x" ] && local GROUPID=$(generate_gid ${GROUP} ${USERID}) GROUPID=$(trim "$GROUPID") - [ "$GROUPID" -lt "1" -o "$GROUPID" -gt "65535" ] && echo "Invalid groupid: $GROUPID" && exit 1 >&2 + [ "$GROUPID" -lt "1" -o "$GROUPID" -gt "65535" ] && perror "Invalid groupid: $GROUPID" # all required variables have been set # does the desired username already exist? if so, check if UID matches, otherwise bail out local _UID=$(grep -E "^${USER}:[^:]*:[0-9]+:" "${_PASSWD}" | head -1 | awk -F ':' '{print $3}') - [ ! -z "${_UID}" ] && [ "x${_UID}" != "x${USERID}" ] && echo "User ${USER}(${USERID}) already exists with UID ${_UID}" && exit 1 >&2 + [ ! -z "${_UID}" ] && [ "x${_UID}" != "x${USERID}" ] && perror "User ${USER}(${USERID}) already exists with UID ${_UID}" # do the same for the group local _GID=$(grep -E "^${GROUP}:[^:]*:[0-9]+:" "${_GROUP}" | head -1 | awk -F ':' '{print $3}') - [ ! -z "${_GID}" ] && [ "x${_GID}" != "x${GROUPID}" ] && echo "Group ${GROUP}(${GROUPID}) already exists with GID ${_GID}" && exit 1 >&2 + [ ! -z "${_GID}" ] && [ "x${_GID}" != "x${GROUPID}" ] && perror "Group ${GROUP}(${GROUPID}) already exists with GID ${_GID}" # if user already exists, check if he is in another group than the one requested. if so, bail out # (TODO: don't bail out and add user to the new group) if [ ! -z "${_UID}" ] then - local _EXGID=$(grep -E "^${USER}:[^:]*:[0-9]+:" "${_PASSWD}" | head -1 | awk -F ':' '{print $3}') - [ "x${GROUPID}" != "x${_EXGID}" ] && echo "Requested GID $GROUPID differs from existing GID $_EXGID" && exit 1 >&2 + local _EXGID=$(grep -E "^${USER}:[^:]*:[0-9]+:" "${_PASSWD}" | head -1 | awk -F ':' '{print $4}') + [ "x${GROUPID}" != "x${_EXGID}" ] && perror "Requested GID $GROUPID differs from existing GID $_EXGID" fi # if user does not exist, try to add it if [ -z "${_UID}" ] then local _TEST=$(grep -E "^[^:]+:[^:]*:${USERID}:" "${_PASSWD}") - [ ! -z "${_TEST}" ] && echo "Cannot add $USER - desired UID $USERID already in use." && exit 1 >&2 + [ ! -z "${_TEST}" ] && perror "Cannot add $USER - desired UID $USERID already in use." fi if [ -z "${_GID}" ] then local _TEST=$(grep -E "^[^:]+:[^:]*:${GROUPID}:" "${_GROUP}") - [ ! -z "${_TEST}" ] && echo "Cannot add $GROUP - desired GID $GROUPID already in use." && exit 1 >&2 + [ ! -z "${_TEST}" ] && perror "Cannot add $GROUP - desired GID $GROUPID already in use." fi [ -z "${USERHOME}" ] && local USERHOME=/nonexistent [ -z "${USERSHELL}" ] && local USERSHELL=/bin/false @@ -125,12 +130,13 @@ add_user() { else PASSWORD=$(sha1pass "${PASSWORD}") [ -z "${PASSWORD}" ] && PASSWORD=$(openssl passwd -1 "${PASSWORD}") - [ -z "${PASSWORD}" ] && "Error generating hashed password for $USER" && exit 1 >&2 + [ -z "${PASSWORD}" ] && perror "Error generating hashed password for $USER" fi echo "${USER}:x:${USERID}:${GROUPID}:${USER}:${USERHOME}:${USERSHELL}" >> "${_PASSWD}" echo "${USER}:${PASSWORD}:15555:0:99999:7:::" >> "${_SHADOW}" fi [ -z "${_GID}" ] && echo "${GROUP}:x:${GROUPID}:" >> "${_GROUP}" echo "${USERID}" + exit 0 } @@ -18,9 +18,17 @@ SELF=$(readlink -f $0) ROOT_DIR=$(dirname ${SELF}) +MLTK_PID="$$" -. ${ROOT_DIR}/helper/functions.common.sh +qnd_exit() { + unset_quiet + kill "$MLTK_PID" + [ $# -ge 1 ] && kill "$1" +} + +. "${ROOT_DIR}/helper/logging.inc" . "${ROOT_DIR}/helper/useradd.inc" +. "${ROOT_DIR}/helper/downloader.inc" banner () { echo -e "\033[38;5;202m\t __ __ __ " @@ -115,12 +123,14 @@ read_params() { } run() { + [ "x$DEBUG" != "x1" ] && set_quiet if [ $TARGET_TOOLS ]; then . ${SETUP_TOOLS} [ $CLEAN ] && clean_tools $TOOLS [ $BUILD ] && generate_stage32 $TOOLS fi if [ $TARGET_CORE ]; then + unset_quiet # TODO: Make build_core logging.inc aware . ${BUILD_CORE} [ $CLEAN ] && clean_core [ $BUILD ] && generate_stage31 @@ -130,7 +140,4 @@ run() { initial_checks read_params $@ -#exec 6>&1 > stdout.log -#exec 2> stderr.log - run diff --git a/remote/setup_tools b/remote/setup_tools index aaa7a23b..76f163f5 100755 --- a/remote/setup_tools +++ b/remote/setup_tools @@ -8,40 +8,35 @@ INIT_DIR=${MODULE_DIR}/stage3.2 initial_checks () { - for BIN in $(which git) $(which locate) + for BIN in git locate do - [ -z $BIN ] && echo "Installing $BIN..." && apt-get install $BIN + local TEST=$(which ${BIN}) + [ -z "$TEST" ] && pinfo "Installing $BIN..." && apt-get install $BIN done } read_config () { - TOOL_CONFIG=${TOOL_DIR}/${TOOL}/${TOOL}.conf + local TOOL_CONFIG=${TOOL_DIR}/${TOOL}/${TOOL}.conf - if [ ! -e ${TOOL_CONFIG} ]; then - echo "ERROR: Config for specified tool not found." - exit 1 - fi + [ ! -e ${TOOL_CONFIG} ] && perror "Config for '$TOOL' not found." . ${TOOL_CONFIG} } read_build () { - BUILD_SCRIPT=${TOOL_DIR}/${TOOL}/${TOOL}.build + local BUILD_SCRIPT=${TOOL_DIR}/${TOOL}/${TOOL}.build - if [ ! -e ${BUILD_SCRIPT} ]; then - echo "ERROR: Build script for specified tool not found." - exit 1 - fi + [ ! -e ${BUILD_SCRIPT} ] && perror "Build script for specified tool not found." . ${BUILD_SCRIPT} } copyfileswithdependencies () { - [ ! -d build ] && echo "No build directory for ${TOOL} found." && return + [ ! -d build ] && pinfo "No build directory found, skipping dependency copying" && return 0 cd build @@ -49,21 +44,16 @@ copyfileswithdependencies () [ -e ${COPYFILES_LIST} ] && rm ${COPYFILES_LIST} - echo -e "\n\n*********************************************************" - echo "*" - echo "* Copying required binaries from config file..." - echo "*" - echo -e "*********************************************************\n\n" + [ ! -z "${REQUIRED_BINARIES}" ] && pinfo "Gathering required binaries from config file..." for FILENAME in ${REQUIRED_BINARIES} do - FILE=$(find . -name ${FILENAME} -type f -executable | xargs grep -l ELF) + FILE=$(find . -name ${FILENAME} -type f -executable | xargs grep -l '^.ELF') # FIXME: What happens on multiple matches? Maybe add " | head -1" if [ -z "$FILE" ]; then - echo -e "\tNo Binary found for ${FILENAME}. Skipping." - echo "-----------------------------------------------------------------" + pwarning "\tNo Binary found for ${FILENAME}. Skipping." continue fi - echo -e "\tFound ${FILENAME} at ${FILE}" - echo ${FILE} >> ${COPYFILES_LIST} + pdebug "\tFound ${FILENAME} at ${FILE}" + echo "${FILE}" >> "${COPYFILES_LIST}" # fetch dependencies # quick fix to exclude libc*, else it copies unneeded libs... # workaround for @@ -71,104 +61,100 @@ copyfileswithdependencies () ldd_exit_code=$? if [ "x$ldd_exit_code" != "x0" ]; then - echo -e "\tldd $FILE failed." + pdebug "\tldd $FILE failed." continue fi - for i in $(ldd ${FILE} |awk '{print $1 $2 $3}'|grep -v ld-linux|grep -v libc.so*|grep -v linux-gate|grep -v linux-vdso) + for i in $(ldd "${FILE}" | awk '{print $1 $2 $3}' | grep -v ld-linux | grep -v libc.so | grep -v linux-gate | grep -v linux-vdso) do arrIN=(${i//=>/ }) - echo -en "\t\t${arrIN[0]}" - LOCAL_MATCHES=$(find . -name $(echo ${arrIN[0]}|awk -F "." '{print $1}').so*) + pdebug "* ${arrIN[0]}" + LOCAL_MATCHES=$(find . -name "$(echo ${arrIN[0]} | awk -F '.' '{print $1}')".so\*) if [ "x${LOCAL_MATCHES}" != "x" ]; then for llib in ${LOCAL_MATCHES}; do - echo -ne " ->${llib}" - echo ${llib} >> ${COPYFILES_LIST} + pdebug " at ${llib}" + echo ${llib} >> "${COPYFILES_LIST}" done - echo "" else if [ -e ${arrIN[1]} ]; then - echo ${arrIN[1]} >> ${COPYFILES_LIST} + echo ${arrIN[1]} >> "${COPYFILES_LIST}" if [ ! -L ${arrIN[1]} ]; then - echo -e " -> ${arrIN[1]}" + pdebug " at ${arrIN[1]}" else - echo -e " -> ${arrIN[1]} -> $(readlink -f ${arrIN[1]})" + pdebug " at ${arrIN[1]} -> $(readlink -f ${arrIN[1]})" echo $(readlink -f ${arrIN[1]}) >> ${COPYFILES_LIST} fi fi fi done - echo -e "\t-------------------------------------------------------------------------------------------------------------" done + [ ! -z "${REQUIRED_LIBRARIES}" ] && pinfo "Gathering required libraries from config file..." for LIB in ${REQUIRED_LIBRARIES} do for LOCATION in $(find . -name ${LIB}*) do + pdebug "* $LOCATION" echo ${LOCATION} >> ${COPYFILES_LIST} done done - echo -e "\n\n*********************************************************" - echo "*" - echo "* Copying required directories from config file..." - echo "*" - echo -e "*********************************************************\n\n" + [ ! -z "${REQUIRED_DIRECTORIES}" ] && pinfo "Gathering required directories from config file..." + local CURRENT_PWD=$(pwd) # Prevent calling pwd 50000 times inside the loop below for ENTRY in ${REQUIRED_DIRECTORIES} do - echo ".${ENTRY}" >> ${COPYFILES_LIST} - for BIN in $(find .${ENTRY} -type f -not -name "*.a" | xargs grep -l ELF) - do - echo -e "\tSearching libs for ${BIN}..." - for i in $(ldd ${BIN} |awk '{print $1 $2 $3}'|grep -v ld-linux|grep -v libc.so*|grep -v linux-gate|grep -v linux-vdso) + pdebug "* ./$ENTRY" + echo "./${ENTRY}" >> "${COPYFILES_LIST}" + for BIN in $(find "./${ENTRY}" -type f -not -name '*.a' | xargs grep -l '^.ELF') + do + pdebug " Searching libs for ${BIN}..." + for i in $(ldd ${BIN} | awk '{print $1 $2 $3}' | grep -v ld-linux | grep -v libc.so | grep -v linux-gate | grep -v linux-vdso) do arrIN=(${i//=>/ }) - echo -e "\t\t---------------------------------------------------------" - echo -ne "\t\tSearching ${arrIN[0]} under $(pwd)..." - LOCAL_MATCHES=$(find . -name $(echo ${arrIN[0]}|awk -F "." '{print $1}').so*) + pdebug " Searching for ${arrIN[0]}...($i)" + local LOCAL_MATCHES=$(find . -name "$(echo ${arrIN[0]} | awk -F '.' '{print $1}')".so\*) if [ "x${LOCAL_MATCHES}" != "x" ]; then for llib in ${LOCAL_MATCHES}; do - echo -en "\n\t\tCopying ${llib}" - echo ${llib} >> ${COPYFILES_LIST} + pdebug " Found locally, copying ${llib}" + echo ${llib} >> "${COPYFILES_LIST}" done - echo "" else - echo " not found." - if [ ! -z ${arrIN[1]} ]; + if [ ! -z ${arrIN[1]} ] && [ "x${arrIN[1]}" != "xnot" ]; then - echo -e "\t\tCopying from system ${arrIN[1]} ..." - echo ${arrIN[1]} >> ${COPYFILES_LIST} - [ -L ${arrIN[1]} ] && echo $(readlink -f ${arrIN[1]}) >> ${COPYFILES_LIST} + pdebug " Not found locally but in system, copying ${arrIN[1]}" + echo ${arrIN[1]} >> "${COPYFILES_LIST}" + [ -L ${arrIN[1]} ] && echo $(readlink -f "${arrIN[1]}") >> "${COPYFILES_LIST}" + else + pwarning "Lib '${arrIN[0]}' from required dir '$ENTRY' neither found in build directory nor on this system." + pwarning "If this lib is not supplied by another module, this module will probably fail in your final system" fi fi done - echo -e "\tCopied $BIN" - echo -e "\t-------------------------------------------------------------------------------------------------------------" done - echo -e "\t Copied directory $ENTRY" done - echo "*********************************************************" - echo "*" - echo "* Copying required files from config file..." - echo "*" - echo "*********************************************************" + [ ! -z "${REQUIRED_FILES}" ] && pinfo "Gathering required files from config file..." for ENTRY in ${REQUIRED_FILES} do - echo ".${ENTRY}" >> ${COPYFILES_LIST} - echo -e "\t Copied file $ENTRY" + echo "./${ENTRY}" >> "${COPYFILES_LIST}" done #copy to initramfsdir - echo "[stage32] Completed file list generation at ${TOOL_DIR}/${TOOL}/build/${COPYFILES_LIST}." - (tar -cpv $(cat ${COPYFILES_LIST}|sort -u) | tar -xpv -C ${INIT_DIR}) &>/dev/null + pdebug "[stage32] Completed file list generation at ${TOOL_DIR}/${TOOL}/build/${COPYFILES_LIST}." + if [ -s "$COPYFILES_LIST" ]; then + local CLISTCOUNT=$(cat "$COPYFILES_LIST" | wc -l) + pinfo "Copying $CLISTCOUNT files to stage 3.2 target directory." + tar -cp $(cat ${COPYFILES_LIST}|sort -u) | tar -xp -C "${INIT_DIR}" + local RET=$? + [ "x$RET" != "x0" ] && perror "Could not tar-copy to $INIT_DIR" + fi unset REQUIRED_BINARIES unset REQUIRED_LIBRARIES unset REQUIRED_DIRECTORIES @@ -180,17 +166,19 @@ get_basic_libs () { [ ! -d ${INIT_DIR} ] && mkdir ${INIT_DIR} # copy libc and ld-linux separatly - echo "----------------------------------------------------" + pinfo "Adding basic libs" BASICLIBS="" for i in $(ldd ${SHELL}) do if [ $(echo $i | grep '^/' | grep -c ld) -eq 1 -o $(echo $i | grep '^/' | grep -c libc.so) -eq 1 ]; then - echo "Copied $i" + pdebug "Adding $i" BASICLIBS="${BASICLIBS} $i $(readlink -f "$i")" fi done - (tar -cpv ${BASICLIBS} | tar -xpv -C ${INIT_DIR}) &>/dev/null + tar -cp ${BASICLIBS} | tar -xp -C ${INIT_DIR} + local RET=$? + [ "x$RET" != "x0" ] && perror "Could not tar-copy to $INIT_DIR" } generate_stage32 () { @@ -211,32 +199,40 @@ generate_stage32 () { TOOL=$1 if [ -d ${TOOL} ]; then - echo "###################################################################################" - echo "# BUILDING $TOOL" - echo "#" + TOOL_STR="[${TOOL}]" + pinfo "## ## Processing module ## ##" - [ "x$DEBUG" != "x1" ] \ - && echo "Logging to ${TOOL_DIR}/${TOOL}/stage32.log" \ - && exec 6>&1 > ${TOOL_DIR}/${TOOL}/stage32.log - cd ${TOOL} + #[ "x$DEBUG" != "x1" ] \ + # && echo "Logging to ${TOOL_DIR}/${TOOL}/stage32.log" \ + # && exec 6>&1 > ${TOOL_DIR}/${TOOL}/stage32.log + # TODO: Make above work with the new logging system (add function to logging.inc to switch logfile) + cd "${TOOL}" + pinfo "## Reading config" read_config - read_build + pinfo "## Reading build" + read_build + pinfo "## Installing dependencies" install_dependencies + pinfo "## Fetching source" fetch_source + pinfo "## Building" build # remove *.la files as they might confuse libtool/linker of other tool packages find "${TOOL_DIR}/${TOOL}/build" -name '*.la' -exec rm -f {} \; + pinfo "## Copying files with dependencies" copyfileswithdependencies + pinfo "## Post copy" post_copy cd ${TOOL_DIR} # reset pipes - [ "x$DEBUG" != "x1" ] && exec 1>&6 6>&- - echo "#" - echo "# DONE" - echo "###################################################################################" + #[ "x$DEBUG" != "x1" ] && exec 1>&6 6>&- + # TODO + pinfo "## ## Module completed ## ##" + TOOL_STR="" else - echo "Tool directory not found." + perror "Tool directory for '$TOOL' not found." + # maybe make this a warning instead of error? fi shift done @@ -245,8 +241,11 @@ generate_stage32 () { clean_tools() { if [ "x$1" = "x" -o "x$1" = "xall" ]; then #clean all - [ -d ${INIT_DIR} ] && echo -n "Cleaning ${INIT_DIR}..." \ - && rm -rf ${INIT_DIR} && echo " done." + if [ -d ${INIT_DIR} ]; then + pinfo "Cleaning ${INIT_DIR}..." + rm -rf "${INIT_DIR}" || perror "Error deleting $INIT_DIR" + pinfo "done." + fi for TOOL in $(ls ${TOOL_DIR}); do clean_tool $TOOL done @@ -260,17 +259,27 @@ clean_tools() { clean_tool() { TOOLDIR=${TOOL_DIR}/$1 - echo -n "Cleaning ${TOOLDIR}..." + pinfo "Cleaning ${TOOLDIR}..." #[ -e ${TOOLDIR}/build/list_wanted_stage3.2 ] && cd ${INIT_DIR} \ # && xargs rm < ${TOOLDIR}/build/list_wanted_stage3.2 #[ -d ${TOOLDIR}/data ] && cd ${INIT_DIR} \ # && xargs rm < $(find ${TOOLDIR}/data -type f) - [ -e ${TOOLDIR}/.built ] && rm ${TOOLDIR}/.built - [ -e ${TOOLDIR}/.fetched_source ] && rm ${TOOLDIR}/.fetched_source - [ -d ${TOOLDIR}/build ] && rm -rf ${TOOLDIR}/build - [ -d ${TOOLDIR}/src ] && rm -rf ${TOOLDIR}/src - [ -e ${TOOLDIR}/list_binaries_and_files ] && rm ${TOOLDIR}/list_binaries_and_files - echo " done." + if [ -e ${TOOLDIR}/.built ]; then + rm "${TOOLDIR}/.built" || perror "Could not clear built flag" + fi + if [ -e ${TOOLDIR}/.fetched_source ]; then + rm "${TOOLDIR}/.fetched_source" || perror "Could not clear fetched_source flag" + fi + if [ -d ${TOOLDIR}/build ]; then + rm -rf "${TOOLDIR}/build" || perror "Could not delete build path" + fi + if [ -d ${TOOLDIR}/src ]; then + rm -rf "${TOOLDIR}/src" || perror "Could not delete src path" + fi + if [ -e ${TOOLDIR}/list_binaries_and_files ]; then + rm "${TOOLDIR}/list_binaries_and_files" || perror "Could not delete list_binaries_and_files" + fi + pinfo "done." } #generate_stage32 $@ diff --git a/remote/tools/policykit/policykit.build b/remote/tools/policykit/policykit.build index db216f22..871025a1 100644 --- a/remote/tools/policykit/policykit.build +++ b/remote/tools/policykit/policykit.build @@ -2,13 +2,8 @@ fetch_source () { - if [ ! -e .fetched_source ]; then - [ ! -d src ] && mkdir src - wget $URL - tar xfz $VERSION.tar.gz -C src/ - rm $VERSION.tar.gz - touch .fetched_source - fi + [ ! -e .fetched_source ] && download_untar "$URL" "src/" + touch .fetched_source } install_dependencies() { @@ -21,32 +16,41 @@ build () { if [ ! -e .built ]; then cd src/$VERSION - [ ! -d ${TOOL_DIR}/systemd/build ] && echo "[$TOOL] systemd build directory not found Build it first. Exiting." && exit 1 - - export LIBSYSTEMD_LOGIN_LIBS="-L${TOOL_DIR}/systemd/build/usr/lib/" - export LIBSYSTEMD_LOGIN_CFLAGS="-I${TOOL_DIR}/systemd/build/usr/include -I${TOOL_DIR}/systemd/build/usr/include/systemd -lsystemd-login -lsystemd-daemon" - ./configure --enable-libsystemd-login=yes --with-systemdsystemunitdir=/etc/systemd/system -prefix="/" --datarootdir="/usr/share" - - make - [ ! -d $BUILDDIR ] && mkdir -p $BUILDDIR - DESTDIR=$BUILDDIR make install + [ ! -d "${TOOL_DIR}/systemd/build" ] && perror "systemd build directory not found. Build it first." + pinfo "configuring..." + LIBSYSTEMD_LOGIN_LIBS="-L${TOOL_DIR}/systemd/build/usr/lib/" \ + LIBSYSTEMD_LOGIN_CFLAGS="-I${TOOL_DIR}/systemd/build/usr/include -I${TOOL_DIR}/systemd/build/usr/include/systemd -lsystemd-login -lsystemd-daemon" \ + ./configure --enable-libsystemd-login=yes --with-systemdsystemunitdir=/etc/systemd/system -prefix="/" --datarootdir="/usr/share" --enable-man-pages=no --enable-gtk-doc-html=no --enable-examples=no --enable-static=no + pinfo "calling make..." + make || perror "make failed." + [ ! -d "$BUILDDIR" ] && mkdir -p "$BUILDDIR" + pinfo "installing to $BUILDDIR..." + DESTDIR="$BUILDDIR" make install || perror "make install failed..." COPYLIST="list_dpkg_output" - [ -e $COPYLIST ] && rm $COPYLIST + [ -e "$COPYLIST" ] && rm "$COPYLIST" + touch "$COPYLIST" + pinfo "determining required packages..." if [ ! -z ${REQUIRED_PACKAGES} ] then - for PACKAGE in ${REQUIRED_PACKAGES} + for PACKAGE in ${REQUIRED_PACKAGES} do for FILE in $(dpkg -L ${PACKAGE} | grep -v share/doc | grep -v share/man) do - [ ! -d $FILE ] && echo $FILE >> $COPYLIST + [ ! -d $FILE ] && echo $FILE >> "$COPYLIST" done done # prepare target dir & copy there - [ ! -d $BUILDDIR ] && mkdir -p $BUILDDIR - tar -cpv $(cat $COPYLIST|sort -u) | tar -xpv -C $BUILDDIR + if [ -s "$COPYLIST" ]; then + pinfo "using tar to copy all dependencies to $BUILDDIR" + tar -cpv $(cat $COPYLIST|sort -u) | tar -xpv -C $BUILDDIR + local RET=$? + [ $RET -ne 0 ] && perror "copy failed." + else + pinfo "no dependencies found!" + fi fi cd - @@ -58,11 +62,7 @@ build () { post_copy() { #Add Polkit User/Group/Shadow to Stage3.2 - local RET=$(add_user polkitd) - if ! [[ $RET ~= [0-9]+ ]] - then - echo "USERADD FAILED: $RET" 1>&2 - exit 1 - fi + pinfo "Adding polkitd user to target system..." + add_user "polkitd" } diff --git a/remote/tools/systemd/systemd.build b/remote/tools/systemd/systemd.build index c5a9a86c..7d9588c0 100644 --- a/remote/tools/systemd/systemd.build +++ b/remote/tools/systemd/systemd.build @@ -1,13 +1,8 @@ #tool/distro specific functions for fetching, building and installing dependencies fetch_source () { - if [ ! -e .fetched_source ]; then - [ ! -d src ] && mkdir src - wget $URL - tar xJf $VERSION.tar.xz -C src/ - rm $VERSION.tar.xz - touch .fetched_source - fi + [ ! -e .fetched_source ] && download_untar "$URL" "src/" + touch .fetched_source } install_dependencies() { @@ -20,6 +15,7 @@ install_dependencies() { # apt-get update --force-yes #fi # install libkmod from source + # TODO: Use download_untar local libkmodversion=kmod-12 if [ ! -d $libkmodversion ]; then wget http://www.kernel.org/pub/linux/utils/kernel/kmod/${libkmodversion}.tar.gz @@ -32,24 +28,27 @@ install_dependencies() { cd - fi - apt-get install -y $DEPS &>/dev/null + apt-get install -y $DEPS } build () { if [ ! -e .built ]; then - cd src/$VERSION - ./configure --disable-manpages --enable-split-usr --sysconfdir="/etc" - make -j5 - [ ! -d $TOOL_DIR/$TOOL/build ] && mkdir -p $TOOL_DIR/$TOOL/build - DESTDIR=$TOOL_DIR/$TOOL/build make install + cd "src/$VERSION/" + pinfo "calling configure" + ./configure --disable-manpages --enable-split-usr --sysconfdir="/etc" --enable-gtk-doc-html=no || perror "configure failed." + pinfo "calling make" + make -j5 || perror "make failed." + mkdir -p $TOOL_DIR/$TOOL/build + pinfo "calling make install" + DESTDIR=$TOOL_DIR/$TOOL/build make install || perror "make install failed." cd - - touch .built + touch .built fi } post_copy() { # copy static data files - cp -r $TOOL_DIR/$TOOL/data/* $INIT_DIR + cp -r $TOOL_DIR/$TOOL/data/* $INIT_DIR || perror "copying data files failed." # dont clear systemd log at startup sed -i.bak "s/TTYVTDisallocate=yes/TTYVTDisallocate=no/g" $INIT_DIR/usr/lib/systemd/system/getty@.service @@ -61,5 +60,6 @@ post_copy() { fi # add nfs to modules-load list - echo "nfs" > $INIT_DIR/etc/modules-load.d/nfs.conf + echo "nfs" > "$INIT_DIR/etc/modules-load.d/nfs.conf" } + |