1 | #!/usr/bin/env bash
|
2 |
|
3 | set -e;
|
4 |
|
5 | export SUMAN_DEBUG_LOG_PATH="$HOME/.suman/logs/suman-postinstall-debug.log"
|
6 | SUMAN_POSTINSTALL_IS_DAEMON=${SUMAN_POSTINSTALL_IS_DAEMON:-no}
|
7 |
|
8 | mkdir -p "$HOME/.suman" && echo "created suman dir" || { echo " could not create suman dir"; exit 1; }
|
9 | mkdir -p "$HOME/.suman/logs" && echo "create logs dir" || { echo " could not create logs dir"; exit 1; }
|
10 | mkdir -p "$HOME/.suman/global" && echo "created global dir" || { echo " could not create global dir"; exit 1; }
|
11 | mkdir -p "$HOME/.suman/database" && echo "created database dir" || { echo " could not create database dir"; exit 1; }
|
12 |
|
13 | if [ -e ${SUMAN_DEBUG_LOG_PATH} ]; then
|
14 | echo "new install run" > ${SUMAN_DEBUG_LOG_PATH} && echo "created debug log file" \
|
15 | || { echo " could not create log file"; exit 1; }
|
16 | else
|
17 | echo "new install run" >> ${SUMAN_DEBUG_LOG_PATH} && echo "created debug log file" \
|
18 | || { echo " could not create log file"; exit 1; }
|
19 | fi
|
20 |
|
21 | SUMAN_START_TIME=$(node -e 'console.log(Date.now())')
|
22 | SUMAN_DEBUG="$(echo -e "${SUMAN_DEBUG}" | tr -d '[:space:]')"
|
23 |
|
24 | SUMAN_IN_CONTAINER="no";
|
25 |
|
26 | if [[ "lxc" == "${container}" ]]; then
|
27 | SUMAN_IN_CONTAINER="yes";
|
28 | echo " => Suman says => We are in a (Docker) container because of the
|
29 | container env var! " | tee -a ${SUMAN_DEBUG_LOG_PATH}
|
30 | fi
|
31 |
|
32 | if [[ -f ~/.dockerenv ]]; then
|
33 | SUMAN_IN_CONTAINER="yes";
|
34 | echo " => Suman says => We are in a (Docker)
|
35 | container because of the presence of .dockerenv file! " | tee -a ${SUMAN_DEBUG_LOG_PATH}
|
36 | fi
|
37 |
|
38 | ./scripts/create-suman-dir.js
|
39 |
|
40 | DOT_SUMAN_DIR=$(cd ~/.suman && pwd)
|
41 | SUMAN_INSTALL_NODE_MODULES="yes";
|
42 |
|
43 | if [[ ! -d "$DOT_SUMAN_DIR" ]]; then
|
44 | echo " => Warning => Suman failed to create ~/.suman directory." | tee -a ${SUMAN_DEBUG_LOG_PATH}
|
45 | SUMAN_INSTALL_NODE_MODULES="no";
|
46 | fi
|
47 |
|
48 | if [[ "${SUMAN_INSTALL_NODE_MODULES}" == "yes" ]]; then
|
49 |
|
50 |
|
51 | (
|
52 |
|
53 | cd "$HOME/.suman/global";
|
54 |
|
55 | npm init -f >> ${SUMAN_DEBUG_LOG_PATH} 2>&1
|
56 |
|
57 | if [[ ! -d "node_modules/handlebars" ]]; then
|
58 | npm install -S handlebars
|
59 | fi
|
60 |
|
61 | if [[ ! -d "node_modules/typescript" ]]; then
|
62 | npm install -S typescript
|
63 | fi
|
64 |
|
65 | if [[ ! -d "node_modules/ts-node" ]]; then
|
66 | npm install -S ts-node
|
67 | fi
|
68 |
|
69 | if [[ ! -d "node_modules/istanbul" ]]; then
|
70 | npm install -S istanbul
|
71 | fi
|
72 |
|
73 | if [[ ! -d "node_modules/nyc" ]]; then
|
74 | npm install -S nyc
|
75 | fi
|
76 |
|
77 | if [[ ! -d "node_modules/suman-inquirer" ]]; then
|
78 | npm install -S suman-inquirer
|
79 | fi
|
80 |
|
81 | if [[ ! -d "node_modules/suman-inquirer-directory" ]]; then
|
82 | npm install -S suman-inquirer-directory
|
83 | fi
|
84 |
|
85 | if [[ ! -d "node_modules/babel-core" ]]; then
|
86 | npm install -S babel-core
|
87 | fi
|
88 |
|
89 | if [[ ! -d "node_modules/babel-runtime" ]]; then
|
90 | npm install -S babel-runtime
|
91 | fi
|
92 |
|
93 | )
|
94 |
|
95 | fi
|
96 |
|
97 | SUMAN_END_TIME=$(node -e 'console.log(Date.now())')
|
98 | SUMAN_TOTAL_TIME=$(expr ${SUMAN_END_TIME} - ${SUMAN_START_TIME})
|
99 | echo " => Suman => all done with postinstall routine after ${SUMAN_TOTAL_TIME}ms. " | tee -a ${SUMAN_DEBUG_LOG_PATH}
|
100 |
|
101 |
|
102 | exit 0;
|