Skip to content

Commit d87eae1

Browse files
committed
Finished shell script rework
1 parent a35e766 commit d87eae1

2 files changed

Lines changed: 36 additions & 18 deletions

File tree

deploy.sh

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,43 @@
22

33
set -e
44

5+
usage() {
6+
cat <<EOF
7+
Usage: $0 ssh-server [options]
8+
9+
Options:
10+
-s, --skip-build Skip building. Use last local build
11+
-u, --skip-upload Skip building and uploading. Use unfinished server-side deployment
12+
-h, --help Show this help message
13+
EOF
14+
}
15+
516
error() {
617
echo "Error: $1" >&2
18+
[ -n "$3" ] && echo && usage
719
exit "${2:-1}"
820
}
921

1022
while [ "${1#-}" != "$1" ]; do
11-
for opt in $([ "${1#--}" = "$1" ] && tr "${1#-}" " " || echo "$1"); do
23+
for opt in $([ "${1#--}" = "$1" ] && echo "${1#-}" | grep -o . || echo "$1"); do
1224
case "$opt" in
1325
'--')
1426
shift
1527
break 2
1628
;;
1729
's' | '--skip-build')
18-
echo s
30+
skip_build=1
1931
;;
2032
'u' | '--skip-upload')
21-
echo u
33+
skip_build=1
34+
skip_upload=1
35+
;;
36+
'h' | '--help')
37+
usage
38+
exit 0
2239
;;
2340
*)
24-
error "unknown option: -$opt"
41+
error "unknown option: -$opt" 1 usage
2542
;;
2643
esac
2744
done
@@ -32,29 +49,31 @@ done
3249
case "$1" in
3350
*@*) ;;
3451
*)
35-
error "Please specify a valid ssh connection! (user@host)"
52+
error "Please specify a valid ssh connection! (user@host)" 1 usage
3653
;;
3754
esac
3855

3956
cd "$(dirname "$0")"
4057

41-
if [ "$2" != "--skip-build" ] && [ "$2" != "-s" ]; then
58+
if [ "$skip_build" != "1" ]; then
4259
npm run build
4360
printf '\n'
4461
fi
4562

46-
ssh "$1" /bin/sh <<'EOF'
47-
set -e
48-
rm -rf "$HOME/emexlabs"
63+
if [ "$skip_upload" != "1" ]; then
64+
ssh "$1" /bin/sh <<'EOF'
65+
set -e
66+
rm -rf "$HOME/emexlabs"
4967
EOF
5068

51-
scp -rC ./build "$1:~/emexlabs"
52-
53-
ssh "$1" /bin/sh <<'EOF'
54-
set -e
55-
find "$HOME/emexlabs" -type d -exec chmod 755 {} +
56-
find "$HOME/emexlabs" -type f -exec chmod 644 {} +
69+
scp -rC ./build "$1:~/emexlabs"
70+
71+
ssh "$1" /bin/sh <<'EOF'
72+
set -e
73+
find "$HOME/emexlabs" -type d -exec chmod 755 {} +
74+
find "$HOME/emexlabs" -type f -exec chmod 644 {} +
5775
EOF
76+
fi
5877

5978
# Bootstrap comparison
6079
set +e
@@ -71,8 +90,7 @@ if [ "$bootstrap_diff" -ne 0 ]; then
7190
printf 'Bootstrap check failed! Continue anyway? [y/N] '
7291
fi
7392
if [ ! -t 0 ]; then
74-
echo "No stdin. Exiting." >&2
75-
exit 2
93+
error "No stdin. Exiting." 2
7694
fi
7795
read -r response
7896
case "$response" in

quickstart.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cd "$(dirname "$0")" || error "Failed to change directory" $?
3737
chmod +x ./deploy.sh
3838

3939
install nodejs node
40-
install coreutils tr
40+
install grep grep
4141

4242
if ! npm list >/dev/null 2>&1; then
4343
npm install || error "npm failed to install required packages" $?

0 commit comments

Comments
 (0)