From c005b20a58c62f30e4016fabfee7a935871843c4 Mon Sep 17 00:00:00 2001 From: artoo Date: Sun, 16 Nov 2014 23:18:01 +0100 Subject: [PATCH] some code cleanup --- bin/build-set.in | 132 ++++++++++++++++++++++++++-------------------- bin/make-set.in | 26 ++++----- lib/util-build.sh | 46 ++++------------ lib/util.sh | 14 +++++ 4 files changed, 109 insertions(+), 109 deletions(-) diff --git a/bin/build-set.in b/bin/build-set.in index 1b3b2b1..9b50a12 100644 --- a/bin/build-set.in +++ b/bin/build-set.in @@ -17,6 +17,70 @@ shopt -s nullglob [[ -r @libdir@/util.sh ]] && source @libdir@/util.sh [[ -r @libdir@/util-build.sh ]] && source @libdir@/util-build.sh +display_settings(){ + msg "manjaro-tools version: ${version}" + + msg "OPTIONS:" + msg2 "arch: ${arch}" + msg2 "branch: ${branch}" + msg2 "chroots: ${chroots}" + + msg "ARGS:" + msg2 "mkchrootpkg_args: ${mkchrootpkg_args[*]}" + msg2 "makepkg_args: ${makepkg_args[*]}" + + msg "PATHS:" + msg2 "chrootdir: ${chrootdir}" + msg2 "profiledir: ${profiledir}" + msg2 "pkgdir: ${pkgdir}" + msg2 "pacman_conf: ${pacman_conf}" + msg2 "makepkg_conf: ${makepkg_conf}" + msg2 "pm_conf: ${pm_conf}" + + if ${clean_first};then + msg "PKG:" + msg2 "base_packages: ${base_packages[*]}" + fi + + msg "SETS:" + msg2 "profiles: $(get_profiles)" + msg2 "profile: ${profile}" + msg2 "is_profile: ${is_profile}" + + if ${is_profile};then + msg "Build queue:" + local list=$(cat ${profiledir}/${profile}.set) + for item in ${list[@]}; do + msg2 "$item" + done + else + msg "Build queue:" + for arg in "${makepkg_args[@]}"; do + case ${arg} in + --pkg) continue ;; + -*) continue ;; + *) local split_arg=${arg} ;; + esac + done + if [[ -n ${split_arg} ]]; then + local IFS=',' + for item in ${split_arg}; do + msg2 "$item" + done + unset IFS + else + msg2 "${profile}" + fi + fi +} + +eval_profile(){ + eval "case $1 in + $(load_sets)) is_profile=true ;; + *) is_profile=false ;; + esac" +} + chroot_create(){ mkdir -p "${chrootdir}" setarch "${arch}" mkchroot \ @@ -69,48 +133,6 @@ chroot_init(){ fi } -display_settings(){ - msg "manjaro-tools version: ${version}" - - msg "OPTIONS:" - msg2 "arch: ${arch}" - msg2 "branch: ${branch}" - msg2 "chroots: ${chroots}" - - msg "ARGS:" - msg2 "mkchrootpkg_args: ${mkchrootpkg_args[*]}" - msg2 "makepkg_args: ${makepkg_args[*]}" - - msg "PATHS:" - msg2 "chrootdir: ${chrootdir}" - msg2 "profiledir: ${profiledir}" - msg2 "pkgdir: ${pkgdir}" - msg2 "pacman_conf: ${pacman_conf}" - msg2 "makepkg_conf: ${makepkg_conf}" - msg2 "pm_conf: ${pm_conf}" - - if ${clean_first};then - msg "PKG:" - msg2 "base_packages: ${base_packages[*]}" - fi - - msg "SETS:" - msg2 "profiles: $(get_profiles)" - msg2 "profile: ${profile}" - msg2 "is_profile: ${is_profile}" - - if ${is_profile};then - msg "Build queue:" - local list=$(cat ${profiledir}/${profile}.set) - for item in ${list[@]}; do - msg2 "$item" - done - else - msg "Build queue:" - msg2 "${profile}" - fi -} - export LC_MESSAGES=C load_config '@sysconfdir@' @@ -129,6 +151,7 @@ load_vars /etc/makepkg.conf arch=$(uname -m) pacman_conf_arch='default' +base_packages=('base-devel') clean_first=false wipe_clean=false @@ -137,12 +160,6 @@ pretend=false is_profile=false sign=false -base_packages=('base-devel') - -mkchroot_args=() -mkchrootpkg_args=() -makepkg_args=() - usage() { echo "Usage: ${0##*/} [options] [--] [makepkg args]" echo " -p Set profile or pkg [default: ${profile}]" @@ -205,13 +222,12 @@ check_root "$0" "${orig_argv[@]}" eval_profile "${profile}" -if ${pretend}; then - display_settings - exit $? -else - ${wipe_clean} && clean_up - display_settings - chroot_init - chroot_build - ${sign} && sign_pkgs "${pkg_owner}" -fi +${pretend} && display_settings && exit + +${wipe_clean} && clean_up + +chroot_init + +chroot_build + +${sign} && sign_pkgs "${pkg_owner}" diff --git a/bin/make-set.in b/bin/make-set.in index 8bbb60f..b1077cf 100644 --- a/bin/make-set.in +++ b/bin/make-set.in @@ -46,20 +46,6 @@ show_set(){ done } -run(){ - if ${create};then - create_set - elif ${remove};then - remove_set - elif ${display};then - show_set - else - msg "Available sets: ${profiles}" - exit 1 - fi -} - -profiles=$(get_profiles) query=false create=false remove=false @@ -71,7 +57,7 @@ usage() { echo " -c Create set" echo " -r Remove set" echo " -d Display set" - echo " -q Query sets" + echo " -q Show sets" echo ' -h This help' echo '' echo '' @@ -96,4 +82,12 @@ shift $(($OPTIND - 1)) check_root "$0" "${orig_argv[@]}" -run $@ +if ${create};then + create_set +elif ${remove};then + remove_set +elif ${display};then + show_set +else + msg "Available sets: $(load_sets)" +fi diff --git a/lib/util-build.sh b/lib/util-build.sh index 207b798..03a9087 100644 --- a/lib/util-build.sh +++ b/lib/util-build.sh @@ -26,58 +26,34 @@ move_pkg(){ chown -R "$1:users" "${pkgdir}" } -get_profiles(){ - local prof= temp= - for item in $(ls ${profiledir}/*.set);do - temp=${item##*/} - prof=${prof:-}${prof:+|}${temp%.set} - done - echo $prof -} - -prepare_dir(){ - mkdir -p $1 - chown -R "$2:users" "$(dirname $1)" -} - clean_up(){ msg "Cleaning up ..." + local query=$(find ${pkgdir} -maxdepth 1 -name "*.*") - if [[ -n $query ]];then - rm -v $query - fi + + [[ -n $query ]] && rm -v $query + if [[ -z $LOGDEST ]];then query=$(find $(pwd) -maxdepth 2 -name '*.log') - if [[ -n $query ]];then - rm -v $query - fi + [[ -n $query ]] && rm -v $query fi + if [[ -z $SRCDEST ]];then query=$(find $(pwd) -maxdepth 2 -name '*.?z?') - if [[ -n $query ]];then - rm -v $query - fi + [[ -n $query ]] && rm -v $query fi } -eval_profile(){ - eval "case $1 in - $(get_profiles)) is_profile=true ;; - *) is_profile=false ;; - esac" -} blacklist_pkg(){ - local blacklist=('libsystemd') cmd=$(pacman -Q ${blacklist[@]} -r $1/root 2> /dev/null) + local blacklist=('libsystemd') \ + cmd=$(pacman -Q ${blacklist[@]} -r $1/root 2> /dev/null) + if [[ -n $cmd ]] ; then - msg2 "Removing blacklisted [${blacklist[@]}] ..." - pacman -Rdd "${blacklist[@]}" -r $1/root --noconfirm - else - msg2 "Blacklisted [${blacklist[@]}] not present." + chroot-run $1/root pacman -Rdd "${blacklist[@]}" --noconfirm fi } - chroot_clean(){ for copy in "$1"/*; do [[ -d ${copy} ]] || continue diff --git a/lib/util.sh b/lib/util.sh index a0b1adc..5789421 100644 --- a/lib/util.sh +++ b/lib/util.sh @@ -195,4 +195,18 @@ load_config(){ else pkgdir='/var/cache/manjaro-tools/pkg' fi +} + +load_sets(){ + local prof= temp= + for item in $(ls ${profiledir}/*.set);do + temp=${item##*/} + prof=${prof:-}${prof:+|}${temp%.set} + done + echo $prof +} + +prepare_dir(){ + mkdir -p $1 + chown -R "$2:users" "$(dirname $1)" } \ No newline at end of file