I have a .sh script that I packaged as .rpm to distribute. I'm using GitLab CI CD pipeline using gitlab-ci.yml. I'm able to pacakge the script in .rpm with no problems using the .spec.
The issue is when I install the .rpm (after uploading and downloading) in various systems for testing and make sure it does what I expect it to do.
So in the .spec file I specify that I want to install it in /usr/bin/myscript.sh with the following in .spec file:
%build
%install
rm -rf %{buildroot}
mkdir -p $RPM_BUILD_ROOT/%{_prefix}/bin
install -m 755 -p $RPM_BUILD_DIR/myscript.sh $RPM_BUILD_ROOT/%{_prefix}/bin/
So to test the newly created .rpm I try to install in 2 different containers
First one called centos
Output
[root#1235 /]# curl -O http://url/srpms/myscript-1.0-1.el7.src.rpm
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5773 100 5773 0 0 626k 0 --:--:-- --:--:-- --:--:-- 626k
[root#1235 /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var myscript-1.0-1.el7.src.rpm
[root#1235 /]# rpm -iv myscript-1.0-1.el7.src.rpm
myscript-1.0-1.el7.noarch
[root#1235 /]# rpm -ql xsoar*
myscript.sh
myscript.spec
[root#1235 /]# find . -type f -name "myscript.sh" 2>/dev/null
./root/rpmbuild/SOURCES/myscript.sh
[root#1235 /]#
As you can see the script ends up in a path that was created by the installation itself ./root/rpmbuild/SOURCES/ instead of the expected /usr/bin/
For the next container I used the same image/container used by gitlab-ci.yml to package the .rpm
Output
[root#5704de76a68c /]# rpm -iv myscript-1.0-1.el7.src.rpm
myscript-1.0-1.el7.noarch
[root#5704de76a68c /]# rpm -ql xsoar*
package myscript-1.0-1.el7.src.rpm is not installed
[root#5704de76a68c /]# find . -type f -name "myscript.sh" 2>/dev/null
./root/rpmbuild/SOURCES/myscript.sh
[root#5704de76a68c /]#
Similar result but it says .rpm is not installed
Then for the heck of I tried installing the .rpm in the same instance/container right after creation using gitlab-ci.yml (before it gets uploaded to any repo for distribution) and I do get the expected result
Output
$ rpm -ivh $HOME/rpmbuild/RPMS/noarch/*.rpm
Preparing... ########################################
Updating / installing...
myscript-1.0-1.el7 ########################################
$ rpm -ql myscript
/usr/bin/myscript.sh
Part of the .spec
%prep
cp -fp %{SOURCE0} ./
%build
%install
rm -rf %{buildroot}
mkdir -p $RPM_BUILD_ROOT/%{_prefix}/bin
install -m 755 -p $RPM_BUILD_DIR/myscript.sh $RPM_BUILD_ROOT/%{_prefix}/bin/
%clean
rm -rf %{buildroot}
%files
%attr(755,root,root) %{_prefix}/bin/myscript.sh
Found the issue. Of course it had to be stupid. For my testing i was installing myscript.src.rpm instead of myscript.noarch.rpm
I am using fpm to generate my debian package from a directory which contains my bash script.
The directory has only this bash script. I want to add a man page to the package so that I can view the man page using man command after installing my deb package . how to do so ?
What's the fpm option or command to include the created manpage in the package ?
Add usr/share/man with your man pages to the option on fpm
In my makefile which runs fpm I have ronn which creates man.5 pages from markdown.
#mkdir -p pkg/tmp/usr/share/man/man5
#ronn -r README.md --pipe > pkg/tmp/usr/share/man/man5/example.5
(cd pkg && \
fpm -s dir -t deb -C tmp ---other-stuff usr/share/man)
See the docs example:
https://fpm.readthedocs.io/en/latest/use-cases/make-install.html#package-up-the-manpages-create-nodejs-doc
I created an node.js Docker image.
Using CMD node myapp.js in the end of my Dockerfile, it starts.
But when I use CMD /root/start.sh, then it fails.
This is how my start.sh looks like:
#!/bin/bash
node myapp.js
And here are the important lines of my Dockerfile:
FROM debian:latest
COPY config/start.sh /root/start.sh
RUN chmod +x /root/start.sh
WORKDIR /my/app/directory
RUN apt-get install -y wget && \
wget https://nodejs.org/dist/latest-v5.x/node-v5.12.0-linux-x64.tar.gz && \
tar -C /usr/local --strip-components 1 -xzf node-v5.12.0-linux-x64.tar.gz && \
rm -f node-v5.12.0-linux-x64.tar.gz && \
ln -s /usr/bin/nodejs /usr/bin/node
# works:
CMD node myapp.js
# doesn't work:
CMD /root/start.sh
Using docker logs I get: standard_init_linux.go:175: exec user process caused "no such file or directory"
But I don't understand, because if I add RUN ls /root in my Dockerfile, I can see the file exists.
I also tried with full paths in my script:
#!/bin/bash
/usr/bin/node /my/app/directory/myapp.js
but nothing changed. So what can be the problem?
Use docker run -entrypoint="/bin/bash" -i your_image.
What you used is the shell form of dockerfile CMD. As described in the doc, the default shell binary is /bin/sh, not as your expected /bin/bash in start.sh line 1.
Or try using exec form, that is CMD ["/root/start.sh"].
Most common error I've seen is creating the start.sh on a Windows system and saving the file either with a different character encoding or including windows linefeeds. The /bin/bash^M is not the same as /bin/bash but you won't see that linefeed on Windows. You also want to save the file in ascii encoding, not any of the multi-character UTF encodings.
I am building my own Debian-based Linux with own kernel and software. One of the last steps of the make-process has to be done in a chrooted environment:
Install the custom kernel using dpkg
Create symbolic links to the kernel and initrd.img
Execute ldconfig
Set my custom theme for the splash screen using plymouth
Update the initrd.img
While the installation of the kernel succeeds and the symbolic links are acutally created, all other commands do not seem to work. If I boot into the system the splash screen is set to the default and the initrd.img cannot find the HDD nor the kernel. So the updating of the initrd.img inside the dpkg-installation process seems to fail somehow. The plymouth script to set the theme does not work either.
To fix this, I manually chroot into the system and do the following:
Set my custom theme for the splash screen using plymouth
Execute ldconfig
Update the initrd.img
This works perfectly fine. Next time I boot the system, my splash screen is shown and everything starts properly.
Here is my approach to get this done in my Makefile:
cp $(INTEGRATION_KERNEL_IMAGE) $(ROOTFS)/tmp/kernel.deb
cd $(ROOTFS); /usr/bin/sudo /bin/mount -t proc proc proc/; /usr/bin/sudo /bin/mount -t sysfs sys sys/; /usr/bin/sudo /bin/mount -o bind /dev dev/
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/usr/bin/dpkg --force-not-root -i /tmp/kernel.deb"
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/bin/ln -nsf vmlinuz-3.2.54-rt75custom /boot/vmlinuz"
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/bin/ln -nsf initrd.img-3.2.54-rt75custom /boot/initrd.img"
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/sbin/ldconfig"
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/bin/bash /usr/sbin/plymouth-set-default-theme my_theme"
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/bin/bash /usr/sbin/update-initramfs -u"
/usr/bin/sudo /bin/umount $(ROOTFS)/proc; /usr/bin/sudo /bin/umount $(ROOTFS)/sys; /usr/bin/sudo /bin/umount $(ROOTFS)/dev
The output of make does not provide any errors on this topic. Well, it possibly cannot do this because make does not know what is going on inside the chrooted environment. But how can I find out what is going wrong?
A possible workaround would be to put everything I mentioned above in a shell script and execute this in the chrooted environment. But I would prefer to do everything in the Makefile and I do not know if the workaround really works. I have not verified this yet.
Have you tried saving command output in the chroot environment and extracting it later? For example:
/usr/sbin/chroot [...] bash -c "/usr/bin/dpkg [...] >> /root/chroot.log"
or
/usr/sbin/chroot [...] bash -c "/usr/bin/dpkg [...] | tee -a /root/chroot.log"
followed by
cp $(ROOTFS)/root/chroot.log .
In the long run I would suggest to avoid code duplication and Makefile clutter, either by passing everything in a single chroot command or by copying over a script.
You should be able to get rid of most or all of the bash -c and /bin/bash invocations. That should simplify things even more.
My production server (Centos 5.9) won't compile nodejs, possibly because it's gcc is only 4.1.2 (4.2 or above is recommended) so I've trying to install the binaries.
$ wget http://nodejs.org/dist/v0.10.22/node-v0.10.22-linux-x86.tar.gz
$ tar -zxvf node-v0.10.22-linux-x86.tar.gz
$ cd node-v0.10.22-linux-x86
$ sudo cp bin/* /usr/local/bin
$ sudo cp -R lib/* /usr/local/lib
$ sudo cp -R share/* /usr/local/share
And now for testing:
$ node -v # => v0.10.22
$ man node # looks fine
$ npm -v # UH OH, PROBLEM - Cannot find module 'npmlog'
Now (keeping in mind I'm a complete beginner at node) I did some searching and found there's an environment variable called NODE_PATH, so I tried:
$ export NODE_PATH=/usr/local/lib/node_modules
$ npm -v # SAME PROBLEM - Cannot find module 'npmlog'
So then I found out where npmlog lives and tried modifying NODE_PATH accordingly:
$ find /usr/local/lib -name npmlog # => /usr/local/lib/node_modules/npm/node_modules/npmlog
$ export NODE_PATH=/usr/local/lib/node_modules/npm/node_modules
$ npm -v # DIFFERENT PROBLEM - Can't find '../lib/npm.js'
At this stage, after more unhelpful googling, I decided I was in over my depth and decided to ask for help. Can anyone tell me what I'm doing wrong?
It is much faster to do clean NPM reinstall which will remove "broken" links:
wget https://npmjs.org/install.sh
chmod +x install.sh
sudo ./install.sh
Then it will ask you to remove old NPM link
Using Node Version Manager
Use a Node version manager like nvm to handle installation and version management for you. After you install nvm you can simply install any Node version, for example nvm install 8.
But if you just want to install the binary yourself, see below:
Using apt-get
In special cases where you need a system wide Node installation, you can use apt-get:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
The above snippet will install the latest Node 8.
Installing the Binary Manually
In order to install the binary manually, all you need to do is to download the binary and create a bunch of symbolic links. Execute the commands below one after the other, and it should do the job. I have also written a shell script that does it for you if that is easier (see the bottom of the answer). Hope that helps.
Make sure to use the correct download link for your OS architecture (i.e. either 32-bit or 64-bit) for wget on the second line.
ME=$(whoami) ; sudo chown -R $ME /usr/local && cd /usr/local/bin #adding yourself to the group to access /usr/local/bin
mkdir _node && cd $_ && wget https://nodejs.org/dist/v8.11.4/node-v8.11.4-linux-x64.tar.xz -O - | tar zxf - --strip-components=1
ln -s "/usr/local/bin/_node/bin/node" .. # Making the symbolic link to node
ln -s "/usr/local/bin/_node/lib/node_modules/npm/bin/npm-cli.js" ../npm ## making the symbolic link to npm
Here is a shell script that downloads and installs all the components. If you use this script to install Node, you can use the uninstall script to uninstall it.
Installing Node
#! /bin/bash
# run it by: bash install-node.sh
read -p " which version of Node do you need to install: for example 8.11.4 (or any other valid version): " VERSIONNAME
read -p " Are you using a 32-bit or 64-bit operating system ? Enter 64 or 32: " ARCHVALUE
if [[ $ARCHVALUE = 32 ]]
then
printf "user put in 32 \n"
ARCHVALUE=86
URL=https://nodejs.org/dist/v${VERSIONNAME}/node-v${VERSIONNAME}-linux-x${ARCHVALUE}.tar.gz
elif [[ $ARCHVALUE = 64 ]]
then
printf "user put in 64 \n"
ARCHVALUE=64
URL=https://nodejs.org/dist/v${VERSIONNAME}/node-v${VERSIONNAME}-linux-x${ARCHVALUE}.tar.gz
else
printf "invalid input expted either 32 or 64 as input, quitting ... \n"
exit
fi
# setting up the folders and the the symbolic links
printf $URL"\n"
ME=$(whoami) ; sudo chown -R $ME /usr/local && cd /usr/local/bin #adding yourself to the group to access /usr/local/bin
mkdir _node && cd $_ && wget $URL -O - | tar zxf - --strip-components=1 # downloads and unzips the content to _node
cp -r ./lib/node_modules/ /usr/local/lib/ # copy the node modules folder to the /lib/ folder
cp -r ./include/node /usr/local/include/ # copy the /include/node folder to /usr/local/include folder
mkdir /usr/local/man/man1 # create the man folder
cp ./share/man/man1/node.1 /usr/local/man/man1/ # copy the man file
cp bin/node /usr/local/bin/ # copy node to the bin folder
ln -s "/usr/local/lib/node_modules/npm/bin/npm-cli.js" ../npm ## making the symbolic link to npm
# print the version of node and npm
node -v
npm -v
Uninstalling Node
#! /bin/bash
# run it by: ./uninstall-node.sh
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/lib/node_modules/
sudo rm -rf /usr/local/include/node/
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/bin/_node/
I had a problem like that, but with iojs. However it should be the same procedure:
(Assuming that you've got a file matching node-v*-linux-x64.tar.gz in your current directory):
# In case of iojs you need to replace the occurrences of 'node' with 'iojs'
# Extract the downloaded archive with the linux-x64 version of node
tar zxf node-v*-linux-x64.tar.gz
# Move the extracted folder (./node-v*-linux-x64/) to /opt/
mv ./node-v*-linux-x64/ /opt/
To make the binary files available in your shell, create some softlinks inside the /usr/bin/ directory:
# Create a softlink to node in /usr/bin/
ln -s /opt/node-v*-linux-x64/bin/node /usr/bin/node
# Create a softlink to npm in /usr/bin/
ln -s /opt/node-v*-linux-x64/bin/npm /usr/bin/npm
# Create a softlink to iojs in /usr/bin (this step can be omitted if you're using node)
ln -s /opt/node-v*-linux-x64/bin/iojs /usr/bin/iojs
Notice: If you'd like to access the cli of some globally installed node modules (for example bower, typescript or coffee-script), you're required to create a softlink to each of those executables in the /usr/bin/ directory.
Alternatively you could just add the bin directory of your node installation directory (e.g. /opt/node-v*-linux-x64/) to the PATH environment variable: (you should use the absolute path for this!)
# create a new .sh script in /etc/profile.d which adds the directory to PATH
echo "export PATH=$PATH:/opt/node-v0.12.3-linux-x64/bin" > /etc/profile.d/node-npm.sh
This change will take effect after logging out and in again.
Both methods worked for me (I use a linux desktop version of Ubuntu 14.04/15.04 with GNOME 3).
I had the same issue reported here. Fixed it by removing /usr/local/bin/npm and replacing it with a symlink to /usr/local/lib/node_modules/npm/bin/npm-cli.js
$ ls -l /usr/local/bin/
node
npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
$ npm -v
1.3.17
wget <node archive url from nodejs.org>
cd /usr/local
sudo tar --strip-components 1 -xf <path to node archive>
You can run node and npm right away.
It used to be documented in the README inside the archive in older versions.
I had the same problem and I was able to resolve it by creating symlinks instead of copying the binaries.
$ cd /usr/local/src
$ wget http://nodejs.org/dist/v0.10.24/node-v0.10.24-linux-x64.tar.gz
$ tar -zxvf node-v0.10.24-linux-x64.tar.gz
$ cd node-v0.10.24-linux-x64
$ sudo cp -R lib/* /usr/local/lib
$ sudo cp -R share/* /usr/local/share
$ ln -s /usr/local/src/node-v0.10.24-linux-x64/bin/node /usr/local/bin/node
$ ln -s /usr/local/src/node-v0.10.24-linux-x64/bin/npm /usr/local/bin/npm
$ node -v
v0.10.24
$ npm -v
1.3.21
I tend to use nave to install the binaries. Use wget to download the nave.sh file and then us it to install node. Nave is also nice to have around in case one of your production apps requires a different version of node than what's installed globally.
$ wget https://raw.github.com/isaacs/nave/master/nave.sh
$ sudo bash nave.sh usemain 0.10.22
You can use GNU stow to make symbolic links of those binaries in /usr/local properly with one command. Stow also allows you to easily remove Node js from /usr/local at a later time and swap multiple versions of Node js.
$ # first, install stow
$ mkdir /usr/local/stow # if it doesn't exist
$ # then, place software binary package in /usr/local/stow
$ cd /usr/local/stow
$ stow <package_name> # install / add sym links
$ source $HOME/.bash_profile # reload your environment
$ # node -v and npm -v should now work
$ stow -D <package_name> # uninstall / remove sym links
These steps worked for me with node-v0.10.17-linux-x64.
In the man page of cp in Mac OS X:
Symbolic links are always followed unless the -R flag is set, in which case symbolic links are not followed, by default.
When you execute sudo cp bin/* /usr/local/bin, the symbolic link bin/npm is followed.
Actually, bin/npm is linked to ../lib/node_modules/npm/bin/npm-cli.js, so cp will copy npm-cli.js to /usr/local/bin. That's why you get an error.
I had the same problem.
The problem is the npm excutable in /usr/local/bin.
The way I solved it was:
sudo rm /usr/local/bin/npm
sudo ln -s "/usr/local/lib/node_modules/npm/bin/npm-cli.js" /usr/local/bin/npm
In Ubuntu there is a .bashrc file which sets path to binaries.
By default, there is path set for bin in home directory. Perhaps you can create bin directory in your home directory and move the binaries there. Reboot your system and try executing the command node
I faced the same problem. So, I symlinked node and npm from ./bin/ to /usr/local/bin
If someone is interested in using Docker, in the Dockerfile,
ENV NODE_VERSION 8.10.0
RUN wget https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz
RUN tar -xJvf node-v$NODE_VERSION-linux-x64.tar.xz -C /usr/local/
ENV NODEJS_HOME /usr/local/node-v$NODE_VERSION-linux-x64
ENV PATH $NODEJS_HOME/bin:$PATH
RUN node --version
RUN npm --version