From 8404838dd6e744bd5f84f0c3d5db1abc7ee891d6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 5 Jun 2022 11:48:30 +0300 Subject: Reworked user interface and started work on update --- stupid.sh | 94 +++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 30 deletions(-) diff --git a/stupid.sh b/stupid.sh index b1be337..bfdf4a5 100755 --- a/stupid.sh +++ b/stupid.sh @@ -3,82 +3,99 @@ STUPID_DIR=$(pwd) function installRoutine { - echo "[$1] Running checks for $1 ..." + if [ "$2" = '1' ]; then + echo " <$(date +'%H:%M:%S')> Installing $1 ..." + else + echo "<$(date +'%H:%M:%S')> Installing $1 ..." + fi if grep -q "$1" 'installed.stupid-log'; then - echo "| Package has already been installed! It will be reinstalled!" - read -p "L Do you want to continue? [y/N]: " confirm && ! [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] && exit + echo " Package has already been installed! It will be reinstalled!" + read -p " Do you want to continue? [y/N]: " confirm && ! [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] && exit - removeRoutine $1 + removeRoutine $1 '1' elif grep -q "$name" 'installed.stupid-log'; then otherPkg=$(grep "$name--*" 'installed.stupid-log') - echo "| Another version of the package ($otherPkg) has been found! It will be removed and $1 will be installed!" - read -p "L Do you want to continue? [y/N]: " confirm && ! [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] && exit + echo " Another version of the package has been found! $otherPkg will be removed and $1 will be installed!" + read -p " Do you want to continue? [y/N]: " confirm && ! [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] && exit - removeRoutine $otherPkg + removeRoutine $otherPkg '1' fi - echo "[$1] Installing $1 ..." - mkdir -p "/tmp/stupid/$name" && cd "/tmp/stupid/$name"; touch "$1.install-log" - stupidInstall >"$1.install-log" 2>&1 || (installFail $1 && exit) + stupidInstall >"$1.install-log" 2>&1 || (installFail $1 $2 && exit) echo "FINISHED" >> "$1.install-log"; echo "$1" >> "$STUPID_DIR/installed.stupid-log" - echo "L Installed!" + if [ "$2" = '1' ]; then + echo " <$(date +'%H:%M:%S')> Installed $1!" + else + echo " <$(date +'%H:%M:%S')> Installed $1!" + fi } function installFail { - echo "| Could not install! Log:" + if [ "$2" = '1' ]; then + echo " Could not install! Log:" + else + echo " Could not install! Log:" + fi cat "/tmp/stupid/$name/$1.install-log" } function removeRoutine { - echo "[$1] Running checks for $1 ..." + if [ "$2" = '1' ]; then + echo " <$(date +'%H:%M:%S')> Removing $1 ..." + else + echo "<$(date +'%H:%M:%S')> Removing $1 ..." + fi if ! grep -q "$1" 'installed.stupid-log'; then - echo "L Package isn't installed!" && exit + echo " Package isn't installed!" && exit fi - echo "[$1] Removing $1 ..." - mkdir -p "/tmp/stupid/$name" && cd "/tmp/stupid/$name"; touch "$1.remove-log" - stupidRemove >"$1.remove-log" 2>&1 || (removeFail $1 && exit) + stupidRemove >"$1.remove-log" 2>&1 || (removeFail $1 $2 && exit) grep -qv "$1" "$STUPID_DIR/installed.stupid-log" > "$STUPID_DIR/installed.stupid-log" - echo "L Removed!" + if [ "$2" = '1' ]; then + echo " <$(date +'%H:%M:%S')> Removed $1!" + else + echo " <$(date +'%H:%M:%S')> Removed $1!" + fi } function removeFail { - echo "[$1] Could not remove! Log:" + if [ "$2" = '1' ]; then + echo " Could not remove! Log:" + else + echo " Could not remove! Log:" + fi cat "/tmp/stupid/$name/$1.remove-log" } - function handlePackages { routine=$1 shift; shift while [ ! -z $1 ]; do - echo '' - # Package names can either be "PACKAGENAME" or "PACKAGENAME--VERSION" # If it's "PACKAGENAME" we only want the last occurence, since alphanumerically this should be the latest version 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 + echo " No package file for $1!"; shift; continue fi # Ran in subshell so the source-ing doesn't persist between routine functions of multiple packages ( source "$pkg" - if [[ "$1--$version" != "$name--$version" ]] && [[ "$1" != "$name--$version" ]]; then - echo "[$1] Package file name and package name and/or version do not match!"; exit + if [ "$1--$version" != "$name--$version" ] && [ "$1" != "$name--$version" ]; then + echo " Package file name and package name and/or version do not match for $1!"; exit fi - if [[ $(type -t stupidInstall) != "function" ]]; then - echo "[$1] No install function found!"; exit + if [ $(type -t stupidInstall) != "function" ]; then + echo " No install function found for $1!"; exit fi - if [[ $(type -t stupidRemove) != "function" ]]; then - echo "[$1] No remove function found!"; exit + if [ "$(type -t stupidRemove)" != "function" ]; then + echo " No remove function found for $1!"; exit fi $routine "$name--$version" @@ -87,6 +104,20 @@ function handlePackages { done } +function updateAll { + while read p; do + pkg=$(find . -type f -name "$(egrep -o '^[^--]+' <<< $p)--*.stupid" | tail -n 1) + if [ "$p.stupid" != "$pkg" ] && ! [ -z "$p" ]; then + echo " Updating $p ..." + ( + source "$pkg" + removeRoutine $p + installRoutine "$name--$version" + ) + fi + done < 'installed.stupid-log' +} + while [ ! -z $1 ]; do case $1 in -i|install) @@ -95,11 +126,14 @@ while [ ! -z $1 ]; do -r|remove) handlePackages removeRoutine $@ ; exit ;; + -u|update) + updateAll ; exit + ;; -q|query) echo 'Not implemented yet!' ; exit ;; *) - echo "[Error] Invalid command \"$1\"!" && exit 1 + echo " Invalid command \"$1\"!" && exit 1 ;; esac shift -- cgit v1.2.3