manjaro-tools/bin/mkset.in
udeved 3b7a3cbe80 small fixes;
add sanity check for pkg or profile dir
2015-01-15 18:15:24 +01:00

120 lines
2.5 KiB
Bash

#!/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@
SYSCONFDIR='@sysconfdir@'
[[ -r @libdir@/util-msg.sh ]] && source @libdir@/util-msg.sh
[[ -r @libdir@/util.sh ]] && source @libdir@/util.sh
load_user_info
load_config "${USER_CONFIG}/manjaro-tools.conf"
load_config "${SYSCONFDIR}/manjaro-tools.conf"
write_set(){
msg2 "Adding ${1##*/}"
echo ${1##*/} >> ${2}/${name}.set || break
}
write_set_iso(){
}
create_set(){
msg "Creating [$1/${name}.set] ..."
if [[ -f $1/${name}.set ]];then
msg2 "Backing up $1/${name}.set.orig"
mv "$1/${name}.set" "$1/${name}.set.orig"
fi
local list=$(find * -maxdepth 0 -type d | sort)
for item in ${list[@]};do
cd $item
if ${iso_mode}; then
if [[ -f displaymanager ]] && [[ -f initsys ]];then
write_set "$item" "${sets_dir_iso}"
fi
else
if [[ -f PKGBUILD ]];then
write_set "$item" "${sets_dir_pkg}"
fi
fi
cd ..
done
}
remove_set(){
msg "Removing [$1/${name}.set] ..."
rm $1/${name}.set
}
show_set(){
local list=$(cat $1/${name}.set)
msg "Content of [$1/${name}.set] ..."
for item in ${list[@]}; do
msg2 "$item"
done
}
query=false
create=false
remove=false
display=false
name='default'
iso_mode=false
usage() {
echo "Usage: ${0##*/} [options]"
echo " -c <name> Create set"
echo " -r <name> Remove set"
echo " -d <name> Display set"
echo " -i Iso mode"
echo " -q Query sets"
echo ' -h This help'
echo ''
echo ''
exit $1
}
orig_argv=("$@")
opts='c:r:d:qh'
while getopts "${opts}" arg; do
case "${arg}" in
c) name="$OPTARG"; create=true ;;
r) name="$OPTARG"; remove=true ;;
q) query=true ;;
i) iso_mode=true ;;
d) name="$OPTARG"; display=true;;
h|?) usage 0 ;;
*) echo "invalid argument '${arg}'"; usage 1 ;;
esac
done
shift $(($OPTIND - 1))
sets_dir_pkg="${sets_dir}/pkg"
sets_dir_iso="${sets_dir}/iso"
check_root "$0" "${orig_argv[@]}"
if ${create};then
create_set
elif ${remove};then
remove_set
elif ${display};then
show_set
else
msg "Available sets: $(load_sets ${sets_dir_pkg})"
fi