Commit | Line | Data |
---|---|---|
5b461c35 KS |
1 | #!/bin/bash |
2 | # shellcheck disable=SC2103 | |
3 | # | |
4 | # Copyright (C) 2022 Kienan Stewart <kstewart@efficios.com> | |
5 | # | |
6 | # This program is free software: you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation, either version 3 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | set -exu | |
20 | ||
8fa2f091 MJ |
21 | print_header() { |
22 | set +x | |
23 | ||
24 | local message=" $1 " | |
25 | local message_len | |
26 | local padding_len | |
27 | ||
28 | message_len="${#message}" | |
29 | padding_len=$(( (80 - (message_len)) / 2 )) | |
30 | ||
31 | printf '\n'; printf -- '#%.0s' {1..80}; printf '\n' | |
32 | printf -- '-%.0s' {1..80}; printf '\n' | |
33 | printf -- '#%.0s' $(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $(seq 1 $padding_len); printf '\n' | |
34 | printf -- '-%.0s' {1..80}; printf '\n' | |
35 | printf -- '#%.0s' {1..80}; printf '\n\n' | |
36 | ||
37 | set -x | |
38 | } | |
39 | ||
bdee76c2 KS |
40 | # Fail early if not set |
41 | echo "Deploy target: ${DEPLOY_TARGET}" | |
42 | ||
5b461c35 KS |
43 | # Add ssh key for deployment |
44 | cp "$HOST_PUBLIC_KEYS" ~/.ssh/known_hosts | |
45 | cp "$KEY_FILE_VARIABLE" ~/.ssh/id_rsa | |
46 | ||
8fa2f091 | 47 | export DEBIAN_FRONTEND=noninteractive |
00c49046 KS |
48 | apt-get update |
49 | ||
8fa2f091 | 50 | print_header "Install web tooling dependencies" |
00c49046 | 51 | apt-get install --no-install-recommends -y npm |
5b461c35 | 52 | ./bootstrap-ubuntu.sh |
8fa2f091 MJ |
53 | |
54 | print_header "Install NPM stuff" | |
5b461c35 KS |
55 | npm install |
56 | ||
8fa2f091 | 57 | print_header "Build website with grunt" |
5b461c35 KS |
58 | grunt build:dev --verbose |
59 | grunt deploy:pre --verbose | |
60 | ||
61 | grunt build:prod --verbose | |
00c49046 KS |
62 | |
63 | # Check for broken internal links | |
8fa2f091 | 64 | print_header "Check links" |
00c49046 KS |
65 | apt-get install -y linkchecker |
66 | grunt connect:prod watch:prod & | |
67 | SERVER_PID="${!}" | |
68 | sleep 10 # While serve:prod starts up | |
8fa2f091 MJ |
69 | |
70 | OUTPUT_DIR="$(mktemp -d)" | |
71 | OUTPUT_FILE="${OUTPUT_DIR}/linkchecker-out.csv" | |
72 | ||
00c49046 | 73 | # linkchecker drops privileges to 'nobody' when run as root |
8fa2f091 MJ |
74 | chown nobody "${OUTPUT_DIR}" |
75 | ||
00c49046 KS |
76 | # @Note: Only internal links are checked by default |
77 | if ! linkchecker -q -F "csv/utf-8/${OUTPUT_FILE}" http://localhost:10000/ ; then | |
78 | echo "Linkchecker failed or found broken links" | |
79 | cat "${OUTPUT_FILE}" | |
80 | kill "${SERVER_PID}" | |
8fa2f091 | 81 | rm -rf "${OUTPUT_DIR}" |
00c49046 KS |
82 | sleep 5 # Let serve:prod stop |
83 | exit 1 | |
84 | else | |
8fa2f091 | 85 | rm -rf "${OUTPUT_DIR}" |
00c49046 KS |
86 | kill "${SERVER_PID}" |
87 | fi | |
88 | ||
8fa2f091 | 89 | print_header "Deploy website" |
bdee76c2 | 90 | grunt "${DEPLOY_TARGET}" --verbose |
5b461c35 | 91 | # EOF |