From d74b471b73265d4524ce299252ac407f2430ff1d Mon Sep 17 00:00:00 2001 From: rick sanchez Date: Fri, 2 Sep 2022 17:38:20 +0200 Subject: [PATCH] update : creation of an first install.sh script --- install.sh | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..f406857 --- /dev/null +++ b/install.sh @@ -0,0 +1,109 @@ +#!/bin/bash +# This script will install the dependencies for the project +# Author: Rick Sanchez +# Date: 2/9/2022 + +linux_install_with_package_manager() { + # if the OS is debian/ubuntu use apt-get to install $1 + if [ -f /etc/debian_version ]; then + sudo apt-get install -y $1 + # elif the OS is archlinux use pacman to install $1 + elif [ -f /etc/arch-release ]; then + sudo pacman -S --noconfirm $1 + # elif the OS is redhat/fedora use yum to install $1 + elif [ -f /etc/redhat-release ]; then + sudo yum install -y $1 + else + echo "OS not supported" + exit 1 + fi +} + +linux_update_package_manager(){ + if [ -f /etc/debian_version ]; then + sudo apt-get update + elif [ -f /etc/arch-release ]; then + sudo pacman -Syu + elif [ -f /etc/redhat-release ]; then + sudo yum update + else + echo "OS not supported" + exit 1 + fi +} + +# update the packager appropriately for the OS and architecture +if [ "$(uname)" == "Darwin" ]; then + export PACKAGER="macosx" +elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then + export PACKAGER="linux" +fi + +# update the architecture appropriately for the OS and architecture +if [ "$(uname -m)" == "x86_64" ]; then + export ARCH="amd64" +elif [ "$(uname -m)" == "i686" ]; then + export ARCH="386" +fi + +# if the var $PACKAGER is not set, exit with an error +if [ -z "$PACKAGER" ]; then + echo "Unable to determine the packager for this OS and architecture." + exit 1 +else +# else call the appropriate package manager to install + if [[ "$PACKAGER" == "linux" ]]; then + echo 'linux package manager update...' + linux_update_package_manager + echo 'linux package manager install...' + linux_install_with_package_manager python3 + elif [[ "$PACKAGER" == "macosx" ]]; then + if [ -f /usr/local/bin/brew ]; then + echo "Homebrew is already installed so brew update and brew upgrade" + echo "Homebrew installation skipped." + brew update + brew install python@3.9 pipenv + else + echo "Homebrew is not installed. Installation of homebrew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + echo "Now installing, brew update and install python@3.9 and pipenv..." + brew update + brew install python@3.9 pipenv + fi + fi +fi + +# function to install packages with the appropriate package manager, linux, mac, fedora, etc. +function install_packages() { + if [ "$(uname)" == "Darwin" ]; then + brew install $1 + elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then + #detect linux branch based + linux_install_with_package_manager $1 + elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then + echo "Windows" + else + echo "Unknown OS" + fi +} + +# install the packages +install_packages hostapd haveged dnsmasq qrencode + +# make the /opt/lnxrouter directory +sudo mkdir -p /opt/lnxrouter + +# make the /opt/lnxrouter/bin directory +sudo mkdir -p /opt/lnxrouter/bin + +# copy the lnxrouter.sh script to /opt/lnxrouter/bin +sudo cp lnxrouter.sh /opt/lnxrouter/bin + +# change the permissions on the lnxrouter.sh script +sudo chmod 755 /opt/lnxrouter/bin/lnxrouter.sh + +# create symbolic link to the lnxrouter.sh script +sudo ln -s /opt/lnxrouter/bin/lnxrouter.sh /usr/local/bin/lnxrouter + +# display "It's done!" in yellow +echo -e "\e[33mIt's done!\e[0m"