aboutsummaryrefslogtreecommitdiff
path: root/stupid.sh
blob: f03e516583929671a2a8bc65b945aa7ad81b7e56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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