some code cleanup

This commit is contained in:
artoo 2014-11-16 23:18:01 +01:00
parent 352aed0dde
commit c005b20a58
4 changed files with 109 additions and 109 deletions

View file

@ -17,6 +17,70 @@ shopt -s nullglob
[[ -r @libdir@/util.sh ]] && source @libdir@/util.sh [[ -r @libdir@/util.sh ]] && source @libdir@/util.sh
[[ -r @libdir@/util-build.sh ]] && source @libdir@/util-build.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(){ chroot_create(){
mkdir -p "${chrootdir}" mkdir -p "${chrootdir}"
setarch "${arch}" mkchroot \ setarch "${arch}" mkchroot \
@ -69,48 +133,6 @@ chroot_init(){
fi 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 export LC_MESSAGES=C
load_config '@sysconfdir@' load_config '@sysconfdir@'
@ -129,6 +151,7 @@ load_vars /etc/makepkg.conf
arch=$(uname -m) arch=$(uname -m)
pacman_conf_arch='default' pacman_conf_arch='default'
base_packages=('base-devel')
clean_first=false clean_first=false
wipe_clean=false wipe_clean=false
@ -137,12 +160,6 @@ pretend=false
is_profile=false is_profile=false
sign=false sign=false
base_packages=('base-devel')
mkchroot_args=()
mkchrootpkg_args=()
makepkg_args=()
usage() { usage() {
echo "Usage: ${0##*/} [options] [--] [makepkg args]" echo "Usage: ${0##*/} [options] [--] [makepkg args]"
echo " -p <profile> Set profile or pkg [default: ${profile}]" echo " -p <profile> Set profile or pkg [default: ${profile}]"
@ -205,13 +222,12 @@ check_root "$0" "${orig_argv[@]}"
eval_profile "${profile}" eval_profile "${profile}"
if ${pretend}; then ${pretend} && display_settings && exit
display_settings
exit $? ${wipe_clean} && clean_up
else
${wipe_clean} && clean_up chroot_init
display_settings
chroot_init chroot_build
chroot_build
${sign} && sign_pkgs "${pkg_owner}" ${sign} && sign_pkgs "${pkg_owner}"
fi

View file

@ -46,20 +46,6 @@ show_set(){
done 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 query=false
create=false create=false
remove=false remove=false
@ -71,7 +57,7 @@ usage() {
echo " -c <name> Create set" echo " -c <name> Create set"
echo " -r <name> Remove set" echo " -r <name> Remove set"
echo " -d <name> Display set" echo " -d <name> Display set"
echo " -q Query sets" echo " -q Show sets"
echo ' -h This help' echo ' -h This help'
echo '' echo ''
echo '' echo ''
@ -96,4 +82,12 @@ shift $(($OPTIND - 1))
check_root "$0" "${orig_argv[@]}" 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

View file

@ -26,58 +26,34 @@ move_pkg(){
chown -R "$1:users" "${pkgdir}" 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(){ clean_up(){
msg "Cleaning up ..." msg "Cleaning up ..."
local query=$(find ${pkgdir} -maxdepth 1 -name "*.*") local query=$(find ${pkgdir} -maxdepth 1 -name "*.*")
if [[ -n $query ]];then
rm -v $query [[ -n $query ]] && rm -v $query
fi
if [[ -z $LOGDEST ]];then if [[ -z $LOGDEST ]];then
query=$(find $(pwd) -maxdepth 2 -name '*.log') query=$(find $(pwd) -maxdepth 2 -name '*.log')
if [[ -n $query ]];then [[ -n $query ]] && rm -v $query
rm -v $query
fi
fi fi
if [[ -z $SRCDEST ]];then if [[ -z $SRCDEST ]];then
query=$(find $(pwd) -maxdepth 2 -name '*.?z?') query=$(find $(pwd) -maxdepth 2 -name '*.?z?')
if [[ -n $query ]];then [[ -n $query ]] && rm -v $query
rm -v $query
fi
fi fi
} }
eval_profile(){
eval "case $1 in
$(get_profiles)) is_profile=true ;;
*) is_profile=false ;;
esac"
}
blacklist_pkg(){ 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 if [[ -n $cmd ]] ; then
msg2 "Removing blacklisted [${blacklist[@]}] ..." chroot-run $1/root pacman -Rdd "${blacklist[@]}" --noconfirm
pacman -Rdd "${blacklist[@]}" -r $1/root --noconfirm
else
msg2 "Blacklisted [${blacklist[@]}] not present."
fi fi
} }
chroot_clean(){ chroot_clean(){
for copy in "$1"/*; do for copy in "$1"/*; do
[[ -d ${copy} ]] || continue [[ -d ${copy} ]] || continue

View file

@ -195,4 +195,18 @@ load_config(){
else else
pkgdir='/var/cache/manjaro-tools/pkg' pkgdir='/var/cache/manjaro-tools/pkg'
fi 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)"
} }