forked from Gregwar/notroot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notroot
executable file
·67 lines (64 loc) · 1.51 KB
/
notroot
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
#!/bin/bash
# Go to this directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
which apt-get 2> /dev/null >&2
if [ $? -eq 0 ]; then
MODE="apt"
else
which yum 2> /dev/null >&2
if [ $? -eq 0 ]; then
MODE="yum"
else
echo "I can't found apt or yum"
exit 1
fi
fi
if [ $# -lt 2 ]; then
echo "Usage: "
echo " notroot [search|install] package"
echo ""
echo " search package:"
echo " Display the search result for a package"
echo ""
echo " install packages:"
echo " Installs a given package"
echo ""
echo "Note: don't forget to source notroot/bashrc"
exit 1
fi
case $1 in
search)
if [ "$MODE" = "apt" ]; then
apt-cache search $2
fi
if [ "$MODE" = "yum" ]; then
yum search $2
fi
;;
install)
shift
for package in $*; do
echo "Installing $package from $MODE..."
if [ "$MODE" = "apt" ]; then
rm -rf deb
mkdir deb &&
cd deb &&
apt-get download $package &&
cd .. &&
dpkg -x deb/*.deb .
fi
if [ "$MODE" = "yum" ]; then
rm -rf rpm
mkdir rpm &&
cd rpm &&
yumdownloader $package &&
cd .. &&
rpm2cpio rpm/*.rpm | cpio -idmvu
fi
done
;;
*)
echo "Unknown instruction $1"
;;
esac