-
Notifications
You must be signed in to change notification settings - Fork 70
/
startdevenv.sh
63 lines (52 loc) · 2.18 KB
/
startdevenv.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
if [ -z ${NEXTJS_PORT+x} ]; then NEXTJS_PORT=3000; else echo "NEXTJS_PORT is set to $NEXTJS_PORT"; fi
if [ -z ${STRAPI_PORT+x} ]; then STRAPI_PORT=1337; else echo "STRAPI_PORT is set to $STRAPI_PORT"; fi
counter=0
watchdog=5
check_and_set_strapi_port() {
if lsof -Pi :$STRAPI_PORT -sTCP:LISTEN -t >/dev/null && [ "$counter" -lt $watchdog ]; then
echo "Strapi port $STRAPI_PORT already occupied, changing to the next consecutive port"
STRAPI_PORT=$((STRAPI_PORT+1))
counter=$((counter+1))
check_and_set_strapi_port
elif [ "$counter" -ge $watchdog ]; then
echo "\033[31m Unable to allocate an empty port for Strapi, the last tried port was $STRAPI_PORT\e[0m"
echo "Please either change the $STRAPI_PORT to an other random number or to an unused port number"
exit 1
else
echo "🚀 An empty port found for Strapi🚀"
fi
}
check_and_set_next_port() {
if lsof -Pi :$NEXTJS_PORT -sTCP:LISTEN -t >/dev/null && [ "$counter" -lt $watchdog ]; then
echo "NextJS port $NEXTJS_PORT already occupied, changing to the next consecutive port"
NEXTJS_PORT=$((NEXTJS_PORT+1))
counter=$((counter+1))
check_and_set_next_port
elif [ "$counter" -ge $watchdog ]; then
echo "\033[31mUnable to allocate an empty port for NextJS, the last tried port was $NEXTJS_PORT\e[0m"
echo "Please either change the $NEXTJS_PORT to an other random number/unused port number"
echo "After changes re-run the script"
exit 1
else
echo "🚀 An empty port found for NextJS 🚀"
fi
}
if ! docker info > /dev/null 2>&1; then
echo "Docker is not running, please start the Docker daemon and try again! 💪"
exit 1
fi
sh startBackend.sh $1
check_and_set_strapi_port
counter=0
check_and_set_next_port
export NEXT_PUBLIC_PORT=$NEXTJS_PORT
printf '\nNEXT_PUBLIC_STRAPI_API_URL'="http://127.0.0.1:$STRAPI_PORT" >> app/.env
printf '\nNEXT_PUBLIC_EVENT_SPK_MAIL'="dhgysfmedomihkzkwv@kvhrr.com" >> app/.env
sh strapi.sh $STRAPI_PORT > /dev/null 2>/dev/null &
cd app
export PORT=$NEXTJS_PORT
export NEXT_PUBLIC_PORT=$NEXTJS_PORT
npm i
sh ../showbrowser.sh $NEXTJS_PORT 2>/dev/null &
npm run dev