manjaro-tools/bin/make-set.in
2014-10-07 17:27:39 +02:00

82 lines
1.6 KiB
Bash

#!/bin/bash
if [[ -r @libdir@/functions.sh ]];then
source @libdir@/functions.sh
fi
manjaro_tools_conf='@sysconfdir@/manjaro-tools.conf'
if [[ -f ${manjaro_tools_conf} ]]; then
. ${manjaro_tools_conf}
fi
if [[ -n ${profiledir} ]];then
profiledir=${profiledir}
else
profiledir='@sysconfdir@/sets'
fi
profiles=$(get_profiles)
query=false
create=false
remove=false
name='default'
create_set(){
msg "Creating [${profiledir}/${name}.set] ..."
local list=$(find * -maxdepth 0 -type d | sort)
if [[ -f ${profiledir}/${name}.set ]];then
msg2 "Backing up ${profiledir}/${name}.set.orig"
mv "${profiledir}/${name}.set" "${profiledir}/${name}.set.orig"
fi
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
}
usage() {
echo "Usage: ${0##*/} [options]"
echo " -c <name> Create set"
echo " -r <name> Remove set"
echo " -q Query sets"
echo ' -h This help'
echo ''
echo ''
exit 1
}
opts='c:r:qh'
while getopts "${opts}" arg; do
case "${arg}" in
c) name="$OPTARG"; create=true ;;
r) name="$OPTARG"; remove=true ;;
q) query=true ;;
h) usage ;;
esac
done
shift $(($OPTIND - 1))
if [[ $EUID != 0 ]]; then
die 'This script must be run as root.'
fi
if ${create};then
create_set
elif ${remove};then
remove_set
else
msg "Sets: ${profiles}"
exit 1
fi