Skip to content

Commit 98ff349

Browse files
committed
feat : initial commit
Install, uninstall and create-laravel-app script
0 parents  commit 98ff349

File tree

6 files changed

+323
-0
lines changed

6 files changed

+323
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Yann
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# create-laravel-app
2+
Create laravel app with Laravel Sail by using command line

create-laravel-app

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#!/bin/bash
2+
3+
VERSION="1.0.0-beta.1"
4+
5+
CYAN="\033[36m"
6+
GREEN="\033[32m"
7+
RED="\033[31m"
8+
YELLOW="\033[33m"
9+
WHITE="\033[37m"
10+
11+
NC="\033[0m"
12+
BOLD='\033[1m'
13+
14+
if [[ $1 == "-h" || $1 == "--help" ]]; then
15+
16+
echo ""
17+
echo ""
18+
echo "-- Create Laravel app ($VERSION) --"
19+
echo ""
20+
echo ""
21+
echo "Usage: create-laravel-app [options]"
22+
echo ""
23+
echo "Create a new Laravel app with the given services"
24+
echo ""
25+
26+
echo "By run this script in terminal you will create a laravel app in your current directory or in a specified directory."
27+
echo ""
28+
29+
echo "Please provide one or more of the supported services (mysql, pgsql, mariadb, redis, memcached, meilisearch, minio, mailpit, selenium, soketi)."
30+
echo ""
31+
32+
echo "If you do not specify which services you would like configured, a default stack of mysql, redis, meilisearch, mailpit, and selenium will be configured."
33+
echo ""
34+
35+
echo "It use this enpoints to get the docker compose file and the sail file : https://laravel.build/app-name?with=service1,service2,service3"
36+
echo ""
37+
38+
echo "Options:"
39+
echo " -h, --help"
40+
echo " -v, --version"
41+
echo " -d, --directory"
42+
echo " -s, --services"
43+
echo " -n, --name"
44+
echo " -y, -Y, --yes (autostart)"
45+
echo ""
46+
return 0
47+
48+
fi
49+
50+
if [[ $1 == "-v" || $1 == "--version" ]]; then
51+
printf "\nCreate Laravel app by \e]8;;https://github.com/YannBirba\e\\@YannBirba\e]8;;\e\ version %s \n" "$VERSION"
52+
return 0
53+
fi
54+
55+
# -----------------------------------------------------------------------------------
56+
57+
# Ensure that Docker is running...
58+
if ! docker info >/dev/null 2>&1; then
59+
echo ""
60+
echo -e "${BOLD}${RED}✕ Docker is not running ✕${NO_BG}"
61+
echo ""
62+
echo -e "${GREEN}${YELLOW}Please start Docker and try again.${NC}"
63+
echo ""
64+
return 1
65+
fi
66+
67+
# -----------------------------------------------------------------------------------
68+
69+
name=""
70+
dir="."
71+
services="none"
72+
auto_start="n"
73+
74+
available_services=("mysql" "pgsql" "mariadb" "redis" "memcached" "meilisearch" "minio" "mailpit" "selenium" "soketi")
75+
services_available="${available_services[*]}"
76+
services_available="${services_available// /, }"
77+
78+
while [[ $# -gt 0 ]]; do
79+
key="$1"
80+
case $key in
81+
-n | --name)
82+
name="$2"
83+
shift
84+
shift
85+
;;
86+
-d | --directory)
87+
dir="$2"
88+
shift
89+
shift
90+
;;
91+
-s | --services)
92+
services="$2"
93+
shift
94+
shift
95+
;;
96+
-y | -Y | --yes)
97+
auto_start="yes"
98+
shift
99+
;;
100+
*)
101+
shift
102+
;;
103+
esac
104+
done
105+
106+
if [[ -z "$services" ]]; then
107+
services="none"
108+
fi
109+
110+
if [[ -z "$name" ]]; then
111+
echo ""
112+
echo "↪ Please provide a name for your app"
113+
echo ""
114+
return 1
115+
fi
116+
117+
if [[ $services != "none" ]]; then
118+
for service in $(
119+
services_list=$services
120+
echo "${services_list//,/ }"
121+
); do
122+
if [[ ! " ${available_services[*]} " =~ " ${service} " ]]; then
123+
echo ""
124+
printf "${BOLD}${YELLOW}↪ Service \"%s\" is not available, available services: \e]8;;https://laravel.com/docs/10.x/installation#choosing-your-sail-services\e\\%s\e]8;;\e\ .${NC}" "$service" "$services_available"
125+
echo "[$(date)] -- Service \"$service\" is not available, available services: $services_available ." >>/var/log/create-laravel-app.log
126+
echo ""
127+
return 1
128+
fi
129+
done
130+
fi
131+
132+
if [[ $dir == "." ]]; then
133+
dir=$(pwd)
134+
app_dir="$dir/$name"
135+
else
136+
if [[ ! -d $dir ]]; then
137+
mkdir "$dir"
138+
cd "$dir" || return 1
139+
app_dir="$dir/$name"
140+
else
141+
echo ""
142+
echo -e "${RED}${BOLD}Directory $dir already exists ${NC}"
143+
echo ""
144+
return 1
145+
fi
146+
fi
147+
148+
if [[ $services == "none" ]]; then
149+
echo ""
150+
printf "Creating Laravel app named %s with \e]8;;https://laravel.com/docs/10.x/installation#choosing-your-sail-services\e\\default services\e]8;;\e\ in %s" "$name" "$app_dir"
151+
echo ""
152+
echo "[$(date)] -- Create Laravel app ($VERSION) : named $name with default services on $app_dir" >>/var/log/create-laravel-app.log
153+
154+
if ! curl -s https://laravel.build/"$name" | bash; then
155+
echo ""
156+
echo -e "${RED}${BOLD}↪ An error occured while creating the app ${NC}"
157+
echo ""
158+
echo "[$(date)] -- An error occured while creating the app" >>/var/log/create-laravel-app.log
159+
return 1
160+
fi
161+
return 0
162+
else
163+
echo ""
164+
echo "Creating Laravel app named $name with $services in $app_dir"
165+
echo ""
166+
echo "[$(date)] -- Create Laravel app ($VERSION) : named $name with $services on $app_dir" >>/var/log/create-laravel-app.log
167+
168+
if ! curl -s https://laravel.build/"$name"\?with="$services" | bash; then
169+
echo ""
170+
echo -e "${RED}${BOLD}↪ An error occured while creating the app ${NC}"
171+
echo ""
172+
echo "[$(date)] -- An error occured while creating the app" >>/var/log/create-laravel-app.log
173+
return 1
174+
fi
175+
fi
176+
177+
echo ""
178+
printf "${GREEN}${BOLD}✓ App created successfully created in : \e]8;;code %s\e\\%s\e]8;;\e\ .${NC}" "$app_dir" "$app_dir"
179+
echo ""
180+
181+
cd "$name" || return 1
182+
183+
if [[ $auto_start == "yes" ]]; then
184+
./vendor/bin/sail up
185+
else
186+
echo -e "${BOLD}${CYAN}Your app is ready! Build something amazing.${NC}"
187+
echo ""
188+
echo -e "${BOLD}${WHITE}Would you like to run the app now? ${YELLOW}[Y/n]${NC}"
189+
read -r run_app
190+
191+
if [[ $run_app == "Y" || $run_app == "y" || $run_app == "" ]]; then
192+
./vendor/bin/sail up
193+
fi
194+
fi

