2016-08-15 10:27:55 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# nodejs functions
|
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
2017-06-04 19:35:55 +02:00
|
|
|
# Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
|
2016-08-15 10:27:55 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# For reasons unknown we initially have to upgrade to an intermediate version
|
|
|
|
# before getting to the version we want
|
|
|
|
|
|
|
|
VARIANTS='mesh'
|
|
|
|
|
2016-11-04 18:20:36 +01:00
|
|
|
# change these versions at your peril. Things will often crash if you don't
|
|
|
|
# have specifically the correct versions
|
2017-09-12 19:50:14 +02:00
|
|
|
NODEJS_VERSION='6.11.3'
|
2017-04-02 12:40:34 +02:00
|
|
|
NODEJS_N_VERSION='2.1.7'
|
2017-06-22 18:41:23 +02:00
|
|
|
NPM_VERSION='4.0.5'
|
2016-08-15 10:27:55 +02:00
|
|
|
|
2016-11-04 15:06:09 +01:00
|
|
|
# This file keeps track of the apps needing nodejs
|
|
|
|
# so that it can be removed if tere are no apps which need it
|
|
|
|
NODEJS_INSTALLED_APPS_FILE=$HOME/.nodejs-apps
|
|
|
|
|
2017-09-14 14:19:30 +02:00
|
|
|
function get_npm_arch {
|
2017-09-14 14:34:22 +02:00
|
|
|
N_ARCH='x86'
|
2017-09-14 14:19:30 +02:00
|
|
|
NPM_ARCH='ia32'
|
2017-09-18 16:44:59 +02:00
|
|
|
if [[ $ARCHITECTURE == 'arm'* ]]; then
|
2017-09-14 14:19:30 +02:00
|
|
|
NPM_ARCH='armv7l'
|
2017-09-14 14:34:22 +02:00
|
|
|
N_ARCH='arm'
|
2017-09-14 14:19:30 +02:00
|
|
|
fi
|
2017-09-18 16:44:59 +02:00
|
|
|
if [[ $ARCHITECTURE == *"aarch"* ]]; then
|
|
|
|
NPM_ARCH='arm64'
|
|
|
|
N_ARCH='arm64'
|
|
|
|
fi
|
2017-09-14 14:19:30 +02:00
|
|
|
if [[ $ARCHITECTURE == 'x86_64' || $ARCHITECTURE == 'amd64' ]]; then
|
|
|
|
NPM_ARCH='x64'
|
2017-09-14 14:34:22 +02:00
|
|
|
N_ARCH='x64'
|
2017-09-14 14:19:30 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-08-15 10:27:55 +02:00
|
|
|
function mesh_install_nodejs {
|
2017-09-19 12:03:45 +02:00
|
|
|
mesh_install_nodejs_prefix=
|
|
|
|
if [ $rootdir ]; then
|
2017-10-06 22:20:22 +02:00
|
|
|
if [[ $VARIANT == "mesh" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
2017-09-19 12:03:45 +02:00
|
|
|
mesh_install_nodejs_prefix="chroot $rootdir"
|
|
|
|
fi
|
|
|
|
$mesh_install_nodejs_prefix apt-get -yq install g++ m4 libtool automake nodejs curl
|
|
|
|
$mesh_install_nodejs_prefix apt-get -yq install libxext-dev libxtst-dev libxkbfile-dev
|
2016-08-15 10:27:55 +02:00
|
|
|
|
|
|
|
if [ ! -f ${rootdir}/usr/bin/nodejs ]; then
|
|
|
|
echo $'nodejs was not installed'
|
|
|
|
exit 63962
|
|
|
|
fi
|
|
|
|
|
2017-09-13 21:10:28 +02:00
|
|
|
if [ -f $rootdir/usr/bin/nodejs ]; then
|
|
|
|
cp $rootdir/usr/bin/nodejs $rootdir/usr/bin/node
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $rootdir/usr/bin/node ]; then
|
|
|
|
echo $'/usr/bin/node not found'
|
|
|
|
exit 7235728
|
|
|
|
fi
|
|
|
|
|
2017-10-13 19:22:22 +02:00
|
|
|
$mesh_install_nodejs_prefix apt-get -qy install wget
|
2017-10-13 18:56:59 +02:00
|
|
|
$mesh_install_nodejs_prefix wget https://www.npmjs.com/install.sh -O /root/npm_install.sh
|
2017-09-15 20:50:23 +02:00
|
|
|
if [ ! -f $rootdir/root/npm_install.sh ]; then
|
|
|
|
echo $'Unable to download npm installer'
|
|
|
|
exit 8793636
|
2017-09-13 21:10:28 +02:00
|
|
|
fi
|
2017-10-13 18:56:59 +02:00
|
|
|
if ! grep -q "t=\"\${npm_install}\"" $rootdir/root/npm_install.sh; then
|
|
|
|
echo $'Unable to set npm version within npm_install.sh'
|
|
|
|
exit 629052
|
|
|
|
fi
|
2017-09-19 12:03:45 +02:00
|
|
|
$mesh_install_nodejs_prefix chmod +x /root/npm_install.sh
|
2017-10-13 18:56:59 +02:00
|
|
|
$mesh_install_nodejs_prefix sed -i "s|t=\"\${npm_install}\"|t=\"$NPM_VERSION\"|g" /root/npm_install.sh
|
2017-09-19 12:03:45 +02:00
|
|
|
$mesh_install_nodejs_prefix /root/npm_install.sh
|
2017-09-15 20:50:23 +02:00
|
|
|
|
2017-09-14 14:19:30 +02:00
|
|
|
if [ ! -f $rootdir/usr/bin/npm ]; then
|
|
|
|
echo $'npm was not installed'
|
|
|
|
exit 5290462
|
|
|
|
fi
|
2017-09-15 20:50:23 +02:00
|
|
|
cp $rootdir/usr/bin/npm $rootdir/root/npm
|
2017-09-14 14:19:30 +02:00
|
|
|
|
|
|
|
# update from the old debian nodejs version
|
|
|
|
get_npm_arch
|
2017-09-19 12:03:45 +02:00
|
|
|
$mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g n@${NODEJS_N_VERSION} --save
|
|
|
|
$mesh_install_nodejs_prefix n --arch $N_ARCH ${NODEJS_VERSION}
|
2017-09-15 20:50:23 +02:00
|
|
|
cp $rootdir/root/npm $rootdir/usr/bin/npm
|
2016-08-15 10:27:55 +02:00
|
|
|
}
|
|
|
|
|
2016-11-04 15:06:09 +01:00
|
|
|
function remove_nodejs {
|
|
|
|
if [ ! $1 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if [ ! -f $NODEJS_INSTALLED_APPS_FILE ]; then
|
2017-05-18 13:50:24 +02:00
|
|
|
#remove_app nodejs
|
2016-11-04 15:06:09 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
sed -i "/install_${1}/d" $NODEJS_INSTALLED_APPS_FILE
|
2017-06-28 14:52:14 +02:00
|
|
|
if ! grep -q "install_" $NODEJS_INSTALLED_APPS_FILE; then
|
2016-11-04 15:06:09 +01:00
|
|
|
apt-get -yq remove --purge nodejs
|
|
|
|
|
|
|
|
if [ -f /usr/bin/nodejs ]; then
|
|
|
|
rm /usr/bin/nodejs
|
|
|
|
fi
|
|
|
|
if [ -f /usr/local/bin/node ]; then
|
|
|
|
rm /usr/local/bin/node
|
|
|
|
fi
|
|
|
|
if [ -f /usr/bin/node ]; then
|
|
|
|
rm /usr/bin/node
|
|
|
|
fi
|
2016-11-04 18:42:17 +01:00
|
|
|
if [ -d /usr/lib/node_modules ]; then
|
|
|
|
rm -rf /usr/lib/node_modules
|
|
|
|
fi
|
2017-04-02 12:40:34 +02:00
|
|
|
if [ -f /usr/bin/n ]; then
|
|
|
|
rm /usr/bin/n
|
|
|
|
fi
|
2016-11-04 15:06:09 +01:00
|
|
|
|
2016-11-04 15:50:11 +01:00
|
|
|
remove_app nodejs
|
|
|
|
|
2016-11-04 15:06:09 +01:00
|
|
|
rm $NODEJS_INSTALLED_APPS_FILE
|
2016-11-04 15:41:20 +01:00
|
|
|
|
|
|
|
apt-get -yq autoremove
|
2016-11-04 15:06:09 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-04-02 12:40:34 +02:00
|
|
|
function upgrade_nodejs {
|
|
|
|
CURR_NODE_VERSION=$(node --version)
|
|
|
|
CURR_NPM_VERSION=$(npm --version)
|
|
|
|
CURR_N_VERSION=$(n --version)
|
|
|
|
if [[ "$CURR_NPM_VERSION" != "$NPM_VERSION" ]]; then
|
2017-04-02 12:42:07 +02:00
|
|
|
npm upgrade -g npm@${NPM_VERSION} --save
|
2017-04-02 12:40:34 +02:00
|
|
|
fi
|
|
|
|
if [[ "$CURR_N_VERSION" != "$NODEJS_N_VERSION" ]]; then
|
|
|
|
npm upgrade -g n@${NODEJS_N_VERSION} --save
|
|
|
|
fi
|
2017-04-02 15:15:45 +02:00
|
|
|
if [[ "$CURR_NODE_VERSION" != "v${NODEJS_VERSION}" ]]; then
|
2017-04-02 12:40:34 +02:00
|
|
|
n {NODEJS_VERSION}
|
|
|
|
fi
|
|
|
|
cp /usr/local/bin/n /usr/bin/n
|
2017-06-04 16:38:50 +02:00
|
|
|
if [ -f /usr/local/bin/npm ]; then
|
|
|
|
cp /usr/local/bin/npm /usr/bin/npm
|
|
|
|
fi
|
|
|
|
if [ -f /usr/local/bin/node ]; then
|
|
|
|
cp /usr/local/bin/node /usr/bin/nodejs
|
|
|
|
cp /usr/local/bin/node /usr/bin/node
|
|
|
|
fi
|
2017-04-02 12:40:34 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 10:27:55 +02:00
|
|
|
function install_nodejs {
|
|
|
|
if [ $INSTALLING_MESH ]; then
|
|
|
|
mesh_install_nodejs
|
|
|
|
return
|
|
|
|
fi
|
2017-05-18 14:39:56 +02:00
|
|
|
if [[ $(is_completed $FUNCNAME) == "1" ]]; then
|
|
|
|
upgrade_nodejs
|
|
|
|
return
|
|
|
|
fi
|
2016-08-15 10:27:55 +02:00
|
|
|
|
2017-09-19 00:44:12 +02:00
|
|
|
if [ ! $ARCHITECTURE ]; then
|
|
|
|
ARCHITECTURE=$(uname -m)
|
2017-05-18 14:39:56 +02:00
|
|
|
fi
|
2017-09-19 00:44:12 +02:00
|
|
|
rootdir=
|
|
|
|
mesh_install_nodejs
|
2017-05-18 13:50:24 +02:00
|
|
|
|
2017-09-19 00:44:12 +02:00
|
|
|
|
|
|
|
#if [ ! -f /usr/bin/nodejs ]; then
|
|
|
|
# Note: this has to be jessie for now
|
|
|
|
# wget -qO- https://deb.nodesource.com/gpgkey/nodesource.gpg.key > /root/node.gpg.key
|
|
|
|
# apt-key add /root/node.gpg.key
|
|
|
|
# echo "deb https://deb.nodesource.com/node_6.x stretch main" > /etc/apt/sources.list.d/nodesource.list
|
|
|
|
# echo "deb-src https://deb.nodesource.com/node_6.x stretch main" >> /etc/apt/sources.list.d/nodesource.list
|
|
|
|
|
|
|
|
# apt-get update
|
|
|
|
|
|
|
|
# apt-get -yq remove --purge nodejs
|
|
|
|
|
|
|
|
# if [ -d /usr/local/lib/node_modules ]; then
|
|
|
|
# rm -rf /usr/local/lib/node_modules
|
|
|
|
# fi
|
|
|
|
# if [ -f /usr/local/bin/node ]; then
|
|
|
|
# rm /usr/local/bin/node
|
|
|
|
# fi
|
|
|
|
# if [ -f /usr/bin/node ]; then
|
|
|
|
# rm /usr/bin/node
|
|
|
|
# fi
|
|
|
|
# if [ -f /usr/bin/nodejs ]; then
|
|
|
|
# rm /usr/bin/nodejs
|
|
|
|
# fi
|
|
|
|
|
|
|
|
# apt-get -yq install nodejs
|
|
|
|
# apt-get -yq install curl
|
|
|
|
|
|
|
|
# if [ ! -f /usr/bin/nodejs ]; then
|
|
|
|
# echo $'nodejs was not installed'
|
|
|
|
# exit 63962
|
|
|
|
# fi
|
|
|
|
#fi
|
|
|
|
|
|
|
|
#npm install -g npm@${NPM_VERSION} --save
|
|
|
|
#npm install -g n@${NODEJS_N_VERSION} --save
|
|
|
|
#n ${NODEJS_VERSION}
|
|
|
|
#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
|
2017-06-06 12:31:25 +02:00
|
|
|
npm install -g npm@${NPM_VERSION} --save
|
2016-08-15 10:27:55 +02:00
|
|
|
|
2017-09-19 00:44:12 +02:00
|
|
|
#cp /usr/local/bin/node /usr/bin/nodejs
|
|
|
|
if [ -f /usr/local/bin/npm ]; then
|
|
|
|
cp /usr/local/bin/npm /usr/bin/npm
|
|
|
|
fi
|
2017-05-18 14:39:56 +02:00
|
|
|
|
|
|
|
# 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
|
2017-04-02 12:40:34 +02:00
|
|
|
fi
|
|
|
|
|
2016-11-04 15:06:09 +01:00
|
|
|
if [ $1 ]; then
|
2017-06-28 14:52:14 +02:00
|
|
|
if ! grep -q "install_${1}" $NODEJS_INSTALLED_APPS_FILE; then
|
2016-11-04 15:06:09 +01:00
|
|
|
echo "install_${1}" >> $NODEJS_INSTALLED_APPS_FILE
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-10-16 20:50:56 +02:00
|
|
|
mark_completed $FUNCNAME
|
2016-08-15 10:27:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: deliberately there is no "exit 0"
|