From d003662f4e1e12d012e9f4a6dec23641ac5e4beb Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 23 May 2022 11:36:40 +0300 Subject: Added current implementation progress of stupid --- stupid.sh | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 stupid.sh (limited to 'stupid.sh') 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] No package file!"; shift; continue + fi + ( + source "$pkg" + if [[ $(type -t stupidInstall) != "function" ]]; then + echo "[$1] No install function found!"; exit + fi + if [[ $(type -t stupidRemove) != "function" ]]; then + echo "[$1] No remove function found (required even when installing)!"; exit + fi + + echo "[$1] 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] Installed!" + ) + if (( $? != 0 )); then + echo "[$1] 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] No package file!"; shift; continue + fi + ( + source "$pkg" + if [[ $(type -t stupidRemove) != "function" ]]; then + echo "[$1] No remove function found!"; exit + fi + + echo "[$1] 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] Installed!" + ) + if (( $? != 0 )); then + echo "[$1] 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 -- cgit v1.2.3