Skip to content

Commit

Permalink
[v4.1.0] Blended the notification system with helper functions (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodM4ven committed May 8, 2024
2 parents 38c79e0 + abd1e97 commit 83e0b4f
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ LOGGING_LEVEL=1 # 1 = notifications only | 2 = 1 + errors + warnings | 3 = every
USERNAME=<your-username>
DB_PASSWORD=<your-password>
OPINIONATED=true
EXPOSE_TOKEN="" # Installed when provided
EXPOSE_TOKEN="" # Installed when provided
13 changes: 8 additions & 5 deletions lara-stacker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [[ "$is_updateable" == true ]]; then
current_version=$(git log --pretty=format:'%s' | grep -o '\[v[0-9]*\.[0-9]*\.[0-9]*\]' | head -1 | tr -d '[]')
fi

echo -e "-=|[ LARA-STACKER $current_version ]|=-\n"
echo -e "-=|[ LARA-STACKER $current_version ]|=-"

# * ===========
# * Validation
Expand All @@ -34,9 +34,9 @@ echo -e "-=|[ LARA-STACKER $current_version ]|=-\n"

prompt_function_dir="./scripts/functions/helpers/prompt.sh"
if [[ ! -f $prompt_function_dir ]]; then
echo -e "Error: Working directory isn't the script's main.\n"
echo -e "\nError: Working directory isn't the script's main.\n"

echo -e "Tip: Maybe run [cd ~/Downloads/lara-stacker/ && sudo ./lara-stacker.sh] commands.\n"
echo -e "Tip: Maybe [cd ~/Downloads/lara-stacker/ && sudo ./lara-stacker.sh] instead.\n"

echo -n "Press any key to exit..."
read whatever
Expand Down Expand Up @@ -65,9 +65,12 @@ fi
placeholders=("<your-username>" "<your-password>")

while IFS= read -r line; do
# ? Skip comments and empty lines
[[ "$line" =~ ^#.*$ || "$line" == "" ]] && continue

for placeholder in "${placeholders[@]}"; do
if [[ "$line" == *"$placeholder"* ]]; then
prompt "Aborted because [.env] file contains a placeholder." "Please replace placeholders with values."
prompt "Aborted because [.env] file contains a placeholder: '$placeholder'." "Please replace placeholders with values."
fi
done
done < "./.env"
Expand Down Expand Up @@ -108,7 +111,7 @@ if [[ -f "/tmp/updated-lara-stacker.flag" ]]; then
rm /tmp/updated-lara-stacker.flag
fi

echo -en "Checking for updates"
echo -en "\nChecking for updates"
sleep 1
echo -en "."
sleep 1
Expand Down
32 changes: 20 additions & 12 deletions scripts/TALL/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
clear

# * Display a status indicator
echo -e "-=|[ Lara-Stacker |> TALL Projects Management |> CREATE ]|=-\n"
echo -e "-=|[ Lara-Stacker |> TALL Projects Management |> CREATE ]|=-"

# * ===========
# * Validation
Expand Down Expand Up @@ -75,28 +75,30 @@ fi
projects_directory=/var/www/html

# ? Get the project name from the user
echo -ne "Enter the project name: " >&3
echo -ne "\nEnter the project name: " >&3
read project_name

escaped_project_name=$(echo "$project_name" | tr ' ' '-' | tr '_' '-' | tr '[:upper:]' '[:lower:]')
escaped_project_name=${escaped_project_name// /}

# ? Abort if the project directory already exists
if [ -d "$projects_directory/$escaped_project_name" ]; then
prompt "Project folder already exists!" "Project creation cancelled."
prompt "Project folder already exists!" "Project creation cancelled." $cancel_suppression
fi

# * ===============
# * Initialization
# * =============

# ? Source the procedural function scripts now
sourcer "apacheUp"
sourcer "viteUp"
sourcer "mysqlUp"
sourcer "minioUp"
sourcer "workspaceUp"
sourcer "xdebugUp"
sourcer "apacheUp" $cancel_suppression
sourcer "viteUp" $cancel_suppression
sourcer "mysqlUp" $cancel_suppression
sourcer "memcachedUp" $cancel_suppression
sourcer "mailpitUp" $cancel_suppression
sourcer "minioUp" $cancel_suppression
sourcer "workspaceUp" $cancel_suppression
sourcer "xdebugUp" $cancel_suppression

# ? =====================================================
# ? Create the Laravel project in the projects directory
Expand All @@ -119,6 +121,12 @@ viteUp $escaped_project_name
# ? Generate a MySQL database if doesn't exit
mysqlUp $escaped_project_name

# ? Configure Memcached to replace Redis
memcachedUp $escaped_project_name

# ? Configure Mailpit to replace log mailer driver
mailpitUp $escaped_project_name

# ? Set up launch.json for debugging (Xdebug), if VSC is used
xdebugUp $USING_VSC $escaped_project_name

Expand All @@ -133,20 +141,20 @@ cd $projects_directory/$escaped_project_name

# TODO Install vpremiss/tall-stacker package manager via Composer when it's ready -_-"

if [ -n "$EXPOSE_TOKEN" ]; then
if [[ -n "$EXPOSE_TOKEN" ]]; then
# ? Modify the TrustProxies middleware to work with Expose
sed -i -E ':a;N;$!ba;s/(->withMiddleware\(function \(Middleware \$middleware\) \{\n\s*)\/\/(\n\s*\})/\1\$middleware->trustProxies(at: \x27*\x27); \2/g' ./bootstrap/app.php

echo -e "\nTrusted all proxies for Expose compatibility." >&3
fi

if [ "$OPINIONATED" == true ]; then
if [[ "$OPINIONATED" == true ]]; then
# ? Apply Prettier config
sudo cp $lara_stacker_dir/files/.opinionated/.prettierrc ./.prettierrc

echo -e "\nCopied an opinionated Prettier config file to the project." >&3

if [ "$USING_VSC" == true ]; then
if [[ "$USING_VSC" == true ]]; then
# ? Create a dedicated VSC workspace in Desktop
workspaceUp $escaped_project_name
fi
Expand Down
12 changes: 6 additions & 6 deletions scripts/TALL/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
clear

# * Display a status indicator
echo -e "-=|[ Lara-Stacker |> TALL Projects Management |> DELETE ]|=-\n"
echo -e "-=|[ Lara-Stacker |> TALL Projects Management |> DELETE ]|=-"

# * ===========
# * Validation
Expand Down Expand Up @@ -73,11 +73,11 @@ fi
# * ====

# ? Source the procedural function scripts now
sourcer "apacheDown"
sourcer "mysqlDown"
sourcer "apacheDown" $cancel_suppression
sourcer "mysqlDown" $cancel_suppression

# ? Get the project name from the user
echo -n "Enter the project name: " >&3
echo -ne "\nEnter the project name: " >&3
read project_name

escaped_project_name=$(echo "$project_name" | tr ' ' '-' | tr '_' '-' | tr '[:upper:]' '[:lower:]')
Expand All @@ -87,7 +87,7 @@ projects_directory=/var/www/html

# ? Check if the project doesn't exist
if ! [ -d "$projects_directory/$escaped_project_name" ]; then
prompt "Project \"$escaped_project_name\" doesn't exist."
prompt "Project \"$escaped_project_name\" doesn't exist." "" $cancel_suppression
fi

# * ========
Expand All @@ -106,7 +106,7 @@ if [[ $USING_VSC == true && $OPINIONATED == true ]]; then
fi

# ? Delete the Apache site
apacheDown $escaped_project_name
apacheDown $escaped_project_name $cancel_suppression

# ? Drop its MySQL database if it exists
mysqlDown $escaped_project_name
Expand Down
40 changes: 24 additions & 16 deletions scripts/TALL/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
clear

# * Display a status indicator
echo -e "-=|[ Lara-Stacker |> TALL Projects Management |> IMPORT ]|=-\n"
echo -e "-=|[ Lara-Stacker |> TALL Projects Management |> IMPORT ]|=-"

# * ===========
# * Validation
Expand Down Expand Up @@ -73,7 +73,7 @@ fi
# * ====

# ? Get the project path from the user
echo -ne "Enter the full project path (e.g., /home/$USERNAME/Code/some_laravel_app): " >&3
echo -ne "\nEnter the full project path (e.g., /home/$USERNAME/Code/some_laravel_app): " >&3
read full_directory

full_directory="${full_directory%/}"
Expand All @@ -82,7 +82,7 @@ project_name=$(basename "$full_directory")

# ? Cancel if the project path doesn't exists
if [ ! -d "$project_path/$project_name" ]; then
prompt "The project path doesn't exist!" "Project importing cancelled."
prompt "The project path doesn't exist!" "Project importing cancelled." $cancel_suppression
fi

escaped_project_name=$(echo "$project_name" | tr ' ' '-' | tr '_' '-' | tr '[:upper:]' '[:lower:]')
Expand All @@ -92,20 +92,22 @@ projects_directory=/var/www/html

# ? Cancel if the project already exists
if [ -d "$projects_directory/$escaped_project_name" ]; then
prompt "A project with the same name already exists!" "Project importing cancelled."
prompt "A project with the same name already exists!" "Project importing cancelled." $cancel_suppression
fi

# * ===============
# * Initialization
# * =============

# ? Source the procedural function scripts now
sourcer "apacheUp"
sourcer "viteUp"
sourcer "mysqlUp"
sourcer "minioUp"
sourcer "workspaceUp"
sourcer "xdebugUp"
sourcer "apacheUp" $cancel_suppression
sourcer "viteUp" $cancel_suppression
sourcer "mysqlUp" $cancel_suppression
sourcer "memcachedUp" $cancel_suppression
sourcer "mailpitUp" $cancel_suppression
sourcer "minioUp" $cancel_suppression
sourcer "workspaceUp" $cancel_suppression
sourcer "xdebugUp" $cancel_suppression

# ? ============================================
# ? Make a copy of the project in the directory
Expand All @@ -118,14 +120,20 @@ sudo $lara_stacker_dir/scripts/helpers/permit.sh $projects_directory/$escaped_pr
echo -e "\nThe project folder has been copied to "$projects_directory" directory." >&3

# ? Create the Apache site
apacheUp $escaped_project_name $cancel_suppression true true
apacheUp $escaped_project_name $cancel_suppression true

# ? Link the site to Vite's configuration
viteUp $escaped_project_name

# ? Generate a MySQL database if doesn't exit
mysqlUp $escaped_project_name

# ? Configure Memcached to replace Redis
memcachedUp $escaped_project_name

# ? Configure Mailpit to replace log mailer driver
mailpitUp $escaped_project_name

# ? Set up launch.json for debugging (Xdebug), if VSC is used
xdebugUp $USING_VSC $escaped_project_name

Expand All @@ -140,22 +148,22 @@ cd $projects_directory/$escaped_project_name

# TODO Install TALL-STACKER package manager via Composer

if [ -n "$EXPOSE_TOKEN" ]; then
if [[ -n "$EXPOSE_TOKEN" ]]; then
# ? Modify the TrustProxies middleware to work with Expose
sed -i "s/protected \$proxies;/protected \$proxies = '*';/g" ./app/Http/Middleware/TrustProxies.php
sed -i -E ':a;N;$!ba;s/(->withMiddleware\(function \(Middleware \$middleware\) \{\n\s*)\/\/(\n\s*\})/\1\$middleware->trustProxies(at: \x27*\x27); \2/g' ./bootstrap/app.php

echo -e "\nTrusted all proxies for Expose compatibility." >&3
fi

if [ "$OPINIONATED" == true ]; then
if [ ! -f "./.prettierrc" ]; then
if [[ "$OPINIONATED" == true ]]; then
if [[ ! -f "./.prettierrc" ]]; then
# ? Apply Prettier config
sudo cp $lara_stacker_dir/files/.opinionated/.prettierrc ./.prettierrc

echo -e "\nCopied an opinionated Prettier config file to the project." >&3
fi

if [ "$USING_VSC" == true]; then
if [[ "$USING_VSC" == true ]]; then
# ? Create a dedicated VSC workspace in Desktop
workspaceUp $escaped_project_name
fi
Expand Down
4 changes: 3 additions & 1 deletion scripts/TALL/list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
clear

# * Display a status indicator
echo -e "-=|[ Lara-Stacker |> TALL Projects Management |> LIST ]|=-\n"
echo -e "-=|[ Lara-Stacker |> TALL Projects Management |> LIST ]|=-"

# * ===========
# * Validation
Expand Down Expand Up @@ -38,6 +38,8 @@ source $lara_stacker_dir/.env
# * Process
# * ======

echo

# ? ===========================================
# ? Count and list directories and their names
# ? =========================================
Expand Down
8 changes: 4 additions & 4 deletions scripts/apache/disable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
clear

# * Display a status indicator
echo -e "-=|[ Lara-Stacker |> Apache Site Management |> DISABLE ]|=-\n"
echo -e "-=|[ Lara-Stacker |> Apache Site Management |> DISABLE ]|=-"

# * ===========
# * Validation
Expand Down Expand Up @@ -67,14 +67,14 @@ esac
# * ======

# ? Source the procedural function scripts now
sourcer "apacheDown"
sourcer "apacheDown" $cancel_suppression

# ? Get the site name
echo -ne "Enter the site name: " >&3
echo -ne "\nEnter the site name: " >&3
read site_name

# ? Take the Apache site down if it exists
apacheDown $site_name
apacheDown $site_name $cancel_suppression

# * ========
# * The End
Expand Down
8 changes: 4 additions & 4 deletions scripts/apache/enable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
clear

# * Display a status indicator
echo -e "-=|[ Lara-Stacker |> Apache Site Management |> ENABLE ]|=-\n"
echo -e "-=|[ Lara-Stacker |> Apache Site Management |> ENABLE ]|=-"

# * ===========
# * Validation
Expand Down Expand Up @@ -67,14 +67,14 @@ esac
# * ======

# ? Source the procedural function scripts now
sourcer "apacheUp"
sourcer "apacheUp" $cancel_suppression

# ? Get the site name
echo -ne "Enter the site name: " >&3
echo -ne "\nEnter the site name: " >&3
read site_name

# ? Host the Apache site if it doesn't exist
apacheUp $site_name $cancel_suppression false
apacheUp $site_name $cancel_suppression

# * ========
# * The End
Expand Down
4 changes: 3 additions & 1 deletion scripts/apache/list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
clear

# * Display a status indicator
echo -e "-=|[ Lara-Stacker |> Apache Site Management |> LIST ]|=-\n"
echo -e "-=|[ Lara-Stacker |> Apache Site Management |> LIST ]|=-"

# * ===========
# * Validation
Expand Down Expand Up @@ -36,6 +36,8 @@ fi
# * Process
# * ======

echo ""

# ? ========================================================================
# ? List the sites - omitting the default - and display their Apache status
# ? ======================================================================
Expand Down
Loading

0 comments on commit 83e0b4f

Please sign in to comment.