#!/bin/bash # add-loginv2.sh (June 23, 2023 1825pm) # V1 5086 | V2 5168 # 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 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="y" if [[ $OVERWRITE_FILE == "y" ]]; then read -p "Do you want to install ${package} y/n: [n] " PACKAGE fi 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 and will have to add the code manually "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done echo "OVERWRITE_FILE = $OVERWRITE_FILE" 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 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 LOGIN_DIR="./src" if [ ! -d "$LOGIN_DIR" ]; then echo "$LOGIN_DIR doesnt exists, creating..." mkdir -p $LOGIN_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/$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 and will have to add the code manually "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done echo "OVERWRITE_FILE = $OVERWRITE_FILE" if [[ $OVERWRITE_FILE == "y" ]]; then rm $THIS_ROOT_PATH echo "LINE 127 Overwriting and Downloading loginFile $THIS_ROOT_PATH" curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e fi 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 LOGIN_DIR="src/components" if [ ! -d "$LOGIN_DIR" ]; then echo "$LOGIN_DIR doesnt exists, creating..." mkdir -p $LOGIN_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="$LOGIN_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 and will have to add the code manually "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done echo "OVERWRITE_FILE = $OVERWRITE_FILE" 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 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 LOGIN_DIR="src/views" if [ ! -d "$LOGIN_DIR" ]; then echo "$LOGIN_DIR doesnt exists, creating..." mkdir -p $LOGIN_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="$LOGIN_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 and will have to add the code manually "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done echo "OVERWRITE_FILE = $OVERWRITE_FILE" 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 else echo "207 Downloading loginFile $THIS_ROOT_PATH" curl -o $THIS_ROOT_PATH https://www.webune.com/forums/$ROOT_FILE.html set -e fi done # CONTEXT LOGIN_DIR="src/context" if [ ! -d "$LOGIN_DIR" ]; then echo "$LOGIN_DIR doesnt exists, creating..." mkdir -p $LOGIN_DIR set -e fi # DOWNLOAD CONTEXT PROVIDER ROOT_FILES=("ContextProvider.jsx") for ROOT_FILE in "${ROOT_FILES[@]}"; do OVERWRITE_FILE="" THIS_ROOT_PATH="$LOGIN_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 and will have to add the code manually "$'\n'"Delete? y/n [$OVERWRITE_FILE] " OVERWRITE_FILE set -e done echo "OVERWRITE_FILE = $OVERWRITE_FILE" 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 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