fix: stuff
This commit is contained in:
parent
dd70dd0ad4
commit
ba52a96a60
8 changed files with 39 additions and 121 deletions
80
dot
80
dot
|
@ -3,7 +3,7 @@
|
|||
ask=0
|
||||
|
||||
is_function() {
|
||||
type "$1" 2> /dev/null | sed "s/$1//" | grep -qwi function
|
||||
type "$1" 2>/dev/null | sed "s/$1//" | grep -qwi function
|
||||
}
|
||||
|
||||
curr_distro() {
|
||||
|
@ -23,22 +23,7 @@ func() {
|
|||
[ "$(id -u)" = "0" ] && sh -c "$ecmd" || sudo sh -c "$ecmd"
|
||||
unset ecmd
|
||||
fi
|
||||
is_function $2 && $2
|
||||
}
|
||||
|
||||
get_command() {
|
||||
case $1 in
|
||||
a*)
|
||||
printf "apply"
|
||||
;;
|
||||
u*)
|
||||
printf "undo"
|
||||
;;
|
||||
*)
|
||||
echo "err: not supported" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
is_function $2 && $2
|
||||
}
|
||||
|
||||
# only run this *in crate dir*
|
||||
|
@ -51,25 +36,25 @@ run_crate() {
|
|||
if [ $enabled -ne 1 ]; then
|
||||
return
|
||||
fi
|
||||
cmd=$(get_command $1)
|
||||
cmd=$1
|
||||
scripts=${scripts:-"@self @distro"}
|
||||
for s in $scripts; do
|
||||
for s in $scripts; do
|
||||
echo "exec($(basename $PWD)): $s/$cmd"
|
||||
case $s in
|
||||
@self)
|
||||
func ./crate.sh $cmd
|
||||
@self)
|
||||
func ./crate.sh $cmd
|
||||
;;
|
||||
@distro)
|
||||
unset -f super_$cmd
|
||||
unset -f $cmd
|
||||
include ./crate.$(curr_distro).sh
|
||||
func ./crate.$(curr_distro).sh $cmd
|
||||
unset -f super_$cmd
|
||||
unset -f $cmd
|
||||
include ./crate.sh
|
||||
@distro)
|
||||
unset -f super_$cmd
|
||||
unset -f $cmd
|
||||
include ./crate.$(curr_distro).sh
|
||||
func ./crate.$(curr_distro).sh $cmd
|
||||
unset -f super_$cmd
|
||||
unset -f $cmd
|
||||
include ./crate.sh
|
||||
;;
|
||||
*)
|
||||
sh $s
|
||||
*)
|
||||
sh $s
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
@ -80,18 +65,25 @@ echo "# user: $USER (${UID:-$(id -u)})"
|
|||
echo "# groups: $(groups)"
|
||||
echo "# distro: $(curr_distro)"
|
||||
|
||||
if [ $# -eq 2 ]; then
|
||||
[ -d crates/*$1 ] || exit 1
|
||||
cd crates/*$1
|
||||
run_crate $2
|
||||
cd ../..
|
||||
else
|
||||
[ $# -eq 0 ] && exit 2
|
||||
for crate in $(find ./crates -mindepth 1 -maxdepth 1 -type d | sort); do
|
||||
cd $crate
|
||||
run_crate $1
|
||||
cd ../..
|
||||
done
|
||||
cmd=$1
|
||||
if [ -z "$cmd" ]; then
|
||||
echo "usage: $0 <command> [...args]"
|
||||
exit 1
|
||||
else
|
||||
shift
|
||||
fi
|
||||
|
||||
|
||||
for c in ${@:-$(ls crates)}; do
|
||||
[ -d crates/*$c ] || exit 1
|
||||
cd crates/*$c
|
||||
case $cmd in
|
||||
a | apply)
|
||||
run_crate apply
|
||||
;;
|
||||
u | undo)
|
||||
run_crate undo
|
||||
;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
cd ../..
|
||||
done
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue