#!/bin/bash # add-loginv2.sh (July 09, 2023 2054pm) # V1 5086 | V2 5168| V3 5173 # Version 3 - does not overwrite exisitng jsx files but makes a copy in the appropiate directory # Version 3 - https://www.webune.com/forums/bash-script-add-login-to-react-vite-with-laravel-version-3.html # The purpose of this script is to add several components and views to a Vite React Login Authentication APP # Tutorial: https://www.webune.com/forums/add-authentication-to-react-vite-using-laravel-backend.html # Homepage: https://www.webune.com/forums/vite-login-bash-script-202306222251.html # source: /f/apachefriends/xampp/htdocs/over-imgV5/REACT/MYOWN/vite-upload-login #V3 SOURCE: /f/apachefriends/xampp/htdocs/over-imgV5/REACT/GITHUB-TEMLPLATES APP_NAME="" echo "Instructions: "$'\n'"This script will automatcially add register/login/logout capabilities to a vite react project to protected pages" echo "" echo "To add authentication to existing application, put this file outside the app folder and provide the name of the folder name. The script will look for the folder and if exists, you will be prompted to delete and rebuild, if selected no, it will add the authentication files only the exisiting app." echo "" while [[ $APP_NAME == "" ]] do read -p "Enter the name of the Application: " APP_NAME set -e done #rm -rf $APP_NAME echo "" OVERWRITE_FILE="" if [ -d "$APP_NAME" ]; then while [[ $OVERWRITE_FILE == "" ]] do read -p "[IMPORTANT] $APP_NAME already exists, do you want to Delete and REBUILD? "$'\n'"y = Will delete and rebuild existing folder "$'\n'"n = Will NOT delete the existing folder and ONLY add the authentication files. "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done if [[ $OVERWRITE_FILE == "y" ]]; then rm -rf $APP_NAME set -e echo "" echo "[DELTED] App Deleted. Rebuilding App $APP_NAME" fi else OVERWRITE_FILE="y" fi if [[ $OVERWRITE_FILE == "y" ]]; then clear echo "" echo "$APP_NAME/ doest not exisit in this directory. A new application will be create - App Name: $APP_NAME" echo "" while [[ $CLONE_APP == "" ]] do read -p "[Clone?] A new app will be created from scratch. Would you rather clone from github? "$'\n'"y = App will be clone from GitHub "$'\n'"n = App will be create from scratch using create vite "$'\n'"Clone? y/n " CLONE_APP set -e done if [[ $CLONE_APP == "y" ]]; then CLONE_URL="https://github.com/edwinaquino/June-2023-React-Vite-SSL-SPA-With-API-Authentication.git" echo "" echo "Cloning from $CLONE_URL" git clone $CLONE_URL $APP_NAME else echo "" echo "Building New App $APP_NAME" npm create vite@latest $APP_NAME -- --template react fi cd $APP_NAME set -e echo "Installing npm dependencies!!!!!!!!!!" npm install set -e cd ../ set -e fi cd $APP_NAME if [[ $CLONE_APP == "y" ]]; then npm run dev fi # INSTALL DEPENCIES packages+=("react-router-dom" "axios" "@vitejs/plugin-basic-ssl" "bootstrap") for package in "${packages[@]}"; do PACKAGE="n" read -p "Do you want to install ${package} y/n: [n] " PACKAGE if [[ $PACKAGE == "y" ]]; then npm i $package set -e fi done # ROOT FILES ROOT_FILES=(".env" "vite.config.js") for ROOT_FILE in "${ROOT_FILES[@]}"; do OVERWRITE_FILE="" THIS_ROOT_PATH="$ROOT_FILE" if [ -f "$THIS_ROOT_PATH" ]; then while [[ $OVERWRITE_FILE == "" ]] do read -p "[IMPORTANT] $THIS_ROOT_PATH already exists, do you want to overwrite from the download? "$'\n'"y = Will delete and rebuild existing file "$'\n'"n = Will NOT delete the existing file, create a new file with '_login postfix' and will have to add the code manually "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done # echo "OVERWRITE_FILE = $THIS_ROOT_PATH" # if [[ $OVERWRITE_FILE == "y" ]]; then # rm $THIS_ROOT_PATH # echo "LINE 91 Overwriting and Downloading loginFile $THIS_ROOT_PATH" # curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html # set -e # fi if [[ $OVERWRITE_FILE == "y" ]]; then echo "OVERWRITE_FILE = $THIS_ROOT_PATH" rm $THIS_ROOT_PATH echo "LINE 124 Overwriting and Downloading loginFile $THIS_ROOT_PATH" else THIS_ROOT_PATH="${THIS_ROOT_PATH}_copy" echo "CREATE COPY FILE: = $THIS_ROOT_PATH" fi curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e else echo "LINE 95 Downloading loginFile $THIS_ROOT_PATH" curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e fi done # src/ files SRC_DIR="src" if [ ! -d "$SRC_DIR" ]; then echo "$SRC_DIR doesnt exists, creating..." mkdir -p $SRC_DIR set -e fi ROOT_FILES=("router.jsx" "main.jsx" "Dashboard.jsx" "axios-client.js") for ROOT_FILE in "${ROOT_FILES[@]}"; do THIS_ROOT_PATH="${SRC_DIR}/$ROOT_FILE" OVERWRITE_FILE="" if [ -f "$THIS_ROOT_PATH" ]; then while [[ $OVERWRITE_FILE == "" ]] do read -p "[IMPORTANT] $THIS_ROOT_PATH already exists, do you want to overwrite from the download? "$'\n'"y = Will delete and rebuild existing file "$'\n'"n = Will NOT delete the existing file, create a new file with '_login postfix' and will have to add the code manually "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done if [[ $OVERWRITE_FILE == "y" ]]; then echo "OVERWRITE_FILE = $THIS_ROOT_PATH" rm $THIS_ROOT_PATH echo "LINE 165 Overwriting and Downloading loginFile $THIS_ROOT_PATH" else THIS_ROOT_PATH="${THIS_ROOT_PATH}_copy" echo "CREATE COPY FILE: = $THIS_ROOT_PATH" fi curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e else echo "LINE 132 Downloading loginFile $THIS_ROOT_PATH" curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e fi done # COMPONENTS src/components SRC_DIR="src/components" if [ ! -d "$SRC_DIR" ]; then echo "$SRC_DIR doesnt exists, creating..." mkdir -p $SRC_DIR set -e fi # DOWNLOAD LOGIN FILES with array # https://www.freecodecamp.org/news/bash-array-how-to-declare-an-array-of-strings-in-a-bash-script/ ROOT_FILES=("DefaultLayout.jsx" "GuestLayout.jsx" "Header.jsx") for ROOT_FILE in "${ROOT_FILES[@]}"; do OVERWRITE_FILE="" THIS_ROOT_PATH="${SRC_DIR}/$ROOT_FILE" if [ -f "$THIS_ROOT_PATH" ]; then while [[ $OVERWRITE_FILE == "" ]] do read -p "[IMPORTANT] $THIS_ROOT_PATH already exists, do you want to overwrite from the download? "$'\n'"y = Will delete and rebuild existing file "$'\n'"n = Will NOT delete the existing file, create a new file with '_login postfix' and will have to add the code manually "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done # echo "OVERWRITE_FILE = $THIS_ROOT_PATH" # if [[ $OVERWRITE_FILE == "y" ]]; then # rm $THIS_ROOT_PATH # echo "LINE 162 Overwriting and Downloading loginFile $THIS_ROOT_PATH" # curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html # set -e # fi if [[ $OVERWRITE_FILE == "y" ]]; then echo "OVERWRITE_FILE = $THIS_ROOT_PATH" rm $THIS_ROOT_PATH echo "LINE 206 Overwriting and Downloading loginFile $THIS_ROOT_PATH" else THIS_ROOT_PATH="${THIS_ROOT_PATH}_copy" echo "CREATE COPY FILE: = $THIS_ROOT_PATH" fi curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e else echo "LIne 167 Downloading loginFile $THIS_ROOT_PATH" curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e fi done # VIEWS src/views - CREATE ALL THE NECESSARY USER AUTHENTICATION FILES SRC_DIR="src/views" if [ ! -d "$SRC_DIR" ]; then echo "$SRC_DIR doesnt exists, creating..." mkdir -p $SRC_DIR set -e fi # DOWNLOAD LOGIN FILES with array # https://www.freecodecamp.org/news/bash-array-how-to-declare-an-array-of-strings-in-a-bash-script/ ROOT_FILES=("Login.jsx" "NotFound.jsx" "Signup.jsx" "Users.jsx" "UserForm.jsx") for ROOT_FILE in "${ROOT_FILES[@]}"; do OVERWRITE_FILE="" THIS_ROOT_PATH="${SRC_DIR}/$ROOT_FILE" if [ -f "$THIS_ROOT_PATH" ]; then while [[ $OVERWRITE_FILE == "" ]] do read -p "[IMPORTANT] $THIS_ROOT_PATH already exists, do you want to overwrite from the download? "$'\n'"y = Will delete and rebuild existing file "$'\n'"n = Will NOT delete the existing file, create a new file with '_login postfix' and will have to add the code manually "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done # echo "OVERWRITE_FILE = $THIS_ROOT_PATH" # if [[ $OVERWRITE_FILE == "y" ]]; then # rm $THIS_ROOT_PATH # echo "LINE 202 Overwriting and Downloading loginFile $THIS_ROOT_PATH" # curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html # set -e # fi if [[ $OVERWRITE_FILE == "y" ]]; then echo "OVERWRITE_FILE = $THIS_ROOT_PATH" rm $THIS_ROOT_PATH echo "LINE 206 Overwriting and Downloading loginFile $THIS_ROOT_PATH" else THIS_ROOT_PATH="${THIS_ROOT_PATH}_copy" echo "CREATE COPY FILE: = $THIS_ROOT_PATH" fi curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e else echo "LINE207 Downloading loginFile $THIS_ROOT_PATH" curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e fi done # CONTEXT SRC_DIR="src/context" if [ ! -d "$SRC_DIR" ]; then echo "$SRC_DIR doesnt exists, creating..." mkdir -p $SRC_DIR set -e fi # DOWNLOAD CONTEXT PROVIDER ROOT_FILES=("ContextProvider.jsx") for ROOT_FILE in "${ROOT_FILES[@]}"; do OVERWRITE_FILE="" THIS_ROOT_PATH="${SRC_DIR}/$ROOT_FILE" if [ -f "$THIS_ROOT_PATH" ]; then while [[ $OVERWRITE_FILE == "" ]] do read -p "[IMPORTANT] $THIS_ROOT_PATH already exists, do you want to overwrite from the download? "$'\n'"y = Will delete and rebuild existing file "$'\n'"n = Will NOT delete the existing file, create a new file with '_login postfix' and will have to add the code manually "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done # echo "OVERWRITE_FILE = $THIS_ROOT_PATH" # if [[ $OVERWRITE_FILE == "y" ]]; then # rm $THIS_ROOT_PATH # echo "LINE 236 Overwriting and Downloading loginFile $THIS_ROOT_PATH" # curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html # set -e # fi if [[ $OVERWRITE_FILE == "y" ]]; then echo "OVERWRITE_FILE = $THIS_ROOT_PATH" rm $THIS_ROOT_PATH echo "LINE 206 Overwriting and Downloading loginFile $THIS_ROOT_PATH" else THIS_ROOT_PATH="${THIS_ROOT_PATH}_copy" echo "CREATE COPY FILE: = $THIS_ROOT_PATH" fi curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e else echo "241 Downloading loginFile $THIS_ROOT_PATH" curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e fi done echo "#################################" echo 'starting server' echo "#################################" #sleep 5 code . set -e set -e npm run dev set -e # import packages #sed -i '1 i\import axios from "axios";' Readme.md