From 5e08da5f65ccc4039c6d72635576a6d33832d124 Mon Sep 17 00:00:00 2001 From: Luca Saladino Date: Thu, 25 Apr 2024 16:25:11 +0200 Subject: [PATCH 1/3] Implemented macos support --- install.sh | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 5eb7d98..8f147f7 100644 --- a/install.sh +++ b/install.sh @@ -19,14 +19,47 @@ By using this software you must agree all below terms: [?] If you agree, press [Enter] to procede:" read junk -# TODO: Implement non-APT environment installation -if [ $(dpkg-query -W -f='${Status}' python3 > /dev/null 2>&1 | grep -c "ok installed") -eq 0 ]; then - # Python3 not installed on the system, just install it! - echo "[*] Installing python interpreter on the system..." - apt update > /dev/null 2>&1; - apt install python3 > /dev/null 2>&1; +if [ "$(uname)" == "Darwin" ]; then + install_python_mac() +elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then + install_python_linux() +else + echo "[x] Only MacOS and Linux operating system are supported." fi +install_python_mac () { + if ! command -v brew >/dev/null; then + echo "[x] Brew package manager not installed." + fi + + if ! brew list -1 | grep -q "python@3"; then + echo "[*] Installing python interpreter on the system..." + if ! brew install -y "python3" > /dev/null 2>&1; then + echo "[x] Cannot install python via brew." + fi + fi +} + +install_python_linux () { + if command -v apt-get >/dev/null; then + install_python_apt() + elif command -v yum >/dev/null; then + install_python_yum() + else + echo "[x] Neither apt not yum found as package manager." + exit + fi +} + +install_python_apt () { + if [ $(dpkg-query -W -f='${Status}' python3 > /dev/null 2>&1 | grep -c "ok installed") -eq 0 ]; then + # Python3 not installed on the system, just install it! + echo "[*] Installing python interpreter on the system..." + apt update > /dev/null 2>&1; + apt install python3 > /dev/null 2>&1; + fi +} + # Install python requirements echo "[*] Installing python requirements..." pip3 install -r requirements.txt > /dev/null 2>&1; From 87a30aaaba21bc184a8d932cdc5b13e1088413b6 Mon Sep 17 00:00:00 2001 From: Luca Saladino Date: Sat, 27 Apr 2024 13:59:23 +0200 Subject: [PATCH 2/3] First tests and fixes for linux --- README.md | 16 +++++- install.sh | 145 +++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 117 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 66f0bc6..e44d3d6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # script-wizard -A fully automated installer for python scripts +A fully automated installer for python scripts. + +# Requirements +- The shell should be `bash` +- MacOS or Linux +- The system package manager must be `apt` or `yum` for Linux environments and `brew` for MacOS enviroments +- The python script must be a single file inside placed under the `src/` directory of the project + +# Usage +1) Copy the `install.sh` script to your project root directory +2) Edit the script replacing the 3 variables as described below: + - `PROGRAMNAME` is the **full program name** such as "My Project" + - `DEVELOPERNAME` is the **developer name** such as "My Name" + - `SHORTPROGRAMNAME` is the **git like project name** such as "my-project" + diff --git a/install.sh b/install.sh index 8f147f7..783d0a3 100644 --- a/install.sh +++ b/install.sh @@ -1,78 +1,137 @@ #!/bin/bash -if [ "$EUID" -ne 0 ] - then echo "[x] Root privileges required!" - exit -fi - PROGRAMNAME="" DEVELOPERNAME="" SHORTPROGRAMNAME="" -echo "Welcome to the $PROGRAMNAME installer - -By using this software you must agree all below terms: - 1) By using this software, it's the end user’s responsibility to obey all applicable local, state and federal laws. - 2) The software is provided \"as is\", without warranty of any kind, express or implied. - 3) $DEVELOPERNAME isn't responsible for any damage caused by this software. - -[?] If you agree, press [Enter] to procede:" -read junk - -if [ "$(uname)" == "Darwin" ]; then - install_python_mac() -elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then - install_python_linux() -else - echo "[x] Only MacOS and Linux operating system are supported." -fi - install_python_mac () { - if ! command -v brew >/dev/null; then + if ! command -v brew > /dev/null; then echo "[x] Brew package manager not installed." + exit 1 fi - if ! brew list -1 | grep -q "python@3"; then - echo "[*] Installing python interpreter on the system..." + brew list | grep "python@3.*" > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "[*] Installing the python interpreter on the system..." if ! brew install -y "python3" > /dev/null 2>&1; then - echo "[x] Cannot install python via brew." + echo "[x] Cannot install the python interpreter via brew." + exit 1 fi + else + echo "[*] The python interpreter is already installed." fi } install_python_linux () { - if command -v apt-get >/dev/null; then - install_python_apt() - elif command -v yum >/dev/null; then - install_python_yum() + if [ "$EUID" -ne 0 ] + then echo "[x] Root privileges required!" + exit 1 + fi + + if command -v apt-get > /dev/null; then + install_python_apt + elif command -v yum > /dev/null; then + install_python_yum else - echo "[x] Neither apt not yum found as package manager." - exit + echo "[x] Neither apt nor yum found as package manager." + exit 1 fi } install_python_apt () { if [ $(dpkg-query -W -f='${Status}' python3 > /dev/null 2>&1 | grep -c "ok installed") -eq 0 ]; then - # Python3 not installed on the system, just install it! - echo "[*] Installing python interpreter on the system..." + echo "[*] Installing the python interpreter on the system..." apt update > /dev/null 2>&1; apt install python3 > /dev/null 2>&1; fi } -# Install python requirements +install_python_yum () { + if ! yum list installed python3 &>/dev/null; then + echo "[*] Installing the python interpreter on the system..." + yum install -y python3 > /dev/null 2>&1; + fi +} + +check_init_variables () { + if [ -z "$PROGRAMNAME" ]; then + echo "[x] The PROGRAMNAME variable is empty. Please configure the script before running it." + exit 2 + fi + + if [ -z "$DEVELOPERNAME" ]; then + echo "[x] The DEVELOPERNAME variable is empty. Please configure the script before running it." + exit 2 + fi + + if [ -z "$SHORTPROGRAMNAME" ]; then + echo "[x] The SHORTPROGRAMNAME variable is empty. Please configure the script before running it." + exit 2 + fi +} + +create_directory () { + if [ -w /opt ]; then + mkdir /opt/$SHORTPROGRAMNAME > /dev/null 2>&1; + else + sudo mkdir /opt/$SHORTPROGRAMNAME > /dev/null 2>&1; + fi +} + +copy_script () { + if [ -w /opt/$SHORTPROGRAMNAME ]; then + cp src/$SHORTPROGRAMNAME.py /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py > /dev/null 2>&1; + else + sudo cp src/$SHORTPROGRAMNAME.py /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py > /dev/null 2>&1; + sudo chmod 005 /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py + fi +} + +link_executable () { + if [ $(id -u) != 0 ]; then + sudo ln -s /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py /usr/bin/$SHORTPROGRAMNAME > /dev/null 2>&1; + else + ln -s /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py /usr/bin/$SHORTPROGRAMNAME > /dev/null 2>&1; + fi +} + +### MAIN ################################################################################# + +check_init_variables + +echo "Welcome to the $PROGRAMNAME installer + +By using this software you must agree all below terms: + 1) By using this software, it's the end user's responsibility to obey all applicable local, state and federal laws. + 2) The software is provided \"as is\", without warranty of any kind, express or implied. + 3) $DEVELOPERNAME isn't responsible for any damage caused by this software. + +[?] If you agree, press [Enter] to procede..." +read junk + +if [ "$(uname)" == "Darwin" ]; then + install_python_mac +elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then + install_python_linux +else + echo "[x] Only MacOS and Linux operating system are supported." + exit 1 +fi + echo "[*] Installing python requirements..." pip3 install -r requirements.txt > /dev/null 2>&1; -# Install the script in the opt directory +if [ -d /opt/$SHORTPROGRAMNAME ]; then + echo "[*] The software seems already installed." + exit 0 +fi + echo "[*] Installing the software..." -mkdir /opt/$SHORTPROGRAMNAME > /dev/null 2>&1; -cp src/$SHORTPROGRAMNAME.py /opt/$SHORTPROGRAMNAME > /dev/null 2>&1; -chmod +x /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py > /dev/null 2>&1; +create_directory +copy_script -# Create the command for the shell -echo "[*] Setting up the environment..." -ln -s /opt/$SHORTPROGRAMNAME/$SHORTPROGRAMNAME.py /usr/bin/$SHORTPROGRAMNAME > /dev/null 2>&1; +echo "[*] Linking the executable..." +link_executable echo "" echo "[v] Successfully installed $PROGRAMNAME in your system!"; From aa3fe9a9a3b06473a98c78bf1fb0e221e09e4201 Mon Sep 17 00:00:00 2001 From: Luca Saladino <38191926+zeroSal@users.noreply.github.com> Date: Sun, 28 Apr 2024 13:19:32 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e44d3d6..34a394f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # script-wizard A fully automated installer for python scripts. +![witch-hat](https://github.com/zeroSal/script-wizard/assets/38191926/ac7b475d-60c0-4ee2-b24c-05ebcd3c8ed2) + +[Icon by Freepik - Flaticon](https://www.flaticon.com/free-icons/wizard) + # Requirements - The shell should be `bash` - MacOS or Linux @@ -13,4 +17,3 @@ A fully automated installer for python scripts. - `PROGRAMNAME` is the **full program name** such as "My Project" - `DEVELOPERNAME` is the **developer name** such as "My Name" - `SHORTPROGRAMNAME` is the **git like project name** such as "my-project" -