diff options
author | Vijay A <vraravam@users.noreply.github.com> | 2022-04-30 05:15:02 -0500 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2022-04-30 05:23:58 -0500 |
commit | 713614cb36c4ab22039720187835c69b18b88bbd (patch) | |
tree | f875fc4727969fa955e6462ef9dbc2f02be71e01 /scripts/build-unix.sh | |
parent | Creates the build script for Windows based on Ferdium-App (diff) | |
download | ferdium-server-713614cb36c4ab22039720187835c69b18b88bbd.tar.gz ferdium-server-713614cb36c4ab22039720187835c69b18b88bbd.tar.zst ferdium-server-713614cb36c4ab22039720187835c69b18b88bbd.zip |
Added build script for unix OSes
Diffstat (limited to 'scripts/build-unix.sh')
-rwxr-xr-x | scripts/build-unix.sh | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/scripts/build-unix.sh b/scripts/build-unix.sh new file mode 100755 index 0000000..ff1ce0f --- /dev/null +++ b/scripts/build-unix.sh | |||
@@ -0,0 +1,142 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | # INTRO: | ||
4 | # This file is used to build ferdium-server on both x64 and arm-based for macos and linux (not tested on arm for linux). | ||
5 | # It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning) | ||
6 | # It will install the system dependencies except for node and python (which are still verified) | ||
7 | # I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed independently | ||
8 | # This file can live anywhere in your PATH | ||
9 | |||
10 | set -e | ||
11 | |||
12 | export CI=true | ||
13 | |||
14 | # ----------------------------------------------------------------------------- | ||
15 | # Utility functions | ||
16 | fail_with_docs() { | ||
17 | printf "\n*************** FAILING ***************\n" | ||
18 | echo "$1" | ||
19 | echo "" | ||
20 | echo "Please read the developer documentation in CONTRIBUTING.md" | ||
21 | exit 1 | ||
22 | } | ||
23 | |||
24 | command_exists() { | ||
25 | type "$1" &>/dev/null 2>&1 | ||
26 | } | ||
27 | |||
28 | # ----------------------------------------------------------------------------- | ||
29 | # Checking the developer environment | ||
30 | # Check for installed programmes | ||
31 | command_exists node || fail_with_docs "Node is not installed" | ||
32 | command_exists python || fail_with_docs "python is not installed" | ||
33 | |||
34 | # Check node version | ||
35 | EXPECTED_NODE_VERSION=$(cat .nvmrc) | ||
36 | ACTUAL_NODE_VERSION=$(node -v) | ||
37 | if [ "v$EXPECTED_NODE_VERSION" != "$ACTUAL_NODE_VERSION" ]; then | ||
38 | fail_with_docs "You are not running the expected version of node! | ||
39 | expected: [v$EXPECTED_NODE_VERSION] | ||
40 | actual : [$ACTUAL_NODE_VERSION]" | ||
41 | fi | ||
42 | |||
43 | # Check if the 'recipes' folder is present either as a git submodule or a symbolic link | ||
44 | if ! [ -f "recipes/package.json" ]; then | ||
45 | fail_with_docs "'recipes' folder is missing or submodule has not been checked out" | ||
46 | fi | ||
47 | |||
48 | # This log statement is only to remind me which 'recipes' folder I am using (symlink or git submodule) | ||
49 | if [[ -L recipes ]]; then | ||
50 | printf "\n*************** CONTINUING for 'recipes' symlinked ***************\n" | ||
51 | else | ||
52 | printf "\n*************** CONTINUING for 'recipes' submodule ***************\n" | ||
53 | fi | ||
54 | |||
55 | # ----------------------------------------------------------------------------- | ||
56 | # If you are moving to a new version of node or any other system dependency, then cleaning is recommended | ||
57 | # so that there's no irregular results due to cached modules | ||
58 | if [ "$CLEAN" != "true" ]; then | ||
59 | printf "\n*************** SKIPPING Cleaning ***************\n" | ||
60 | else | ||
61 | printf "\n*************** Cleaning!!!!!! ***************\n" | ||
62 | |||
63 | if [[ -s 'pnpm-lock.yaml' ]]; then | ||
64 | pnpm store prune || true # in case the pnpm executable itself is not present | ||
65 | rm -rf ~/.pnpm-store ~/.pnpm-state | ||
66 | fi | ||
67 | |||
68 | npm cache clean --force | ||
69 | rm -rf ~/.npm ~/.node-gyp ~/.asdf/installs/nodejs/*/.npm/ | ||
70 | |||
71 | git -C recipes clean -fxd # Clean recipes folder/submodule | ||
72 | git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it | ||
73 | fi | ||
74 | |||
75 | # ----------------------------------------------------------------------------- | ||
76 | # Ensure that the system dependencies are at the correct version - fail if not | ||
77 | # Check python version | ||
78 | EXPECTED_PYTHON_VERSION="3.10.4" | ||
79 | ACTUAL_PYTHON_VERSION=$(python --version | sed -e "s/Python //") | ||
80 | if [[ "$ACTUAL_PYTHON_VERSION" != "$EXPECTED_PYTHON_VERSION" ]]; then | ||
81 | fail_with_docs "You are not running the expected version of Python! | ||
82 | expected: [$EXPECTED_PYTHON_VERSION] | ||
83 | actual : [$ACTUAL_PYTHON_VERSION]" | ||
84 | fi | ||
85 | |||
86 | # ----------------------------------------------------------------------------- | ||
87 | # Ensure that the system dependencies are at the correct version - recover if not | ||
88 | # If 'asdf' is installed, reshim for new nodejs if necessary | ||
89 | command_exists asdf && asdf reshim nodejs | ||
90 | |||
91 | # Ensure that the system dependencies are at the correct version | ||
92 | # Check npm version | ||
93 | EXPECTED_NPM_VERSION=$(node -p 'require("./package.json").engines.npm') | ||
94 | ACTUAL_NPM_VERSION=$(npm --version) | ||
95 | if [[ "$ACTUAL_NPM_VERSION" != "$EXPECTED_NPM_VERSION" ]]; then | ||
96 | npm i -gf npm@$EXPECTED_NPM_VERSION | ||
97 | fi | ||
98 | |||
99 | # Check pnpm version | ||
100 | EXPECTED_PNPM_VERSION=$(node -p 'require("./recipes/package.json").engines.pnpm') | ||
101 | ACTUAL_PNPM_VERSION=$(pnpm --version || true) # in case the pnpm executable itself is not present | ||
102 | if [[ "$ACTUAL_PNPM_VERSION" != "$EXPECTED_PNPM_VERSION" ]]; then | ||
103 | npm i -gf pnpm@$EXPECTED_PNPM_VERSION | ||
104 | fi | ||
105 | |||
106 | # If 'asdf' is installed, reshim for new nodejs if necessary | ||
107 | command_exists asdf && asdf reshim nodejs | ||
108 | |||
109 | # ----------------------------------------------------------------------------- | ||
110 | # This is useful if we move from 'npm' to 'pnpm' for the main repo as well | ||
111 | if [[ -s 'pnpm-lock.yaml' ]]; then | ||
112 | BASE_CMD=pnpm | ||
113 | else | ||
114 | BASE_CMD=npm | ||
115 | fi | ||
116 | |||
117 | ENV_FILE=".env" | ||
118 | if [[ ! -s $ENV_FILE ]]; then | ||
119 | APP_KEY=`cat /dev/urandom | LC_ALL=C tr -dc "[:alnum:]" | fold -w ${1:-32} | head -n 1` | ||
120 | # SAVE APP_KEY TO .env FILE | ||
121 | sed "s/APP_KEY\=/APP_KEY=$APP_KEY/" .env.example > $ENV_FILE | ||
122 | fi | ||
123 | |||
124 | mkdir -p data | ||
125 | |||
126 | # ----------------------------------------------------------------------------- | ||
127 | printf "\n*************** Building recipes ***************\n" | ||
128 | # Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm | ||
129 | pushd recipes | ||
130 | pnpm i | ||
131 | pnpm package | ||
132 | popd | ||
133 | |||
134 | # Now the meat..... | ||
135 | $BASE_CMD i | ||
136 | node ace migration:refresh | ||
137 | |||
138 | # ----------------------------------------------------------------------------- | ||
139 | printf "\n*************** Building app ***************\n" | ||
140 | $BASE_CMD start --dev | ||
141 | |||
142 | printf "\n*************** App successfully stopped! ***************\n" | ||