-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathpkg
More file actions
131 lines (122 loc) · 2.95 KB
/
Copy pathpkg
File metadata and controls
131 lines (122 loc) · 2.95 KB
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
121
122
123
124
125
126
127
128
129
130
131
#! /bin/sh
# Tool to install/remove commands to a-Shell
#
# options:
# install packageName: pull server/packageName.pkg, execute script packageName.pkg, create .pkg/packageName
# remove packageName: execute .pkg/packageName
# list: show all installed packages
# search + regexp: pull list from server, grep with regexp
# main url. Can be overidden by environment variable
if [ -z "$PKG_SERVER" ]
then
server=https://raw.githubusercontent.com/holzschu/a-Shell-commands/master/
else
server=$PKG_SERVER
fi
usage() {
cat << 'EOF'
Usage: pkg [install name] [remove name] [list] [search expression]
install: installs package "name"
remove: removes package "name"
list: list all installed packages
search: lists packages matching expression
pkg will search for packages on $PKG_SERVER, if it set, and https://raw.githubusercontent.com/holzschu/a-Shell-commands/master/ otherwise
EOF
}
list() {
if [ -d ~/Documents/.pkg ]
then
$APPDIR/bin/ls -1 ~/Documents/.pkg/
else
echo No packages installed yet
fi
}
search() {
echo Packages available:
if [ -z $1 ]
then
$APPDIR/bin/curl -L $server/list --silent
else
expression=$1
$APPDIR/bin/curl -L $server/list --silent | $APPDIR/bin/grep $expression
fi
}
install() {
for name in $@
do
if [ $# -ge 2 ]
then
echo Processing $name
fi
$APPDIR/bin/curl -L $server/list --silent | $APPDIR/bin/grep ^$name > ~/tmp/packageList
length=`wc -l < ~/tmp/packageList`
if [ $length -eq 0 ]
then
echo Package $name not found
elif [ $length -eq 1 ]
then
packageName=`cat ~/tmp/packageList`
echo Downloading $packageName
$APPDIR/bin/curl -L $server/packages/$packageName -o ~/tmp/$packageName --silent
$APPDIR/bin/chmod +x ~/tmp/$packageName
$APPDIR/bin/sh ~/tmp/$packageName
$APPDIR/bin/rm ~/tmp/$packageName
echo Done
else
packageFound=0
for packageName in `cat ~/tmp/packageList`
do
if [ $packageName = $name ]
then
echo Downloading $packageName
$APPDIR/bin/curl -L $server/packages/$packageName -o ~/tmp/$packageName --silent
$APPDIR/bin/chmod +x ~/tmp/$packageName
$APPDIR/bin/sh ~/tmp/$packageName
$APPDIR/bin/rm ~/tmp/$packageName
packageFound=1
echo Done
break
fi
done
if [ $packageFound -eq 0 ]
then
echo Package name $name unclear. Did you mean:
$APPDIR/bin/cat ~/tmp/packageList
fi
fi
$APPDIR/bin/rm ~/tmp/packageList
done
}
remove() {
for name in $@
do
if [ $# -ge 2 ]
then
echo Processing $name
fi
if [ -f ~/Documents/.pkg/$name ]
then
echo Removing $name
$APPDIR/bin/sh ~/Documents/.pkg/$name
$APPDIR/bin/rm ~/Documents/.pkg/$name
# mandocdb complains if it's called with $APPDIR/bin/
\mandocdb ~/Library/man/
echo Done
else
echo Package $name was not installed by pkg. Cannot remove it.
fi
done
}
case $1 in
install|update|upgrade)
shift
install $@
;;
list) list;;
remove|uninstall)
shift
remove $@
;;
search) search $2;;
*) usage
esac