#!/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 create_set_pkg(){ msg "[${sets_dir_pkg}/${name}.set]" if [[ -f ${sets_dir_pkg}/${name}.set ]];then msg3 "Backing up ${sets_dir_pkg}/${name}.set.orig" mv "${sets_dir_pkg}/${name}.set" "${sets_dir_pkg}/${name}.set.orig" fi local list=$(find * -maxdepth 0 -type d | sort) for item in ${list[@]};do if [[ -f $item/PKGBUILD ]];then cd $item msg2 "Adding ${item##*/}" echo ${item##*/} >> ${sets_dir_pkg}/${name}.set || break cd .. fi done } create_set_iso(){ msg "[${sets_dir_iso}/${name}.set]" if [[ -f ${sets_dir_iso}/${name}.set ]];then msg3 "Backing up ${sets_dir_iso}/${name}.set.orig" mv "${sets_dir_iso}/${name}.set" "${sets_dir_iso}/${name}.set.orig" fi local list=$(find * -maxdepth 0 -type d | sort) for item in ${list[@]};do if [[ -f $item/initsys ]];then cd $item msg2 "Adding ${item##*/}" echo ${item##*/} >> ${sets_dir_iso}/${name}.set || break cd .. fi done } remove_set(){ if [[ -f $1/${name}.set ]]; then msg "Removing [$1/${name}.set] ..." rm $1/${name}.set fi } show_set(){ local list=$(cat $1/${name}.set) msg "Content of [$1/${name}.set] ..." for item in ${list[@]}; do msg2 "$item" done } load_user_info load_config "${USER_CONFIG}/manjaro-tools.conf" load_config "${SYSCONFDIR}/manjaro-tools.conf" query=false create=false remove=false show=false iso_mode=false name='default' usage() { echo "Usage: ${0##*/} [options]" echo " -c Create set" echo " -r Remove set" echo " -s Show set" echo " -i Iso mode" echo " -q Query sets" echo ' -h This help' echo '' echo '' exit $1 } orig_argv=("$@") opts='c:r:s:qih' while getopts "${opts}" arg; do case "${arg}" in c) name="$OPTARG"; create=true ;; r) name="$OPTARG"; remove=true ;; s) name="$OPTARG"; show=true;; i) iso_mode=true ;; q) query=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 if ${iso_mode}; then create_set_iso else create_set_pkg fi elif ${remove};then if ${iso_mode}; then remove_set "${sets_dir_iso}" else remove_set "${sets_dir_pkg}" fi elif ${show};then if ${iso_mode}; then show_set "${sets_dir_iso}" else show_set "${sets_dir_pkg}" fi else if ${iso_mode}; then msg "Available sets: $(load_sets ${sets_dir_iso})" else msg "Available sets: $(load_sets ${sets_dir_pkg})" fi fi