Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
freedombone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Context Sensitive Group
freedombone
Commits
7c27b35c
Commit
7c27b35c
authored
6 years ago
by
Bob Mottram
Browse files
Options
Downloads
Patches
Plain Diff
Break up nodejs install into subfunctions
parent
3d2e7eb8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/freedombone-utils-nodejs
+144
-103
144 additions, 103 deletions
src/freedombone-utils-nodejs
with
144 additions
and
103 deletions
src/freedombone-utils-nodejs
+
144
−
103
View file @
7c27b35c
...
...
@@ -89,91 +89,69 @@ function nodejs_fix_cpu_detection {
#$mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g worker-farm@1.6.0 --save
}
function
mesh_install_nodejs
{
mesh_install_nodejs_prefix
=
if
[
"
$rootdir
"
]
;
then
mesh_install_nodejs_prefix
=
"chroot
$rootdir
"
function
nodejs_setup_repo
{
if
[
-f
"
$rootdir
/etc/apt/sources.list.d/nodesource.list"
]
;
then
return
fi
if
[
!
-f
"
$rootdir
/etc/apt/sources.list.d/nodesource.list"
]
;
then
echo
$'Setting up nodejs debian repos'
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$INSTALL_PACKAGES
wget curl g++ m4 libtool automake
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$INSTALL_PACKAGES
libxext-dev libxtst-dev libxkbfile-dev
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$INSTALL_PACKAGES
apt-transport-https
$mesh_install_nodejs_prefix
wget https://deb.nodesource.com/gpgkey/nodesource.gpg.key
-O
/root/node.gpg.key
if
[
!
-f
"
$rootdir
/root/node.gpg.key"
]
;
then
echo
$'Unable to obtain gpg key for nodejs repo'
NODE_UPGRADE
=
exit
63
fi
$mesh_install_nodejs_prefix
apt-key add /root/node.gpg.key
echo
"deb https://deb.nodesource.com/node_8.x stretch main"
>
"
$rootdir
/etc/apt/sources.list.d/nodesource.list"
echo
"deb-src https://deb.nodesource.com/node_8.x stretch main"
>>
"
$rootdir
/etc/apt/sources.list.d/nodesource.list"
echo
$'nodejs repos added'
fi
if
[
!
$NODE_UPGRADE
]
;
then
echo
$'Removing any previous nodejs installations'
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$PACKAGE_UNHOLD
nodejs
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$UPDATE_PACKAGES
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$REMOVE_PACKAGES_PURGE
nodejs
echo
$'Removing any previous nodejs binaries and modules'
if
[
-d
"
$rootdir
/usr/local/lib/node_modules"
]
;
then
rm
-rf
"
$rootdir
/usr/local/lib/node_modules"
fi
if
[
-f
"
$rootdir
/usr/local/bin/node"
]
;
then
rm
"
$rootdir
/usr/local/bin/node"
fi
if
[
-f
"
$rootdir
/usr/bin/node"
]
;
then
rm
"
$rootdir
/usr/bin/node"
fi
if
[
-f
"
$rootdir
/usr/bin/nodejs"
]
;
then
rm
"
$rootdir
/usr/bin/nodejs"
fi
echo
$'Setting up nodejs debian repos'
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$INSTALL_PACKAGES
wget curl g++ m4 libtool automake
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$INSTALL_PACKAGES
libxext-dev libxtst-dev libxkbfile-dev
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$INSTALL_PACKAGES
apt-transport-https
$mesh_install_nodejs_prefix
wget https://deb.nodesource.com/gpgkey/nodesource.gpg.key
-O
/root/node.gpg.key
if
[
!
-f
"
$rootdir
/root/node.gpg.key"
]
;
then
echo
$'Unable to obtain gpg key for nodejs repo'
NODE_UPGRADE
=
exit
63
fi
$mesh_install_nodejs_prefix
apt-key add /root/node.gpg.key
echo
"deb https://deb.nodesource.com/node_8.x stretch main"
>
"
$rootdir
/etc/apt/sources.list.d/nodesource.list"
echo
"deb-src https://deb.nodesource.com/node_8.x stretch main"
>>
"
$rootdir
/etc/apt/sources.list.d/nodesource.list"
echo
$'nodejs repos added'
}
echo
$'Installing nodejs from
debian
package
'
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$INSTALL_PACKAGES
nodejs
function
nodejs_install_
debian
_
package
{
if
[
$NODE_UPGRADE
]
;
then
return
fi
if
[
-f
"
$rootdir
/usr/bin/nodejs"
]
;
then
cp
"
$rootdir
/usr/bin/nodejs"
"
$rootdir
/usr/bin/node"
echo
$'Removing any previous nodejs installations'
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$PACKAGE_UNHOLD
nodejs
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$UPDATE_PACKAGES
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$REMOVE_PACKAGES_PURGE
nodejs
echo
$'Removing any previous nodejs binaries and modules'
if
[
-d
"
$rootdir
/usr/local/lib/node_modules"
]
;
then
rm
-rf
"
$rootdir
/usr/local/lib/node_modules"
fi
if
[
-f
"
$rootdir
/usr/local/bin/node"
]
;
then
rm
"
$rootdir
/usr/local/bin/node"
fi
if
[
-f
"
$rootdir
/usr/bin/node"
]
;
then
cp
"
$rootdir
/usr/bin/node"
"
$rootdir
/usr/local/bin/node"
rm
"
$rootdir
/usr/bin/node"
fi
if
[
-f
"
$rootdir
/usr/bin/nodejs"
]
;
then
rm
"
$rootdir
/usr/bin/nodejs"
fi
echo
$'Installing nodejs from debian package'
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$INSTALL_PACKAGES
nodejs
echo
$'Holding nodejs debian package'
# shellcheck disable=SC2086
$mesh_install_nodejs_prefix
$PACKAGE_HOLD
nodejs
}
if
[
!
-f
"
${
rootdir
}
/usr/bin/node"
]
;
then
if
[
!
-f
"
${
rootdir
}
/usr/local/bin/node"
]
;
then
if
[
!
-f
"
${
rootdir
}
/usr/bin/nodejs"
]
;
then
echo
$'nodejs was not installed'
NODE_UPGRADE
=
exit
63
fi
fi
fi
if
[
!
-f
"
$rootdir
/usr/bin/node"
]
;
then
echo
$'/usr/bin/node not found'
NODE_UPGRADE
=
exit
72
fi
function
nodejs_install_npm
{
get_npm_arch
$mesh_install_nodejs_prefix
npm config
set
unsafe-perm
true
nodejs_setup_global_modules
nodejs_fix_cpu_detection
...
...
@@ -189,41 +167,55 @@ function mesh_install_nodejs {
fi
cp
"
$rootdir
/usr/bin/npm"
"
$rootdir
/root/npm"
$mesh_install_nodejs_prefix
ln
-s
/root/.npm-global/lib/node_modules /usr/local/bin/node_modules
}
function
nodejs_install_npm_secondary
{
if
[
"
$rootdir
"
]
;
then
return
fi
# deliberate second install of npm
echo
$"Installing npm
${
NPM_VERSION
}
"
$mesh_install_nodejs_prefix
npm
install
--arch
=
$NPM_ARCH
-g
npm@
${
NPM_VERSION
}
--save
if
[
-f
"
$rootdir
/root/.npm-global/lib/node_modules/npm/bin/npm"
]
;
then
cp
"
$rootdir
/root/.npm-global/lib/node_modules/npm/bin/npm"
"
$rootdir
/usr/local/bin/npm"
cp
"
$rootdir
/root/.npm-global/lib/node_modules/npm/bin/npm"
"
$rootdir
/usr/bin/npm"
fi
if
[
-f
"
$rootdir
/usr/local/bin/npm"
]
;
then
cp
"
$rootdir
/usr/local/bin/npm"
"
$rootdir
/usr/bin/npm"
fi
cp
"
$rootdir
/usr/bin/npm"
"
$rootdir
/root/npm"
}
function
nodejs_install_n
{
# update from the old debian nodejs version
echo
$"Installing n
${
NODEJS_N_VERSION
}
on
${
NPM_ARCH
}
"
$mesh_install_nodejs_prefix
npm
install
--arch
=
$NPM_ARCH
-g
n@
${
NODEJS_N_VERSION
}
--save
if
[
!
"
$rootdir
"
]
;
then
# Don't do this if we're building an image,
# because cpu detection faults occur.
# This condition may no longer be needed in future once the bug is fixed
echo
$"Installing nodejs
${
NODEJS_VERSION
}
via n"
$mesh_install_nodejs_prefix
n
--arch
$N_ARCH
${
NODEJS_VERSION
}
nodejs_fix_cpu_detection
cp
"
$rootdir
/root/npm"
"
$rootdir
/usr/bin/npm"
cp
"
$rootdir
/root/npm"
"
$rootdir
/usr/local/bin/npm"
# deliberate second install of npm
echo
$"Installing npm
${
NPM_VERSION
}
"
$mesh_install_nodejs_prefix
npm
install
--arch
=
$NPM_ARCH
-g
npm@
${
NPM_VERSION
}
--save
if
[
-f
"
$rootdir
/root/.npm-global/lib/node_modules/npm/bin/npm"
]
;
then
cp
"
$rootdir
/root/.npm-global/lib/node_modules/npm/bin/npm"
"
$rootdir
/usr/local/bin/npm"
cp
"
$rootdir
/root/.npm-global/lib/node_modules/npm/bin/npm"
"
$rootdir
/usr/bin/npm"
fi
if
[
-f
"
$rootdir
/usr/local/bin/npm"
]
;
then
cp
"
$rootdir
/usr/local/bin/npm"
"
$rootdir
/usr/bin/npm"
fi
cp
"
$rootdir
/usr/bin/npm"
"
$rootdir
/root/npm"
}
function
nodejs_install_from_n
{
# Don't do this if we're building an image,
# because cpu detection faults occur.
# This condition may no longer be needed in future once the bug is fixed
if
[
"
$rootdir
"
]
;
then
return
fi
if
[
-f
"
$rootdir
/usr/bin/node"
]
;
then
cp
"
$rootdir
/usr/bin/node"
"
$rootdir
/usr/local/bin/node"
echo
$"Installing nodejs
${
NODEJS_VERSION
}
via n"
$mesh_install_nodejs_prefix
n
--arch
$N_ARCH
${
NODEJS_VERSION
}
nodejs_fix_cpu_detection
cp
"
$rootdir
/root/npm"
"
$rootdir
/usr/bin/npm"
cp
"
$rootdir
/root/npm"
"
$rootdir
/usr/local/bin/npm"
}
function
nodejs_check_versions
{
if
[
"
$rootdir
"
]
;
then
return
fi
if
[
!
"
$rootdir
"
]
;
then
echo
$'Checking that correct nodejs and npm versions were installed'
# check the version numbers
cat
<<
EOF
> "
$rootdir
/usr/bin/test_nodejs_install"
echo
$'Checking that correct nodejs and npm versions were installed'
# check the version numbers
cat
<<
EOF
> "
$rootdir
/usr/bin/test_nodejs_install"
#!/bin/bash
node_version=
\$
(node -v)
if [[ "
\$
node_version" != "v
${
NODEJS_VERSION
}
" ]]; then
...
...
@@ -238,14 +230,63 @@ if [[ "\$npm_version" != "${NPM_VERSION}" ]]; then
exit 2
fi
EOF
chmod
+x
"
$rootdir
/usr/bin/test_nodejs_install"
if
!
$mesh_install_nodejs_prefix
/usr/bin/test_nodejs_install
;
then
echo
$"nodejs version numbers did not match. Architecture is
$NPM_ARCH
."
NODE_UPGRADE
=
exit
76
chmod
+x
"
$rootdir
/usr/bin/test_nodejs_install"
if
!
$mesh_install_nodejs_prefix
/usr/bin/test_nodejs_install
;
then
echo
$"nodejs version numbers did not match. Architecture is
$NPM_ARCH
."
NODE_UPGRADE
=
exit
76
fi
rm
"
$rootdir
/usr/bin/test_nodejs_install"
}
function
nodejs_check_install_succeeded
{
# rename node command, so there isn't confusion between 'node' and 'nodejs'
if
[
-f
"
$rootdir
/usr/bin/nodejs"
]
;
then
cp
"
$rootdir
/usr/bin/nodejs"
"
$rootdir
/usr/bin/node"
fi
if
[
-f
"
$rootdir
/usr/bin/node"
]
;
then
cp
"
$rootdir
/usr/bin/node"
"
$rootdir
/usr/local/bin/node"
fi
# Check that the node command exists
if
[
!
-f
"
${
rootdir
}
/usr/bin/node"
]
;
then
if
[
!
-f
"
${
rootdir
}
/usr/local/bin/node"
]
;
then
if
[
!
-f
"
${
rootdir
}
/usr/bin/nodejs"
]
;
then
echo
$'nodejs was not installed'
NODE_UPGRADE
=
exit
63
fi
fi
rm
"
$rootdir
/usr/bin/test_nodejs_install"
fi
if
[
!
-f
"
$rootdir
/usr/bin/node"
]
;
then
echo
$'/usr/bin/node not found'
NODE_UPGRADE
=
exit
72
fi
}
function
mesh_install_nodejs
{
mesh_install_nodejs_prefix
=
if
[
"
$rootdir
"
]
;
then
mesh_install_nodejs_prefix
=
"chroot
$rootdir
"
fi
nodejs_setup_repo
nodejs_install_debian_package
nodejs_check_install_succeeded
nodejs_install_npm
nodejs_install_n
nodejs_install_from_n
nodejs_install_npm_secondary
if
[
-f
"
$rootdir
/usr/bin/node"
]
;
then
cp
"
$rootdir
/usr/bin/node"
"
$rootdir
/usr/local/bin/node"
fi
nodejs_check_versions
NODE_UPGRADE
=
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment