|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -if [ "$EUID" -ne 0 ] |
4 |
| - then echo "[x] Root privileges required!" |
5 |
| - exit |
6 |
| -fi |
7 |
| - |
8 | 3 | PROGRAMNAME=""
|
9 | 4 | DEVELOPERNAME=""
|
10 | 5 | SHORTPROGRAMNAME=""
|
11 | 6 |
|
12 |
| -echo "Welcome to the $PROGRAMNAME installer |
13 |
| -
|
14 |
| -By using this software you must agree all below terms: |
15 |
| - 1) By using this software, it's the end user’s responsibility to obey all applicable local, state and federal laws. |
16 |
| - 2) The software is provided \"as is\", without warranty of any kind, express or implied. |
17 |
| - 3) $DEVELOPERNAME isn't responsible for any damage caused by this software. |
18 |
| -
|
19 |
| -[?] If you agree, press [Enter] to procede:" |
20 |
| -read junk |
21 |
| - |
22 |
| -if [ "$(uname)" == "Darwin" ]; then |
23 |
| - install_python_mac() |
24 |
| -elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then |
25 |
| - install_python_linux() |
26 |
| -else |
27 |
| - echo "[x] Only MacOS and Linux operating system are supported." |
28 |
| -fi |
29 |
| - |
30 | 7 | install_python_mac () {
|
31 |
| - if ! command -v brew >/dev/null; then |
| 8 | + if ! command -v brew > /dev/null; then |
32 | 9 | echo "[x] Brew package manager not installed."
|
| 10 | + exit 1 |
33 | 11 | fi
|
34 | 12 |
|
35 |
| - if ! brew list -1 | grep -q "python@3"; then |
36 |
| - echo "[*] Installing python interpreter on the system..." |
| 13 | + brew list | grep "python@3.*" > /dev/null 2>&1 |
| 14 | + if [ $? -ne 0 ]; then |
| 15 | + echo "[*] Installing the python interpreter on the system..." |
37 | 16 | if ! brew install -y "python3" > /dev/null 2>&1; then
|
38 |
| - echo "[x] Cannot install python via brew." |
| 17 | + echo "[x] Cannot install the python interpreter via brew." |
| 18 | + exit 1 |
39 | 19 | fi
|
| 20 | + else |
| 21 | + echo "[*] The python interpreter is already installed." |
40 | 22 | fi
|
41 | 23 | }
|
42 | 24 |
|
43 | 25 | install_python_linux () {
|
44 |
| - if command -v apt-get >/dev/null; then |
45 |
| - install_python_apt() |
46 |
| - elif command -v yum >/dev/null; then |
47 |
| - install_python_yum() |
| 26 | + if [ "$EUID" -ne 0 ] |
| 27 | + then echo "[x] Root privileges required!" |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | + |
| 31 | + if command -v apt-get > /dev/null; then |
| 32 | + install_python_apt |
| 33 | + elif command -v yum > /dev/null; then |
| 34 | + install_python_yum |
48 | 35 | else
|
49 |
| - echo "[x] Neither apt not yum found as package manager." |
50 |
| - exit |
| 36 | + echo "[x] Neither apt nor yum found as package manager." |
| 37 | + exit 1 |
51 | 38 | fi
|
52 | 39 | }
|
53 | 40 |
|
54 | 41 | install_python_apt () {
|
55 | 42 | if [ $(dpkg-query -W -f='${Status}' python3 > /dev/null 2>&1 | grep -c "ok installed") -eq 0 ]; then
|
56 |
| - # Python3 not installed on the system, just install it! |
57 |
| - echo "[*] Installing python interpreter on the system..." |
| 43 | + echo "[*] Installing the python interpreter on the system..." |
58 | 44 | apt update > /dev/null 2>&1;
|
59 | 45 | apt install python3 > /dev/null 2>&1;
|
60 | 46 | fi
|
61 | 47 | }
|
62 | 48 |
|
63 |
| -# Install python requirements |
| 49 | +install_python_yum () { |
| 50 | + if ! yum list installed python3 &>/dev/null; then |
| 51 | + echo "[*] Installing the python interpreter on the system..." |
| 52 | + yum install -y python3 > /dev/null 2>&1; |
| 53 | + fi |
| 54 | +} |
| 55 | + |
| 56 | +check_init_variables () { |
| 57 | + if [ -z "$PROGRAMNAME" ]; then |
| 58 | + echo "[x] The PROGRAMNAME variable is empty. Please configure the script before running it." |
| 59 | + exit 2 |
| 60 | + fi |
| 61 | + |
| 62 | + if [ -z "$DEVELOPERNAME" ]; then |
| 63 | + echo "[x] The DEVELOPERNAME variable is empty. Please configure the script before running it." |
| 64 | + exit 2 |
| 65 | + fi |
| 66 | + |
| 67 | + if [ -z "$SHORTPROGRAMNAME" ]; then |
| 68 | + echo "[x] The SHORTPROGRAMNAME variable is empty. Please configure the script before running it." |
| 69 | + exit 2 |
| 70 | + fi |
| 71 | +} |
| 72 | + |
| 73 | +create_directory () { |
| 74 | + if [ -w /opt ]; then |
| 75 | + mkdir /opt/$SHORTPROGRAMNAME > /dev/null 2>&1; |
| 76 | + else |
| 77 | + sudo mkdir /opt/$SHORTPROGRAMNAME > /dev/null 2>&1; |
| 78 | + fi |
| 79 | +} |
| 80 | + |
| 81 | +copy_script () { |
| 82 | + if [ -w /opt/$SHORTPROGRAMNAME ]; then |
| 83 | + cp src/$SHORTPROGRAMNAME.py /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py > /dev/null 2>&1; |
| 84 | + else |
| 85 | + sudo cp src/$SHORTPROGRAMNAME.py /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py > /dev/null 2>&1; |
| 86 | + sudo chmod 005 /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py |
| 87 | + fi |
| 88 | +} |
| 89 | + |
| 90 | +link_executable () { |
| 91 | + if [ $(id -u) != 0 ]; then |
| 92 | + sudo ln -s /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py /usr/bin/$SHORTPROGRAMNAME > /dev/null 2>&1; |
| 93 | + else |
| 94 | + ln -s /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py /usr/bin/$SHORTPROGRAMNAME > /dev/null 2>&1; |
| 95 | + fi |
| 96 | +} |
| 97 | + |
| 98 | +### MAIN ################################################################################# |
| 99 | + |
| 100 | +check_init_variables |
| 101 | + |
| 102 | +echo "Welcome to the $PROGRAMNAME installer |
| 103 | +
|
| 104 | +By using this software you must agree all below terms: |
| 105 | + 1) By using this software, it's the end user's responsibility to obey all applicable local, state and federal laws. |
| 106 | + 2) The software is provided \"as is\", without warranty of any kind, express or implied. |
| 107 | + 3) $DEVELOPERNAME isn't responsible for any damage caused by this software. |
| 108 | +
|
| 109 | +[?] If you agree, press [Enter] to procede..." |
| 110 | +read junk |
| 111 | + |
| 112 | +if [ "$(uname)" == "Darwin" ]; then |
| 113 | + install_python_mac |
| 114 | +elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then |
| 115 | + install_python_linux |
| 116 | +else |
| 117 | + echo "[x] Only MacOS and Linux operating system are supported." |
| 118 | + exit 1 |
| 119 | +fi |
| 120 | + |
64 | 121 | echo "[*] Installing python requirements..."
|
65 | 122 | pip3 install -r requirements.txt > /dev/null 2>&1;
|
66 | 123 |
|
67 |
| -# Install the script in the opt directory |
| 124 | +if [ -d /opt/$SHORTPROGRAMNAME ]; then |
| 125 | + echo "[*] The software seems already installed." |
| 126 | + exit 0 |
| 127 | +fi |
| 128 | + |
68 | 129 | echo "[*] Installing the software..."
|
69 |
| -mkdir /opt/$SHORTPROGRAMNAME > /dev/null 2>&1; |
70 |
| -cp src/$SHORTPROGRAMNAME.py /opt/$SHORTPROGRAMNAME > /dev/null 2>&1; |
71 |
| -chmod +x /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py > /dev/null 2>&1; |
| 130 | +create_directory |
| 131 | +copy_script |
72 | 132 |
|
73 |
| -# Create the command for the shell |
74 |
| -echo "[*] Setting up the environment..." |
75 |
| -ln -s /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py /usr/bin/$SHORTPROGRAMNAME > /dev/null 2>&1; |
| 133 | +echo "[*] Linking the executable..." |
| 134 | +link_executable |
76 | 135 |
|
77 | 136 | echo ""
|
78 | 137 | echo "[v] Successfully installed $PROGRAMNAME in your system!";
|
0 commit comments