-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild
executable file
·152 lines (99 loc) · 3.07 KB
/
build
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
# This script prepares a initramfs that can boot a NodeOS usersfs
set -o pipefail
GRN="\e[32m"
CLR="\e[0m"
TOOLCHAIN=`node -p "require('nodeos-cross-toolchain')"`
source $TOOLCHAIN/scripts/adjustEnvVars.sh &&
source scripts/utils.sh || exit $?
PATH=$TOOLCHAIN/bin:$PATH
# Build cross-compiler (if needed)
(
cd $TOOLCHAIN
# We can't use `--arch=$NODE_ARCH` because `prebuild` would install a
# cross-compiler for a diferent host platform, so we set the desired target
# platform using environment variables instead
BITS=$BITS CPU=$CPU MACHINE=$MACHINE npm install --production || exit 1
) || exit $?
# Default: multiple users system
if [[ "$SINGLE_USER" ]]; then
OUT_NAME=${CPU}_${SINGLE_USER}
else
OUT_NAME=${CPU}
SINGLE_USER=nodeos-boot-multiUser
fi
#
# Define steps paths
#
NODE_PLATFORM=linux
OUT_DIR=`pwd`/out/$OUT_NAME
OBJ_DIR=${OBJECTS}_${SINGLE_USER}
PREBUILD=prebuilds/$NODE_PLATFORM-$NODE_ARCH.tar.gz
#
# FUSE
#
SRC_FUSE=`node -p "require('libfuse')"`
(
cd $SRC_FUSE && eval "$NPMi" || exit 10
) || err $?
#
# System dependencies
#
STEP_DIR=$OBJ_DIR
if [[ ! -d $STEP_DIR ]]; then
echo -e "${WHT}Generating initramfs${CLR}"
rmStep $OUT_DIR
# Install FUSE
SRC_FUSE=$SRC_FUSE/out/$CPU
mkdir -p $STEP_DIR/lib &&
cp $SRC_FUSE/lib/libfuse.so* $STEP_DIR/lib || exit 20
# Install usrbinenv
eval "$NPMi" -g usrbinenv || err 21
mkdir -p $STEP_DIR/usr/bin &&
ln -fs ../../bin/env $STEP_DIR/usr/bin/env || err 22
#
# Install system init
#
eval "$NPMi" -g $SINGLE_USER --has_libblkid=false \
--fuse__include_dirs=$SRC_FUSE/include/fuse \
--fuse__library_dirs=$SRC_FUSE/lib \
--fuse__libraries=-lfuse || err 23
mkdir -p $STEP_DIR/sbin || err 24
# Set `/sbin/init` to package binary or `server.js` file
MODULE=lib/node_modules/$SINGLE_USER
PACKAGE_JSON=$STEP_DIR/$MODULE/package.json
SERVER=$MODULE/server.js
(
BIN=bin/`pkg-bin $PACKAGE_JSON` && \
ls $STEP_DIR/$BIN && \
ln -fs ../$BIN $STEP_DIR/sbin/init
) \
|| \
(
ls $STEP_DIR/$SERVER && \
ln -fs ../$SERVER $STEP_DIR/sbin/init
) \
|| exit 25
echo -e "${GRN}Successfully generated initramfs${CLR}"
fi
#
# Wrap the system up and pack it
#
STEP_DIR=$OUT_DIR
# Set initramfs files only accesible to root
chmod -R u-w,go-rw "$OBJ_DIR" &&
chmod -R o+r "$OBJ_DIR/lib/node_modules/usrbinenv" &&
chmod -R o+r "$OBJ_DIR/usr/bin/env" || exit 30
if [[ ! -f $STEP_DIR ]]; then
rmStep $PREBUILD
mkdir -p `dirname $STEP_DIR`
(
# TODO on single user systems, set user files user:group to `1:1`. This
# would require to set the global ones to `0:0` before adding the user ones.
# Other option is to use the npm `cpio-stream`module
cd "$OBJ_DIR" &&
find | cpio --owner 0:0 -o -H newc | gzip || exit 40
) > $STEP_DIR || err $?
fi
ln -sf $OUT_NAME out/latest || err 41
echo -e "${GRN}Successfully built 'initramfs'${CLR}"