forked from pool/nodejs-common
- Change the shell script to regular executable
OBS-URL: https://build.opensuse.org/package/show/devel:languages:nodejs/nodejs-common?expand=0&rev=11
This commit is contained in:
parent
fd2fc8377a
commit
b9f5cda917
11
node
11
node
@ -1,11 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
PROG=$(basename $0)
|
||||
PROG_VERSION=${NODE_VERSION:--default}
|
||||
|
||||
if [ ! -x /usr/bin/${PROG}${PROG_VERSION} ]; then
|
||||
echo "${PROG}${PROG_VERSION} is unavailable."
|
||||
exit 127
|
||||
fi
|
||||
exec /usr/bin/${PROG}${PROG_VERSION} "$@"
|
||||
|
85
node.c
Normal file
85
node.c
Normal file
@ -0,0 +1,85 @@
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const unsigned min_version = 4;
|
||||
const unsigned max_version = 20;
|
||||
const char *default_version = "-default";
|
||||
|
||||
const char * const supported_execs[] = {
|
||||
"node",
|
||||
"npm",
|
||||
"npx",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static void __attribute__((noreturn)) printInvalidVersion(const char *version) {
|
||||
fprintf(stderr, "Invalid node version: %s\n", version);
|
||||
exit(-2);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 1) {
|
||||
fprintf(stderr, "Invalid parameters ... no basename?\n");
|
||||
return 128;
|
||||
}
|
||||
|
||||
/* Verify we are called with supported name */
|
||||
const char *program_name = basename(argv[0]);
|
||||
const char * const * bn = supported_execs;
|
||||
|
||||
for (; *bn!=NULL; bn++) {
|
||||
if (strcmp(*bn, program_name) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (*bn == NULL) {
|
||||
fprintf(stderr, "Invalid program called: '%s'\n", program_name);
|
||||
return 129;
|
||||
}
|
||||
|
||||
/* Verify we have one of probably supported versions */
|
||||
const char *version = getenv("NODE_VERSION");
|
||||
char *endptr = 0;
|
||||
if (version == NULL || strcmp(version, default_version) == 0)
|
||||
version = default_version;
|
||||
|
||||
unsigned long node_ver = strtoul(version, &endptr, 10);
|
||||
|
||||
if (*endptr == '\0' &&
|
||||
( node_ver < min_version || node_ver > max_version))
|
||||
{
|
||||
printInvalidVersion(version);
|
||||
}
|
||||
else if (*endptr != '\0' && version != default_version)
|
||||
{
|
||||
printInvalidVersion(version);
|
||||
}
|
||||
|
||||
/* Generate our program path and check that we can execute it */
|
||||
char *program_path, *program;
|
||||
if (asprintf(&program, "%s%s", *bn, version) == -1 ||
|
||||
asprintf(&program_path, "/usr/bin/%s", program) == -1) {
|
||||
|
||||
fputs("Memory allocation error... terminating\n", stderr);
|
||||
return 130;
|
||||
}
|
||||
|
||||
if (access(program_path, X_OK) != 0) {
|
||||
perror(program_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
argv[0] = program;
|
||||
|
||||
execv(program_path, argv);
|
||||
perror("execv failed");
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
-------------------------------------------------------------------
|
||||
Fri Feb 1 15:03:12 UTC 2019 - adam.majer@suse.de
|
||||
|
||||
- Change the shell script to regular executable
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri Jun 22 12:31:05 UTC 2018 - dcassany@suse.de
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# spec file for package nodejs-common
|
||||
#
|
||||
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
|
||||
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
|
||||
#
|
||||
# All modifications and additions to the file contributed by third parties
|
||||
# remain the property of their copyright owners, unless otherwise agreed
|
||||
@ -12,7 +12,7 @@
|
||||
# license that conforms to the Open Source Definition (Version 1.9)
|
||||
# published by the Open Source Initiative.
|
||||
|
||||
# Please submit bugfixes or comments via http://bugs.opensuse.org/
|
||||
# Please submit bugfixes or comments via https://bugs.opensuse.org/
|
||||
#
|
||||
|
||||
|
||||
@ -26,22 +26,20 @@
|
||||
###########################################################
|
||||
|
||||
Name: nodejs-common
|
||||
Version: 2.0
|
||||
Version: 3.0
|
||||
Release: 0
|
||||
Summary: Common files for the NodeJS ecosystem
|
||||
License: MIT
|
||||
Group: Development/Languages/NodeJS
|
||||
Url: https://github.com/AdamMajer/nodejs-packaging
|
||||
Source1: node
|
||||
Source1: node.c
|
||||
Source2: LICENSE
|
||||
Requires: nodejs
|
||||
Conflicts: nodejs4 < 4.8.4
|
||||
Conflicts: nodejs6 < 6.11.1
|
||||
Conflicts: nodejs7 < 7.10.1
|
||||
Conflicts: nodejs8 < 8.1.4
|
||||
|
||||
BuildArch: noarch
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||
BuildRequires: gcc
|
||||
|
||||
%description
|
||||
Common NodeJS files that allow recursive invocation of Node executable
|
||||
@ -50,17 +48,17 @@ while retaining the same codestream version.
|
||||
%prep
|
||||
%build
|
||||
cp %{S:2} .
|
||||
gcc ${RPM_OPT_FLAGS} -g -o node %{S:1}
|
||||
|
||||
%install
|
||||
install -D -m 0755 %{S:1} %{buildroot}%{_bindir}/node
|
||||
ln -s node %{buildroot}%{_bindir}/npm
|
||||
ln -s node %{buildroot}%{_bindir}/npx
|
||||
install -D -m 0755 node %{buildroot}%{_bindir}/node
|
||||
ln node %{buildroot}%{_bindir}/npm
|
||||
ln node %{buildroot}%{_bindir}/npx
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
%license LICENSE
|
||||
%{_bindir}/node
|
||||
%{_bindir}/npm
|
||||
%{_bindir}/npx
|
||||
%license LICENSE
|
||||
|
||||
%changelog
|
||||
|
Loading…
Reference in New Issue
Block a user