|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +clear |
| 4 | + |
| 5 | +# Status indicator |
| 6 | +echo -e "-=|[ Lara-Stacker |> CREATE RAW ]|=-\n" |
| 7 | + |
| 8 | +# * =========== |
| 9 | +# * Validation |
| 10 | +# * ========= |
| 11 | + |
| 12 | +# Check if prompt function exists and source it |
| 13 | +function_path="./scripts/functions/prompt.sh" |
| 14 | +if [[ ! -f $function_path ]]; then |
| 15 | + echo -e "Error: Working directory isn't the script's main.\n" |
| 16 | + |
| 17 | + echo -e "Tip: Maybe run [cd ~/Downloads/lara-stacker/ && sudo ./lara-stacker.sh] commands.\n" |
| 18 | + |
| 19 | + echo -n "Press any key to exit..." |
| 20 | + read whatever |
| 21 | + |
| 22 | + clear |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | +source $function_path |
| 26 | + |
| 27 | +# Ensure the script isn't ran directly |
| 28 | +if [[ -z "$RAN_MAIN_SCRIPT" ]]; then |
| 29 | + prompt "Aborted for direct execution flow." "Please use the main [lara-stacker.sh] script." true false |
| 30 | +fi |
| 31 | + |
| 32 | +# Confirm if setup script isn't run |
| 33 | +if [ ! -e "$PWD/done-setup.flag" ]; then |
| 34 | + echo -n "Setup script isn't run yet. Are you sure you want to continue? (y/n) " |
| 35 | + read confirmation |
| 36 | + |
| 37 | + case "$confirmation" in |
| 38 | + n|N|no|No|NO|nope|Nope|NOPE) |
| 39 | + echo -e "\nAborting...\n" |
| 40 | + |
| 41 | + echo -n "Press any key to continue..." |
| 42 | + read whatever |
| 43 | + |
| 44 | + clear |
| 45 | + exit 1 |
| 46 | + ;; |
| 47 | + esac |
| 48 | +fi |
| 49 | + |
| 50 | +# * ============ |
| 51 | +# * Preparation |
| 52 | +# * ========== |
| 53 | + |
| 54 | +# Get environment variables and defaults |
| 55 | +lara_stacker_dir=$PWD |
| 56 | +source $lara_stacker_dir/.env |
| 57 | + |
| 58 | +# Setting the echoing level |
| 59 | +conditional_quiet="--quiet" |
| 60 | +cancel_suppression=false |
| 61 | +case $LOGGING_LEVEL in |
| 62 | +# Notifications Only |
| 63 | +1) |
| 64 | + exec 3>&1 |
| 65 | + exec > /dev/null 2>&1 |
| 66 | + ;; |
| 67 | +# Notifications + Errors + Warnings |
| 68 | +2) |
| 69 | + exec 3>&1 |
| 70 | + exec > /dev/null |
| 71 | + ;; |
| 72 | +# Everything |
| 73 | +*) |
| 74 | + exec 3>&1 |
| 75 | + conditional_quiet="" |
| 76 | + cancel_suppression=true |
| 77 | + ;; |
| 78 | +esac |
| 79 | + |
| 80 | +# * ================= |
| 81 | +# * Collecting Input |
| 82 | +# * =============== |
| 83 | + |
| 84 | +# Get the project path from the user |
| 85 | +echo -ne "Enter the full project path (e.g., /home/$USERNAME/Code/my_project): " >&3 |
| 86 | +read full_directory |
| 87 | + |
| 88 | +full_directory="${full_directory%/}" |
| 89 | +project_path=$(dirname "$full_directory") |
| 90 | +project_name=$(basename "$full_directory") |
| 91 | + |
| 92 | +# Cancel if the project path directory doesn't exists |
| 93 | +if [ ! -d "$project_path" ]; then |
| 94 | + prompt "\nThe project containing path doesn't exist!" "Raw project creation cancelled." |
| 95 | +fi |
| 96 | + |
| 97 | +# Cancel if the project directory already exists |
| 98 | +if [ -d "$project_path/$project_name" ]; then |
| 99 | + prompt "\nProject folder already exist within the previously given path!" "Raw project creation cancelled." |
| 100 | +fi |
| 101 | + |
| 102 | +# * ================= |
| 103 | +# * Project Creation |
| 104 | +# * =============== |
| 105 | + |
| 106 | +# Create the Laravel raw project in the provided path and folder |
| 107 | +echo -e "\nInstalling the project via Composer..." >&3 |
| 108 | + |
| 109 | +cd $project_path/ |
| 110 | +composer create-project --prefer-dist laravel/laravel $project_name -n $conditional_quiet |
| 111 | + |
| 112 | +# Enforce permissions |
| 113 | +sudo $lara_stacker_dir/scripts/helpers/permit.sh $project_path/$project_name |
| 114 | + |
| 115 | +cd $project_path/$project_name |
| 116 | + |
| 117 | +sed -i "s/APP_NAME=Laravel/APP_NAME=\"$project_name\"/g" ./.env |
| 118 | + |
| 119 | +echo -e "\nCreated and named the raw Laravel application." >&3 |
| 120 | + |
| 121 | +# Set up launch.json for debugging (Xdebug) |
| 122 | +mkdir $project_path/$project_name/.vscode |
| 123 | +cd $project_path/$project_name/.vscode |
| 124 | + |
| 125 | +sudo cp $lara_stacker_dir/files/.vscode/launch.json ./ |
| 126 | + |
| 127 | +sed -i "s~\[projectsDirectory\]~$project_path~g" ./launch.json |
| 128 | +sed -i "s~\[projectName\]~$project_name~g" ./launch.json |
| 129 | + |
| 130 | +echo -e "\nConfigured VSC debug settings for Xdebug support." >&3 |
| 131 | + |
| 132 | +# * ======== |
| 133 | +# * The End |
| 134 | +# * ====== |
| 135 | + |
| 136 | +# Enforce permissions |
| 137 | +sudo $lara_stacker_dir/scripts/helpers/permit.sh $project_path/$project_name |
| 138 | + |
| 139 | +echo -e "\nUpdated directory and file permissions all around." >&3 |
| 140 | + |
| 141 | +# Display a success message |
| 142 | +echo -e "\nRaw project created successfully! Run [art serve] from within its directory for launch.\n" >&3 |
| 143 | + |
| 144 | +echo -n "Press any key to continue..." >&3 |
| 145 | +read whatever |
| 146 | + |
| 147 | +clear >&3 |
0 commit comments