Skip to content

Commit 47086e4

Browse files
Update start.sh (#2147)
* Update start.sh - the codes cds into its folder which makes it possible to run script from any directory - saves the return code from previous commands to a variable and returns it at exit. Without saving the exit code into a variable exit $? return the return code of the echo statement which is always 0. * doc: add comment explaining why we cd into the parent folder in start.sh * set the parent of the script as current location --------- Co-authored-by: Pamela Fox <[email protected]>
1 parent 829a5ed commit 47086e4

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

app/start.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# set the parent of the script as the current location.
2+
Set-Location $PSScriptRoot
3+
14
Write-Host ""
25
Write-Host "Loading azd .env file from current environment"
36
Write-Host ""

app/start.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/sh
22

3+
# cd into the parent directory of the script,
4+
# so that the script generates virtual environments always in the same path.
5+
cd "${0%/*}" || exit 1
6+
37
cd ../
48
echo 'Creating python virtual environment ".venv"'
59
python3 -m venv .venv
@@ -9,9 +13,10 @@ echo "Restoring backend python packages"
913
echo ""
1014

1115
./.venv/bin/python -m pip install -r app/backend/requirements.txt
12-
if [ $? -ne 0 ]; then
16+
out=$?
17+
if [ $out -ne 0 ]; then
1318
echo "Failed to restore backend python packages"
14-
exit $?
19+
exit $out
1520
fi
1621

1722
echo ""
@@ -20,19 +25,21 @@ echo ""
2025

2126
cd app/frontend
2227
npm install
23-
if [ $? -ne 0 ]; then
28+
out=$?
29+
if [ $out -ne 0 ]; then
2430
echo "Failed to restore frontend npm packages"
25-
exit $?
31+
exit $out
2632
fi
2733

2834
echo ""
2935
echo "Building frontend"
3036
echo ""
3137

3238
npm run build
33-
if [ $? -ne 0 ]; then
39+
out=$?
40+
if [ $out -ne 0 ]; then
3441
echo "Failed to build frontend"
35-
exit $?
42+
exit $out
3643
fi
3744

3845
echo ""
@@ -44,7 +51,8 @@ cd ../backend
4451
port=50505
4552
host=localhost
4653
../../.venv/bin/python -m quart --app main:app run --port "$port" --host "$host" --reload
47-
if [ $? -ne 0 ]; then
54+
out=$?
55+
if [ $out -ne 0 ]; then
4856
echo "Failed to start backend"
49-
exit $?
57+
exit $out
5058
fi

0 commit comments

Comments
 (0)