diff options
Diffstat (limited to 'stupid.sh')
| -rwxr-xr-x | stupid.sh | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/stupid.sh b/stupid.sh new file mode 100755 index 0000000..f03e516 --- /dev/null +++ b/stupid.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +quietInstall='no' + +function installPackages { + shift + while [ ! -z $1 ]; do + pkg=$(find . -type f -name "$1--*.stupid" | tail -n 1 || grep -q '--' && find . -type f -name "$1.stupid") + if [ -z $pkg ]; then + echo "[$1]<Error> No package file!"; shift; continue + fi + ( + source "$pkg" + if [[ $(type -t stupidInstall) != "function" ]]; then + echo "[$1]<Error> No install function found!"; exit + fi + if [[ $(type -t stupidRemove) != "function" ]]; then + echo "[$1]<Error> No remove function found (required even when installing)!"; exit + fi + + echo "[$1]<Info > Installing $title $version ..." + + mkdir -p "/tmp/stupid/$1"; cd "/tmp/stupid/$1" + touch "$pkg.install-log" + stupidInstall >"$pkg.install-log" 2>&1 + echo "FINISHED" >> "$pkg.install-log" + + echo "[$1]<Info > Installed!" + ) + if (( $? != 0 )); then + echo "[$1]<Error> Could not install! Log:" + cat "/tmp/stupid/$1/$pkg.install-log" + fi + shift + done +} + +function removePackages { + shift + while [ ! -z $1 ]; do + pkg=$(find . -type f -name "$1--*.stupid" | tail -n 1 || grep -q '--' && find . -type f -name "$1.stupid") + if [ -z $pkg ]; then + echo "[$1]<Error> No package file!"; shift; continue + fi + ( + source "$pkg" + if [[ $(type -t stupidRemove) != "function" ]]; then + echo "[$1]<Error> No remove function found!"; exit + fi + + echo "[$1]<Info > Removing $title $version ..." + + mkdir -p "/tmp/stupid/$1"; cd "/tmp/stupid/$1" + touch "$pkg.remove-log" + stupidRemove >"$pkg.remove-log" 2>&1 + echo "FINISHED" >> "$pkg.remove-log" + + echo "[$1]<Info > Installed!" + ) + if (( $? != 0 )); then + echo "[$1]<Error> Could not remove! Log:" + cat "/tmp/stupid/$1/$pkg.remove-log" + fi + shift + done +} + +while [ ! -z $1 ]; do + case $1 in + -q|quiet) + quietInstall='yes' + ;; + -i|install) + installPackages $@ + exit + ;; + -r|remove) + removePackages $@ + exit + ;; + *) + echo '[Error] Invalid command!' + ;; + esac + shift +done |
