From 3daee0121a144ff84b89c68b8aa4ee5012c725e5 Mon Sep 17 00:00:00 2001 From: Fr4nzD13trich Date: Thu, 9 Oct 2025 15:42:38 +0200 Subject: [PATCH] Several updates in scripts --- README.md | 1 + assets/test/test.sh | 99 +++++++++++++++++++++++++++++++++++++++++++++ dev_env_setup.sh | 48 +++++++++++----------- 3 files changed, 124 insertions(+), 24 deletions(-) create mode 100755 assets/test/test.sh diff --git a/README.md b/README.md index ee7dc25..9f7da2b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Idea is to: - create a web app, coded in `html`, `css`, `js` and `php` and make it a bit prettier than the original. - code a backend utilising `flask`, `python`, `python3-meshtastic` and `python3-requests`. - make it as light but versatile as possible _let's see how this is gonna work out..._ +- and **maybe** connect to mobile clients in the far future. - check progress [here](https://lab.c95.org/fr4nz/LoMeS/src/branch/main/assets/notes/notes.md) --- diff --git a/assets/test/test.sh b/assets/test/test.sh new file mode 100755 index 0000000..1fb107a --- /dev/null +++ b/assets/test/test.sh @@ -0,0 +1,99 @@ +#!/bin/bash +source assets/shell/shell_colors +### DEPENDENCY CHECK & INSTALLER + +pkgs="openssl nginx" + +echo -e "\n${CYN} Dependency and Privilege Check running...${CRS}\n" + +### PRIVILEGES + +if (( $(id -u) == 0 )); then + echo -e "${GRN} Privilege check passed...${CRS}\n" + +else + echo -e "${RED} Privilege check failed... Please run script with sudo or as root!${CRS}\n" + exit 1 +fi + +### DEPENDENCIES + +if command -v "$pkgs" >/dev/null 2>&1; then + echo -e "${GRN} Dependency check passed...${CRS}\n" + +else + echo -e "${YEL} Dependencies not met.${CRS}\n" + + while true; do + echo -e " ${YEL}Do you wish to install via APT? (${GRN}Y${YEL}/${RED}n${YEL})${CRS}" + read -p " --> " install + echo "" + if [[ "$install" = "" || "$install" = "y" || "$install" = "Y" ]]; then + sudo apt update && sudo apt install --install-suggests -y $pkgs --simulate ## DEV + echo -e "\n${GRN} Dependencies installed. Proceeding...${CRS}\n" + break + + elif [[ "$install" == "n" || "$install" = "N" ]]; then + echo -e "\n${RED} Missing dependencies... Exiting!${CRS}\n" + exit 1 + + else + echo -e "\n${YEL} Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n " + fi + done +fi + +### NGINX SETUP & CONFIG + +###### CERTIFICATION + +while true; do + echo -e " ${YEL}Configure SSL and create a self signed cetrificate? (Y/n)${CRS}" + read -p " --> " installSSL + if [[ "$installSSL" = "" || "$installSSL" = "y" || "$installSSL" = "Y" ]]; then + echo -e " ${YEL}Enter path to certificates folder${CRS}" + read -p " default = /etc/nginx/ssl --> " cert_path + if ! [ "$cert_path" ]; then + cert_path=/etc/nginx/ssl + elif [[ "$cert_path" = "." ]]; then + cert_path=$PWD + else + : + fi + echo "" + echo -e " ${YEL}Enter file name for certificate and key${CRS}" + read -p " default --> $HOSTNAME --> " cert_name + if ! [ "$cert_name" ]; then + cert_name=$HOSTNAME + else + : + fi + echo "" + sudo mkdir -p "$cert_path" + sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "$cert_path"/"$cert_name".key -out "$cert_path"/"$cert_name".crt + echo -e "\n${GRN} SSL certificate files ${YEL}$cert_name.crt ${GRN}and ${YEL}$cert_name.key ${GRN}created and stored in ${YEL}$cert_path${CRS}\n" + break + elif [[ "$installSSL" == "n" || "$installSSL" = "N" ]]; then + echo -e "\n${RED} No encryption established${CRS}\n" + break + else + echo -e "\n${YEL} Invalid response... Try again...\n\nY = (Yes, configure SSL certificate and continue)\nN = (No, leave unencrypted and continue)${CRS}\n " + fi + done + + +echo -e "${YEL} Your current hostname is ${CYN}$HOSTNAME${CRS} would you like to change it?${CRS}" + +# ask for network interface & get IP +# ask to change hostname in /etc/hosts & /etc/hostname + +### DEV STATUS + +#sudo cp -R assets/config/nginx/nginx.conf /etc/nginx/sites-enabled/ +## JEFF +# utilise sed to edit config +# test nginx config +# restart nginx +## JEFF END + +echo -e "${GRN}\nScript ran through...${CRS}" diff --git a/dev_env_setup.sh b/dev_env_setup.sh index 1577736..2a5fd13 100755 --- a/dev_env_setup.sh +++ b/dev_env_setup.sh @@ -25,7 +25,8 @@ else echo -e "${YEL} Dependencies not met.${CRS}\n" while true; do - read -p " Do you wish to install via APT? (Y/n) : " install + echo -e " ${YEL}Do you wish to install via APT? (${GRN}Y${YEL}/${RED}n${YEL})${CRS}" + read -p " --> " install echo "" if [[ "$install" = "" || "$install" = "y" || "$install" = "Y" ]]; then sudo apt update && sudo apt install --install-suggests -y $pkgs --simulate ## DEV @@ -37,46 +38,45 @@ else exit 1 else - echo -e "\n${YEL} Invalid response... Try again...\n\n Y = (Yes, install dependencies and continue)\n N = (No, don't install dependencies and exit)${CRS}\n " + echo -e "\n${YEL} Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n " fi done fi ### NGINX SETUP & CONFIG -###### DOMAIN & IP - -# ask for network interface & get IP -# get hostname from /etc/hostname -# ask to change hostname in /etc/hosts & /etc/hostname - ###### CERTIFICATION while true; do - read -p " Configure SSL and create a self signed cetrificate? (Y/n) : " installSSL + echo -e " ${YEL}Configure SSL and create a self signed cetrificate? (Y/n)${CRS}" + read -p " --> " installSSL if [[ "$installSSL" = "" || "$installSSL" = "y" || "$installSSL" = "Y" ]]; then - read -p " Enter path to certificates folder (Will be created if not present) : " cert_path + echo -e " ${YEL}Enter path to certificates folder${CRS}" + read -p " default = /etc/nginx/ssl --> " cert_path + if ! [ "$cert_path" ]; then + cert_path=/etc/nginx/ssl + elif [[ "$cert_path" = "." ]]; then + cert_path=$PWD + else + : + fi echo "" - read -p " Enter file name for certificates (Without file ending) : " cert_name + echo -e " ${YEL}Enter file name for certificate and key${CRS}" + read -p " default --> $HOSTNAME --> " cert_name + if ! [ "$cert_name" ]; then + cert_name=$HOSTNAME + else + : + fi echo "" sudo mkdir -p "$cert_path" sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "$cert_path"/"$cert_name".key -out "$cert_path"/"$cert_name".crt - #sudo cp -R assets/config/nginx/nginx.conf /etc/nginx/sites-enabled/ -## JEFF -# utilise sed to edit config -# test nginx config -# restart nginx -## JEFF END - echo -e "\n${GRN} Nginx configured${CRS}\n" + echo -e "\n${GRN} SSL certificate files ${YEL}$cert_name.crt ${GRN}and ${YEL}$cert_name.key ${GRN}created and stored in ${YEL}$cert_path${CRS}\n" break elif [[ "$installSSL" == "n" || "$installSSL" = "N" ]]; then - echo -e "\n${RED} Nginx configuration kept default${CRS}\n" + echo -e "\n${RED} No encryption established${CRS}\n" break else - echo -e "\n${YEL} Invalid response... Try again...\n\nY = (Yes, configure SSL certificate and continue)\nN = (No, don't configure SSL certificate and continue)${CRS}\n " + echo -e "\n${YEL} Invalid response... Try again...\n\nY = (Yes, configure SSL certificate and continue)\nN = (No, leave unencrypted and continue)${CRS}\n " fi done - -### DEV STATUS - -echo -e "${GRN}\nScript ran through...${CRS}" \ No newline at end of file