pm

A pack manager
git clone git://iotek.org/pm
Log | Files | Refs | README

pm (1908B)


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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh

ROOT=/var/pm

#
# the directory structure should be as;
# /var/pm
#  |___ repo
#         |___ name.of.server
#         (contains list of all available packages, and their dependencies)
#  |___ packages
#         |___ <installed package>
#         (contains the contents of the installed package)
#

pkg_usage() {
	# TODO someone needs to make this pretty.
	echo '	in[stall] <packages...>'
	echo '	rm|remove <packages...>'
	echo '	se[arch] <regex>'
	echo '	av[ail]'
	echo

	exit 0
}

pkg_search() {
	# loop through all repositories
	RET=0
	for DB in `/bin/ls -1 $ROOT/repo/*`
	do
		# find all matches
		cut -d: -f1 <$DB | grep -q "${1}" && {
			# output all matches, and their repository
			for RESULT in `cut -d: -f1 <$DB | grep "${1}"`
			do
				printf '%s/%s\n' "`basename $DB`" "$RESULT"
			done

			RET=$(($RET-1))
		} || RET=$(($RET+1))
	done

	[ $RET -lt 0 ] && RET=0
	return $RET
}

pkg_link() {
	printf "https://%s.pkg\n" "`pkg_search \"^${1}$\"`"
}

pkg_deps() {
	# gets first level dependencies for packageA
	# recursion shall be handled elsewhere.
	for PKG in $1
	do
		for DB in `/bin/ls -1 $ROOT/repo/*`
		do
			grep "^${PKG}:" <$DB | cut -d: -f2
		done
	done
}

pkg_exists() {
	pkg_search "^${1}$" >/dev/null
}

pkg_remove() {
	echo mock uninstall $1
}

pkg_install() {
	# install all dependencies first
	for DEP in `pkg_deps $1`
	do
		$0 in $DEP
	done

	echo mock installing $1
}

case "$1" in
in|install)
	shift
	[ -z "$1" ] && pkg_usage
	for PKG in $@
	do
		pkg_exists $PKG || {
			echo package $PKG does not exist 1>&2
			break
		}
		pkg_install $PKG
	done
	;;
rm|remove)
	shift
	[ -z "$1" ] && pkg_usage
	for PKG in $@
	do
		pkg_exists $PKG || {
			echo package $PKG does not exist 1>&2
			break
		}
		pkg_remove $PKG
	done
	;;
se|search)
	shift
	[ -z "$1" ] && pkg_usage
	pkg_search $@
	;;
av|avail)
	# run a search matching everything
	pkg_search .
	;;
*)
	pkg_usage
	;;
esac