manjaro-tools/bin/make-set.in

94 lines
2.1 KiB
Text
Raw Normal View History

2014-10-07 01:16:29 +02:00
#!/bin/bash
2014-10-08 11:11:19 +02:00
#
# 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.
2014-10-07 01:16:29 +02:00
2014-10-08 13:14:28 +02:00
version=@version@
2014-11-13 16:31:15 +01:00
[[ -r @libdir@/util-msg.sh ]] && source @libdir@/util-msg.sh
[[ -r @libdir@/util.sh ]] && source @libdir@/util.sh
2014-10-07 01:16:29 +02:00
2014-12-07 06:36:46 +01:00
load_config '@sysconfdir@' '@pkgdatadir@'
2014-10-07 01:16:29 +02:00
2014-11-11 21:19:26 +01:00
create_set(){
msg "Creating [${profiledir}/${name}.set] ..."
if [[ -f ${profiledir}/${name}.set ]];then
msg2 "Backing up ${profiledir}/${name}.set.orig"
mv "${profiledir}/${name}.set" "${profiledir}/${name}.set.orig"
fi
local list=$(find * -maxdepth 0 -type d | sort)
for item in ${list[@]};do
cd $item
if [[ -f PKGBUILD ]];then
msg2 "Adding ${item##*/}"
echo ${item##*/} >> ${profiledir}/${name}.set || break
fi
cd ..
done
}
remove_set(){
msg "Removing [${profiledir}/${name}.set] ..."
rm ${profiledir}/${name}.set
}
show_set(){
local list=$(cat ${profiledir}/${name}.set)
msg "Content of [${profiledir}/${name}.set] ..."
for item in ${list[@]}; do
msg2 "$item"
done
}
2014-10-07 10:34:33 +02:00
query=false
2014-10-07 17:27:39 +02:00
create=false
remove=false
2014-10-07 23:06:20 +02:00
display=false
2014-10-07 01:16:29 +02:00
name='default'
usage() {
echo "Usage: ${0##*/} [options]"
2014-10-07 10:34:33 +02:00
echo " -c <name> Create set"
2014-10-07 17:27:39 +02:00
echo " -r <name> Remove set"
2014-10-07 23:06:20 +02:00
echo " -d <name> Display set"
2014-11-16 23:18:01 +01:00
echo " -q Show sets"
2014-10-07 10:34:33 +02:00
echo ' -h This help'
2014-10-07 01:16:29 +02:00
echo ''
echo ''
exit 1
}
orig_argv=("$@")
2014-10-07 23:06:20 +02:00
opts='c:r:d:qh'
2014-10-07 01:16:29 +02:00
while getopts "${opts}" arg; do
case "${arg}" in
2014-10-07 17:27:39 +02:00
c) name="$OPTARG"; create=true ;;
r) name="$OPTARG"; remove=true ;;
2014-10-07 10:34:33 +02:00
q) query=true ;;
2014-10-07 23:06:20 +02:00
d) name="$OPTARG"; display=true;;
2014-10-07 01:16:29 +02:00
h) usage ;;
esac
done
2014-10-07 17:27:39 +02:00
shift $(($OPTIND - 1))
2014-10-07 10:34:33 +02:00
check_root "$0" "${orig_argv[@]}"
2014-10-07 10:34:33 +02:00
2014-11-16 23:18:01 +01:00
if ${create};then
create_set
elif ${remove};then
remove_set
elif ${display};then
show_set
else
msg "Available sets: $(load_sets)"
fi