-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.sh
70 lines (59 loc) · 1.61 KB
/
installer.sh
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
#!/bin/bash
# Function to check root access
check_root() {
[[ $EUID -eq 0 ]]
}
# Check if ipeeinfo is already installed
check_installed() {
[[ -f "/usr/bin/ipeeinfo" ]]
}
# Installing process
installer() {
if check_installed; then
# If package is already installed, print message and exit
echo -e "\ninfo: ipeeinfo is already installed."
exit 0
fi
# Print install message
echo -e "\ninfo: installing package for you."
# Copy file to /usr/bin
if ! cp ipeeinfo.py /usr/bin/ipeeinfo; then
echo "error: failed to copy file to /usr/bin"
exit 1
fi
# Change permissions
if ! chmod 755 /usr/bin/ipeeinfo; then
echo "error: failed to set executable permission for /usr/bin/ipeeinfo"
exit 1
fi
# Print success message
echo "success: ipeeinfo has been installed."
}
# Uninstalling process
uninstaller() {
# Print uninstall message
echo -e "\ninfo: uninstalling package from your system."
# Remove file from /usr/bin
if check_installed; then
if ! rm /usr/bin/ipeeinfo; then
echo "error: failed to remove /usr/bin/ipeeinfo"
exit 1
fi
# Print success message
echo "success: ipeeinfo has been uninstalled."
else
# If package is not installed, print message and exit
echo "info: ipeeinfo is not installed."
exit 0
fi
}
if check_root; then
if [[ $# -gt 0 && "$1" == "--uninstall" ]]; then
uninstaller
else
installer
fi
else
echo "error: you cannot perform this operation unless you are root."
exit 1
fi