install.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
GREEN="\033[32m"
4+
5+
NC="\033[0m"
6+
BOLD='\033[1m'
7+
8+
sudo cp ./create-laravel-app /usr/bin
9+
sudo touch /var/log/create-laravel-app.log
10+
11+
sudo chmod +x /usr/bin/create-laravel-app
12+
13+
sudo chown "$USER" /var/log/create-laravel-app.log
14+
15+
sudo chmod +x ./uninstall.sh
16+
17+
if [[ -f ~/.zshrc ]]; then
18+
19+
if [[ $(grep -c "alias cla" ~/.zshrc) -eq 0 ]]; then
20+
echo $'alias cla="source create-laravel-app"' >>~/.zshrc
21+
fi
22+
23+
if [[ $(grep -c "alias create-laravel-app" ~/.zshrc) -eq 0 ]]; then
24+
echo $'alias create-laravel-app="source create-laravel-app"' >>~/.zshrc
25+
fi
26+
27+
echo ""
28+
echo -e "${GREEN}${BOLD}↪ Install completed !${NC}"
29+
exec zsh
30+
31+
elif [[ -f ~/.bashrc ]]; then
32+
33+
if [[ $(grep -c "alias cla" ~/.bashrc) -eq 0 ]]; then
34+
echo $'alias cla="source create-laravel-app"' >>~/.bashrc
35+
fi
36+
37+
if [[ $(grep -c "alias create-laravel-app" ~/.bashrc) -eq 0 ]]; then
38+
echo $'alias create-laravel-app="source create-laravel-app"' >>~/.bashrc
39+
fi
40+
41+
echo ""
42+
echo -e "${GREEN}${BOLD}↪ Install completed !${NC}"
43+
exec zsh
44+
fi

