aboutsummaryrefslogtreecommitdiff
path: root/stupid.sh
diff options
context:
space:
mode:
Diffstat (limited to 'stupid.sh')
-rwxr-xr-xstupid.sh94
1 files 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]<Info> 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 "| <Warn > Package has already been installed! It will be reinstalled!"
- read -p "L <Warn > Do you want to continue? [y/N]: " confirm && ! [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] && exit
+ echo " <W> 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 "| <Warn > Another version of the package ($otherPkg) has been found! It will be removed and $1 will be installed!"
- read -p "L <Warn > Do you want to continue? [y/N]: " confirm && ! [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] && exit
+ echo " <W> 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]<Info> 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 <Info> Installed!"
+ if [ "$2" = '1' ]; then
+ echo " <$(date +'%H:%M:%S')> Installed $1!"
+ else
+ echo " <$(date +'%H:%M:%S')> Installed $1!"
+ fi
}
function installFail {
- echo "| <Error> Could not install! Log:"
+ if [ "$2" = '1' ]; then
+ echo " <E> Could not install! Log:"
+ else
+ echo " <E> Could not install! Log:"
+ fi
cat "/tmp/stupid/$name/$1.install-log"
}
function removeRoutine {
- echo "[$1]<Info> 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 <Warning> Package isn't installed!" && exit
+ echo " <W> Package isn't installed!" && exit
fi
- echo "[$1]<Info> 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 <Info> 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]<Error> Could not remove! Log:"
+ if [ "$2" = '1' ]; then
+ echo " <E> Could not remove! Log:"
+ else
+ echo " <E> 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]<Error> No package file!"; shift; continue
+ echo "<E> 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]<Error> Package file name and package name and/or version do not match!"; exit
+ if [ "$1--$version" != "$name--$version" ] && [ "$1" != "$name--$version" ]; then
+ echo "<E> Package file name and package name and/or version do not match for $1!"; exit
fi
- if [[ $(type -t stupidInstall) != "function" ]]; then
- echo "[$1]<Error> No install function found!"; exit
+ if [ $(type -t stupidInstall) != "function" ]; then
+ echo "<E> No install function found for $1!"; exit
fi
- if [[ $(type -t stupidRemove) != "function" ]]; then
- echo "[$1]<Error> No remove function found!"; exit
+ if [ "$(type -t stupidRemove)" != "function" ]; then
+ echo "<E> 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 "<I> 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 "<Error> Invalid command \"$1\"!" && exit 1
;;
esac
shift