Skip to content

Commit 87a30aa

Browse files
committed
First tests and fixes for linux
1 parent 5e08da5 commit 87a30aa

File tree

2 files changed

+117
-44
lines changed

2 files changed

+117
-44
lines changed

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
# script-wizard
2-
A fully automated installer for python scripts
2+
A fully automated installer for python scripts.
3+
4+
# Requirements
5+
- The shell should be `bash`
6+
- MacOS or Linux
7+
- The system package manager must be `apt` or `yum` for Linux environments and `brew` for MacOS enviroments
8+
- The python script must be a single file inside placed under the `src/` directory of the project
9+
10+
# Usage
11+
1) Copy the `install.sh` script to your project root directory
12+
2) Edit the script replacing the 3 variables as described below:
13+
- `PROGRAMNAME` is the **full program name** such as "My Project"
14+
- `DEVELOPERNAME` is the **developer name** such as "My Name"
15+
- `SHORTPROGRAMNAME` is the **git like project name** such as "my-project"
16+

install.sh

+102-43
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,137 @@
11
#!/bin/bash
22

3-
if [ "$EUID" -ne 0 ]
4-
then echo "[x] Root privileges required!"
5-
exit
6-
fi
7-
83
PROGRAMNAME=""
94
DEVELOPERNAME=""
105
SHORTPROGRAMNAME=""
116

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-
307
install_python_mac () {
31-
if ! command -v brew >/dev/null; then
8+
if ! command -v brew > /dev/null; then
329
echo "[x] Brew package manager not installed."
10+
exit 1
3311
fi
3412

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..."
3716
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
3919
fi
20+
else
21+
echo "[*] The python interpreter is already installed."
4022
fi
4123
}
4224

4325
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
4835
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
5138
fi
5239
}
5340

5441
install_python_apt () {
5542
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..."
5844
apt update > /dev/null 2>&1;
5945
apt install python3 > /dev/null 2>&1;
6046
fi
6147
}
6248

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+
64121
echo "[*] Installing python requirements..."
65122
pip3 install -r requirements.txt > /dev/null 2>&1;
66123

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+
68129
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
72132

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
76135

77136
echo ""
78137
echo "[v] Successfully installed $PROGRAMNAME in your system!";

0 commit comments

Comments
 (0)