uninstall.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
GREEN="\033[32m"
4+
YELLOW="\033[33m"
5+
6+
NC="\033[0m"
7+
BOLD='\033[1m'
8+
9+
if sudo rm /usr/bin/create-laravel-app; then
10+
echo ""
11+
echo -e "${BOLD}↪ create-laravel-app succesfully deleted from /usr/bin !${NC}"
12+
13+
else
14+
echo ""
15+
echo -e "${YELLOW}${BOLD}↪ Skipped ! File is maybe not existing.${NC}"
16+
echo ""
17+
fi
18+
19+
if sudo rm /var/log/create-laravel-app.log; then
20+
echo ""
21+
echo -e "${BOLD}↪ create-laravel-app.log succesfully deleted from /var/log !${NC}"
22+
echo ""
23+
else
24+
echo ""
25+
echo -e "${YELLOW}${BOLD}↪ Skipped ! File is maybe not existing.${NC}"
26+
echo ""
27+
fi
28+
29+
if [[ -f ~/.zshrc ]]; then
30+
31+
if [[ $(grep -c "alias cla" ~/.zshrc) -eq 1 ]]; then
32+
sed -i "s/alias cla=\"source create-laravel-app\"//g" ~/.zshrc
33+
# remove empty line
34+
sed -i '/^$/d' ~/.zshrc
35+
fi
36+
37+
if [[ $(grep -c "alias create-laravel-app" ~/.zshrc) -eq 1 ]]; then
38+
sed -i "s/alias create-laravel-app=\"source create-laravel-app\"//g" ~/.zshrc
39+
sed -i '/^$/d' ~/.zshrc
40+
fi
41+
42+
echo -e "${GREEN}${BOLD}↪ Uninstall completed !${NC}"
43+
exec zsh
44+
45+
elif [[ -f ~/.bashrc ]]; then
46+
47+
if [[ $(grep -c "alias cla" ~/.bashrc) -eq 1 ]]; then
48+
sed -i "s/alias cla=\"source create-laravel-app\"//g" ~/.bashrc
49+
sed -i '/^$/d' ~/.bashrc
50+
fi
51+
52+
if [[ $(grep -c "alias create-laravel-app" ~/.bashrc) -eq 1 ]]; then
53+
sed -i "s/alias create-laravel-app=\"source create-laravel-app\"//g" ~/.bashrc
54+
sed -i '/^$/d' ~/.bashrc
55+
fi
56+
57+
echo -e "${GREEN}${BOLD}↪ Uninstall completed !${NC}"
58+
exec bash
59+
60+
fi

0 commit comments

Comments
 (0)