-
Notifications
You must be signed in to change notification settings - Fork 0
/
dist.sh
executable file
·86 lines (74 loc) · 2.85 KB
/
dist.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh -
#
# 1) start homewall jail:
# jail -c homewall
#
# 2) Distribute this react webpack using:
# sh dist.sh
#
builtin . /etc/shrc
_main() {
local HERE=$( /usr/bin/dirname $( /bin/realpath "$0" ));
if [ ! -d "$HERE" ]; then
errmsg "script must be executed, not sourced or evaluated."; return 1;
fi
local NAME=$( /usr/bin/basename "$HERE" );
# Delete any old build directory before replacing it.
# *TODO* change this to reflect the name of the jail.
local JAIL_NAME=$( echo "$NAME" | /usr/bin/sed -E 's|\-web$||' )
if [ -z "$JAIL_NAME" ] || [ "$JAIL_NAME" == "$NAME" ]; then
errmsg "${JAIL_NAME} and ${NAME} should not be identical."; return 1;
fi
local JAIL_DIR="/work/systems/targets/${JAIL_NAME}"
if [ ! -d "$JAIL_DIR" ]; then
notdir "$JAIL_DIR"; return 1;
fi
local JAIL_ROOT="${JAIL_DIR}/mnt";
if [ ! -d "$JAIL_ROOT" ]; then
notdir "$JAIL_ROOT"; return 1;
fi
if is-empty-directory "$JAIL_ROOT"; then
errmsg "The jail named ${JAIL_NAME} must be started first."; return 1;
fi
local WWW_DIR="${JAIL_ROOT}/usr/local/www";
if [ ! -d "$WWW_DIR" ]; then
errmsg "nginx doesn't appear to be installed in the ${JAIL_NAME} jail--${WWW_DIR} doesn't exist."; return 1
fi
# Replace /usr/local/www/homewall/
local WEB_DIR="${WWW_DIR}/${JAIL_NAME}";
#if [ -d "$WEB_DIR" ]; then
# echo "Deleting (old) ${WEB_DIR}" >> /dev/stderr
# /bin/rm -rf "$WEB_DIR" || return 1
#fi
echo "Creating ${WEB_DIR}" >> /dev/stderr;
/bin/mkdir -p "$WEB_DIR" || return 1
if [ ! -d "$WEB_DIR" ]; then
notdir "$WEB_DIR"; return 1
fi
local DST_BUILD_DIR="${WEB_DIR}/build"
if [ ! -d "$DST_BUILD_DIR" ]; then
# Create (new) /usr/local/www/homewall/www/build/
#echo "Creating: ${DST_BUILD_DIR}" >> /dev/stderr
#/bin/mkdir -p "$DST_BUILD_DIR" || return 1
notdir "$DST_BUILD_DIR"; return 1;
fi
echo "Deleting old: ${DST_BUILD_DIR}" >> /dev/stderr;
#/bin/rm -rf "$DST_BUILD_DIR" || return 1
/usr/bin/find "$DST_BUILD_DIR" -type f -maxdepth 1 -delete || return 1
# Copy /work/systems/targets/homewall-web/build/* into
# /work/systems/targets/homewall/mnt/usr/local/www/homewall/build/.
local SRC_BUILD_DIR="${HERE}/build"
if [ ! -d "$SRC_BUILD_DIR" ]; then
notdir "$SRC_BUILD_DIR"; return 1;
fi
echo "Copying: ${SRC_BUILD_DIR} into ${DST_BUILD_DIR}" >> /dev/stderr
( /usr/bin/tar -cf - -C ${SRC_BUILD_DIR} . | /usr/bin/tar -xf - -C ${DST_BUILD_DIR} )
#cphier "$SRC_BUILD_DIR" "$DST_BUILD_DIR" || return 1
# Move /usr/local/www/homewall/build/express.cjs,index.html to
# /usr/local/www/homewall/.
echo "Moving: express.cjs from ${SRC_BUILD_DIR} to ${WEB_DIR}" >> /dev/stderr
/bin/mv "${DST_BUILD_DIR}/express.cjs" "$WEB_DIR" || return 1
echo "Moving: index.html from ${SRC_BUILD_DIR} to ${WEB_DIR}" >> /dev/stderr
/bin/mv "${DST_BUILD_DIR}/index.html" "$WEB_DIR" || return 1
}
_main;