manjaro-tools/bin/buildtree.in

135 lines
2.8 KiB
Text
Raw Normal View History

2015-01-19 04:22:02 +01:00
#!/bin/bash
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
version=@version@
LIBDIR='@libdir@'
SYSCONFDIR='@sysconfdir@'
[[ -r ${LIBDIR}/util-msg.sh ]] && source ${LIBDIR}/util-msg.sh
[[ -r ${LIBDIR}/util.sh ]] && source ${LIBDIR}/util.sh
display_settings(){
msg "manjaro-tools"
msg2 "version: ${version}"
if [[ -f ${USER_CONFIG}/manjaro-tools.conf ]]; then
msg2 "user_config: ${USER_CONFIG}/manjaro-tools.conf"
else
msg2 "manjaro_tools_conf: ${manjaro_tools_conf}"
fi
2015-01-19 05:24:32 +01:00
2015-01-19 04:22:02 +01:00
msg "ARGS:"
msg2 "sync: ${sync}"
msg2 "abs: ${abs}"
2015-01-19 05:24:32 +01:00
msg2 "clean: ${clean}"
2015-01-19 04:22:02 +01:00
msg "PATHS:"
msg2 "tree_dir: ${tree_dir}"
msg2 "repo_tree: ${repo_tree[*]}"
msg2 "host_tree: ${host_tree}"
msg2 "host_tree_abs: ${host_tree_abs}"
}
prepare_dir(){
[[ ! -d $1 ]] && mkdir -p $1
}
sync_tree(){
2015-01-19 05:24:32 +01:00
cd ${tree_dir}
2015-01-19 04:22:02 +01:00
for repo in ${repo_tree[@]};do
2015-01-19 05:24:32 +01:00
if [[ -d packages-$repo ]];then
cd packages-$repo
msg "Syncing $repo ..."
git pull origin master
cd ..
else
msg "Cloning $repo ..."
git clone --depth 1 ${host_tree}/packages-$repo.git
fi
2015-01-19 04:22:02 +01:00
done
cd ..
2015-01-19 05:24:32 +01:00
}
sync_tree_abs(){
cd ${tree_dir}/abs
if [[ -d packages ]];then
cd packages
msg "Syncing abs ..."
git pull origin master
2015-01-19 04:22:02 +01:00
cd ..
2015-01-19 05:24:32 +01:00
else
msg "Cloning abs ..."
git clone --depth 1 ${host_tree_abs}.git
fi
cd ..
}
clean_tree_dir(){
if [[ -d ${tree_dir} ]]; then
msg "Cleaning ${tree_dir} ..."
rm -r ${tree_dir}/*
2015-01-19 04:22:02 +01:00
fi
}
load_user_info
2015-01-19 05:24:32 +01:00
load_config "${USER_CONFIG}/manjaro-tools.conf"
2015-01-19 04:22:02 +01:00
load_config "${SYSCONFDIR}/manjaro-tools.conf"
2015-01-19 05:24:32 +01:00
sync=false
2015-01-19 04:22:02 +01:00
pretend=false
abs=false
2015-01-19 05:24:32 +01:00
clean=false
2015-01-19 04:22:02 +01:00
usage() {
echo "Usage: ${0##*/} [options]"
echo " -s Sync tree"
echo " -a Include arch abs"
2015-01-19 05:24:32 +01:00
echo ' -c Clean package tree'
2015-01-19 04:22:02 +01:00
echo ' -q Query settings'
2015-01-19 05:24:32 +01:00
echo ' -h This help'
2015-01-19 04:22:02 +01:00
echo ''
echo ''
exit $1
}
orig_argv=("$@")
2015-01-19 05:24:32 +01:00
opts='sacqh'
2015-01-19 04:22:02 +01:00
while getopts "${opts}" arg; do
case "${arg}" in
2015-01-19 05:24:32 +01:00
s) sync=true ;;
2015-01-19 04:22:02 +01:00
a) abs=true ;;
2015-01-19 05:24:32 +01:00
c) clean=true ;;
2015-01-19 04:22:02 +01:00
q) pretend=true ;;
h|?) usage 0 ;;
*) echo "invalid argument '${arg}'"; usage 1 ;;
esac
done
shift $(($OPTIND - 1))
tree_dir=${cache_dir}/pkgtree
check_root "$0" "${orig_argv[@]}"
prepare_dir "${tree_dir}/abs"
${pretend} && display_settings && exit 1
2015-01-19 05:24:32 +01:00
${clean} && clean_tree_dir && exit 1
${sync} && sync_tree
${abs} && sync_tree_abs