Make nodejs part of the base install

This commit is contained in:
Bob Mottram 2017-05-18 12:50:24 +01:00
parent b6ae4623ec
commit 1c8187e4fe
2 changed files with 117 additions and 37 deletions

View File

@ -1193,6 +1193,82 @@ function image_setup_utils {
# cmake
}
function image_install_nodejs {
if [ $INSTALLING_MESH ]; then
return
fi
chroot "$rootdir" apt-get -yq install nodejs
chroot "$rootdir" apt-get -yq install npm curl
if [ ! -f $rootdir/usr/bin/nodejs ]; then
echo $'nodejs was not installed'
exit 63962
fi
cat <<EOF > $rootdir/root/install-nodejs.sh
#!/bin/bash
PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
NODE_PATH="/usr/lib/node_modules"
cp /usr/bin/nodejs /usr/local/bin/node
cp /usr/bin/nodejs /usr/bin/node
/usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
npm install -g n@${NODEJS_N_VERSION} --save
if [ ! -f /usr/local/bin/n ]; then
exit 1
fi
cp /usr/local/bin/n /usr/bin/n
n ${NODEJS_VERSION}
if [ ! -f /usr/local/bin/node ]; then
exit 2
fi
cp /usr/local/bin/node /usr/bin/nodejs
cp /usr/local/bin/node /usr/bin/node
npm install -g npm@${NPM_VERSION} --save
if [ ! -f /usr/local/bin/npm ]; then
exit 3
fi
cp /usr/local/bin/npm /usr/bin/npm
npm install -g pug@2.0.0-beta6 --save
npm install -g graceful-fs@4.1.10 --save
npm install -g minimatch@3.0.3 --save
exit 0
EOF
chmod +x $rootdir/root/install-nodejs.sh
chroot "$rootdir" /root/install-nodejs.sh
if [ ! "$?" = "0" ]; then
rm -f $rootdir/root/install-nodejs.sh
exit 7632572
fi
rm -f $rootdir/root/install-nodejs.sh
# second npm install attempt seems necessary
chroot "$rootdir" npm install -g npm@${NPM_VERSION} --save
cp $rootdir/usr/local/bin/npm $rootdir/usr/bin/npm
# node seems tricky so here we're going to double check
# that the versions we expect did get installed
CURR_NODE_VERSION=$($rootdir/usr/bin/node --version)
CURR_NPM_VERSION=$($rootdir/usr/bin/npm --version)
CURR_N_VERSION=$($rootdir/usr/bin/n --version)
if [[ "$CURR_NPM_VERSION" != "$NPM_VERSION" ]]; then
echo $"Expected npm version $NPM_VERSION but actually have $CURR_NPM_VERSION"
exit 6728252
fi
if [[ "$CURR_N_VERSION" != "$NODEJS_N_VERSION" ]]; then
echo $"Expected n version $NODEJS_N_VERSION but actually have $CURR_N_VERSION"
exit 5267452
fi
if [[ "$CURR_NODE_VERSION" != "v${NODEJS_VERSION}" ]]; then
echo $"Expected node version $NODEJS_VERSION but actually have $CURR_NODE_VERSION"
exit 5274527
fi
if ! grep -q "nodejs_base" $rootdir$COMPLETION_FILE; then
echo "nodejs_base" >> $rootdir$COMPLETION_FILE
fi
}
##############################################################################
@ -1339,6 +1415,7 @@ configure_wifi
configure_user_interface
image_setup_utils
image_install_inadyn
image_install_nodejs
# remove downloaded packages
chroot $rootdir apt-get -y autoremove

View File

@ -77,7 +77,7 @@ function remove_nodejs {
return
fi
if [ ! -f $NODEJS_INSTALLED_APPS_FILE ]; then
remove_app nodejs
#remove_app nodejs
return
fi
sed -i "/install_${1}/d" $NODEJS_INSTALLED_APPS_FILE
@ -132,20 +132,22 @@ function install_nodejs {
mesh_install_nodejs
return
fi
if [[ $(is_completed $FUNCNAME) == "1" ]]; then
upgrade_nodejs
return
fi
if ! grep -q "nodejs_base" $COMPLETION_FILE; then
apt-get -yq install nodejs
apt-get -yq install npm curl
if [[ $(is_completed $FUNCNAME) == "1" ]]; then
upgrade_nodejs
return
fi
if [ ! -f /usr/bin/nodejs ]; then
echo $'nodejs was not installed'
exit 63962
fi
apt-get -yq install nodejs
apt-get -yq install npm curl
cat <<EOF > /root/install-nodejs.sh
if [ ! -f /usr/bin/nodejs ]; then
echo $'nodejs was not installed'
exit 63962
fi
cat <<EOF > /root/install-nodejs.sh
#!/bin/bash
PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
NODE_PATH="/usr/lib/node_modules"
@ -173,34 +175,35 @@ npm install -g graceful-fs@4.1.10 --save
npm install -g minimatch@3.0.3 --save
exit 0
EOF
chmod +x /root/install-nodejs.sh
/root/install-nodejs.sh
if [ ! "$?" = "0" ]; then
chmod +x /root/install-nodejs.sh
/root/install-nodejs.sh
if [ ! "$?" = "0" ]; then
rm -f /root/install-nodejs.sh
exit 7632572
fi
rm -f /root/install-nodejs.sh
exit 7632572
fi
rm -f /root/install-nodejs.sh
# second npm install attempt seems necessary
npm install -g npm@${NPM_VERSION} --save
cp /usr/local/bin/npm /usr/bin/npm
# second npm install attempt seems necessary
npm install -g npm@${NPM_VERSION} --save
cp /usr/local/bin/npm /usr/bin/npm
# node seems tricky so here we're going to double check
# that the versions we expect did get installed
CURR_NODE_VERSION=$(node --version)
CURR_NPM_VERSION=$(npm --version)
CURR_N_VERSION=$(n --version)
if [[ "$CURR_NPM_VERSION" != "$NPM_VERSION" ]]; then
echo $"Expected npm version $NPM_VERSION but actually have $CURR_NPM_VERSION"
exit 6728252
fi
if [[ "$CURR_N_VERSION" != "$NODEJS_N_VERSION" ]]; then
echo $"Expected n version $NODEJS_N_VERSION but actually have $CURR_N_VERSION"
exit 5267452
fi
if [[ "$CURR_NODE_VERSION" != "v${NODEJS_VERSION}" ]]; then
echo $"Expected node version $NODEJS_VERSION but actually have $CURR_NODE_VERSION"
exit 5274527
# node seems tricky so here we're going to double check
# that the versions we expect did get installed
CURR_NODE_VERSION=$(node --version)
CURR_NPM_VERSION=$(npm --version)
CURR_N_VERSION=$(n --version)
if [[ "$CURR_NPM_VERSION" != "$NPM_VERSION" ]]; then
echo $"Expected npm version $NPM_VERSION but actually have $CURR_NPM_VERSION"
exit 6728252
fi
if [[ "$CURR_N_VERSION" != "$NODEJS_N_VERSION" ]]; then
echo $"Expected n version $NODEJS_N_VERSION but actually have $CURR_N_VERSION"
exit 5267452
fi
if [[ "$CURR_NODE_VERSION" != "v${NODEJS_VERSION}" ]]; then
echo $"Expected node version $NODEJS_VERSION but actually have $CURR_NODE_VERSION"
exit 5274527
fi
fi
if [ $1 ]; then