RPM post scriptlets permission denied with docker commands - linux

So I'm building a rpm package with some pre-loaded docker image, and I want to load the image to the system and delete the image tar file after installation.
I've already achieved this in a debian package by simply adding these 2 lines in postinst file:
docker load -i <path>/image.tar
rm <some_path>/image.tar
However I got some troubles doing this in RPM package and here's the .spec file roughly looks like:
%prep
%build
%install
mkdir -p %{buildroot}/etc/my_app/
cp app %{buildroot}/etc/my_app/app
cp image.tar %{buildroot}/etc/my_app/image.tar
%post
docker load -i /etc/my_app/image.tar
rm /etc/my_app/image.tar
%files
/etc/my_app/app
/etc/my_app/image.tar
%changelog
The first problem is that when installing the package, I got /bin/docker: Permission denied error when running the %post scriptlets. (hence the image wasn't successfully loaded).
The second one is that when uninstalling the package, I got the warning: file /etc/edgexpert/image.tar: remove failed: No such file or directory. I guess this is because I put the image.tar file under $file.
So my questions would be :
how to make the docker command runnable?
where to put my image.tar file so that it can be used during %post scriptlets and won't be checked in %file
Thanks for the help.
Edited:
[vagrant#localhost ~]$ ls -l /bin/docker
-rwxr-xr-x. 1 root root 84956288 Jun 1 09:14 /bin/docker

Related

RPM build issues

I have an RPM spec file like this, I have compiled a C file and created an executable and trying to copy it to buildroot/tmp folder and trying to execute it from there,
%install
mkdir -p %{buildroot}/tmp/
install -m 755 /root/Desktop/np %{buildroot}/tmp/np
./%{buildroot}/tmp/np
%files
/tmp/np
When I try to build the RPM, I am facing an error
"/var/tmp/rpm-tmp.0HMeZn: line 35:
.//root/rpmbuild/BUILDROOT/hp-simulate-generalfailure1-1.0.0-1.x86_64/tmp/np:
No such file or directory"
Help me out to make a clean build. Thanks in advance.
Let's put aside that you are doing something very strange and executing rpmbuild as root (very nasty).
The %{buildroot} is an absolute path. See:
$ rpm --eval '%{buildroot}'
/home/msuchy/rpmbuild/BUILDROOT/%{NAME}-%{VERSION}-%{RELEASE}.x86_64
If you are really trying to execute that binary, you should not put the leading ./ there. So you snippet should be:
%install
mkdir -p %{buildroot}/tmp/
install -m 755 /root/Desktop/np %{buildroot}/tmp/np
%{buildroot}/tmp/np
%files
/tmp/np
Running anything in %install section will occur only on the build machine, during rpm build process. It will not happen when you install the RPM.
To run something upon package installation, you have to make use of scriplets:
%install
mkdir -p %{buildroot}/tmp/
install -m 755 /root/Desktop/np %{buildroot}/tmp/np
%files
/tmp/np
%post
/tmp/np
In example above, /tmp/np will be executed when package is either installed for the first time, or upgraded.

./configure: No such file or directory when getting tar.gz file

I'm creating a mac setup shell script and testing out installing Atom. They give instructions on how to Install the source, but installing source tends to take a lot longer than installing binaries.
When I run the sh script, It gets and installs the binaries,
./configure: No such file or directory
From here:
...
x atom-1.12.7/vendor/jasmine-jquery.js
x atom-1.12.7/vendor/jasmine.js
ln: /usr/local/bin/atom: File exists
/Users/danniu/Desktop/Configs/Bash Setup/mac_setup_script/install_atom.sh: line 10: ./configure: No such file or directory
make: *** No targets specified and no makefile found. Stop.
Password: _____
I've tried following these instructions, and added ./configure --prefix=~/user/local/bin/atom to configure, but it gives the same issue.
Script:
mkdir -p ~/Desktop/testing123
cd ~/Desktop/testing123
ATOM_VER=1.12.7
echo "Hello $USER. Installing Atom v$ATOM_VER"
wget https://github.com/atom/atom/archive/v$ATOM_VER.tar.gz
tar -zxvf v$ATOM_VER.tar.gz
ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom
./configure
make
sudo make install
apm install atom-beautify
apm install docblockr
apm install pigments
There's a missing step in your script:
cd atom-${ATOM_VER}
right after tar and before configure.
EDIT:
This is based on the assumption that a configure script exists!

Installing a tar.gz on Linux

I have downloaded Node.js from this link, which points to this link when clicking the button:
https://nodejs.org/dist/v4.1.2/node-v4.1.2-linux-x64.tar.gz
As advice from the Ubuntu community on installing the tar.gz, the following steps are followed.
$ ./configure
$ make
$ [sudo] make install
The problem is the current file I have downloaded does not contain ./configure.
So how do I install this? Should I extract this to the usr/ folder?
My OS is Debian 8 (Jessie).
Should I include the Java package from Oracle? Is it safe to extract these files to the /usr folder?
You can download this file from the browser or from the console. The latter is shown below (note: the specific Node.js version might be different for you):
Example :
wget http://nodejs.org/dist/v8.1.1/node-v8.1.1-linux-x64.tar.gz
sudo tar -C /usr/local --strip-components 1 -xzf node-v8.1.1-linux-x64.tar.gz
#tar options:
-x, --extract, --get
extract files from an archive
-f, --file ARCHIVE
use archive file or device ARCHIVE
-z, --gzip, --gunzip --ungzip`
You may find list of node version on http://nodejs.org/dist/
You should now have both Node.js and npm installed in “/usr/local/bin”. You can check this typing:
ls -l /usr/local/bin/node ls -l /usr/local/bin/npm
*An alternative way to install Node.js via the package manager:
Installing Node.js via package manager
Download the .tar.xz file form https://nodejs.org/en/ and then press Ctrl + Alt + T.
Then go to the destination that you downloaded your file to. For me it's my downloads folder. Then hit this command and Node.js will get installed on your system:
sudo tar -xf node-v16.0.0-linux-x64.tar.xz --directory=/usr/local --strip-components=1
This was the answer I had posted over two years ago, and here is what I recommand you right now, decompress the tarball, and keep it anywhere where your system knows ( tell it via updating $PATH ), its just a binary file, its not necessary to keep it in some specific location, you can keep it in your home directory and andd your bin folder to your bashrc or whatever shell you are using, its .rc file, and it will work just fine, at the end of the day, its just a pre-compiled binary file (inside node) nothing much.
Somebody in the comment section was saying npm, needs to be installed sepretly, this was in the early days of node back in 2012, when npm used to not ship with node, if you look inside bin folder npm binary is also there, so you dont need to install npm sepretly.
In case of installing from source code, you must download source code from https://nodejs.org/dist/v4.1.2/node-v4.1.2.tar.gz.
The file ending with .tar.gz is the compressed file like zip file, and you should extract the file before you can do another operation.
You can extract this file anywhere you need. In the terminal, change the location to your .tar.gz file:
$ cd /path/to/tar.gz/file
Then extract it using tar:
$ tar xvzf node-v4.1.2.tar.gz
Then change the location to the extracted directory
$ cd node-v4.1.2
After this, you can run .configure and 'make' it:
$ ./configure
$ make
$ [sudo] make install
Using the make utility is only necessary if you're compiling software. However, the tarballs provided by nodejs.org contain compiled binaries, not source code. Really you don't need to install it to use.
You can simply cd into the bin directory and run it via ./node. Though I'll say it's pretty useful to have it in your PATH. Where you put this directory doesn't really matter.
If you're installing it locally on your own machine, you can just untar it, tar xvfz node*tar.gz, to your home directory, add this to the file ~/.bashrc, and append the directory path your your PATH environment variable like so PATH=$PATH:/home/USERNAME/DIRECTORY/bin. Just change the path to the exact path to the bin folder in the directory you extracted.
You can also add these files to a directory that's already in your path, such as /usr/share or /usr/local by simple copying the files from the archive into these folders, as they share the same structure.
Run the following commands where your ta.xz file (no need for extraction) file is located in the terminal. NB: I used Kali Linux
sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xJvf node-v14.4.0-linux-x64.tar.xz -C /usr/local/lib/nodejs
export PATH=/usr/local/lib/nodejs/node-node-v14.4.0-linux-x64/bin:$PATH
You can now check npm -v, node -v, and npx -v.
STEP 1:
Download your version of Node.js from the Node.js website or use the below command with your version:
wget http://nodejs.org/dist/v8.1.1/node-v8.1.1-linux-x64.tar.gz
You will get a Node.js file tar file after the above step.
STEP 2:
Just use the below command for installation
sudo tar -C /usr/local --strip-components 1 -xvf node-v8.1.1-linux-x64.tar.gz
I am mentioning version-specific installation of NVM and Node.js.
If you don't have brew installed, run this:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
If you don't have wget installed, run this:
brew install wget
To install Node.js of a specific version, run these commands: Here, I'm installing NVM - v0.33.1 and Node.js of v0.12.6.
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
source ~/.bashrc
nvm install v0.12.6
command -v nvm //verify install
You can do some this:
# Using Ubuntu or Debian
curl -sL https://deb.nodesource.com/setup_[version].x | sudo -E bash -
sudo apt-get install -y nodejs
Where [version] must be replaced for your version of Node.js that you required install
For example, I required to install Node.js v.12
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
Download a suitable installation from
https://nodejs.org/en/download/
Incase of CentOS
Go to the downloaded file location
Execute the following
sudo tar -C /usr/local --strip-components 1 -xf "name of the tar.xz downloaded"
Check the installed version is correct
node --version
The given solution is correct, but it works for the source file and not the Linux distribution link used in the question above.
$ ./configure
$ make
$ [sudo] make install
The correct link is: https://nodejs.org/dist/v8.11.2/node-v8.11.2.tar.gz and we can use the above steps after downloading and extracting this file.
Download the latest version of Node.js from the official site, https://nodejs.org/en/
Steps to install:
Extract to any of the directories where you wish to install Node.js using a command or archive manager window
Open the terminal
Run '$sudo su'
Being superuser and open the profile file using 'nano ~/.profile'
At the end of the file, add:
# Node.js
export PATH=/path-to-bin.executable:$PATH
The path to bin application located within the bin folder of Node.js extracted folder is to be pasted in the above line
Save using Ctrl + O then come out by Ctrl + X
Refresh profile by the command '.~/.profile'
Come out of superuser by the 'exit' command
Again for normal users, use 'sudo'
'sudo nano ~/.profile'
Add the line at the end:
# Node.js
export PATH=/path-to-bin.executable:$PATH
Same as in step 5
Save and exit
Here the refresh command as above won't work, so restart the system to finish installation correctly
To get the version, issue 'node -v'

How to install pdftk on Amazon Linux AMI release 2012.03

I am not able to install the pdftk on Amazon Linux AMI release 2012.03. pdftk requires gcj2.14 and amazon ami provides gcj2.12 package. If I try to install gcj2.14 getting conflicts with the existing gcj package. Please suggest a way to install pdftk without any need to upgrade amazon ami linux as my application is already setup and running there.
Your help will be appreciated
Inspired by #marcus and his github repo, I just did this:
sudo wget -O /usr/lib64/libgcj.so.10 https://github.com/lob/lambda-pdftk-example/raw/master/bin/libgcj.so.10
sudo wget -O /usr/bin/pdftk https://github.com/lob/lambda-pdftk-example/raw/master/bin/pdftk
chmod a+x /usr/bin/pdftk
Works like a charm.
As you probably don't want to pollute your production image with all dependencies pdftk requires - one way is to build pdftk somewhere else and deploy it to e.g. through S3.
Following is steps should get you started. Copy and paste from history so should show steps needed.
Pick up RedHat instance from AWS (or local Centos 6)
sudo su -
yum install gcc
yum install gcc-java
yum install gcc-c++
cd /tmp/
wget http://pkgs.repoforge.org/pdftk/pdftk-1.44-2.rf.src.rpm
rpm2cpio pdftk-1.44-2.rf.src.rpm | cpio -idmv
unzip pdftk-1.44-src.zip
cd pdftk-1.44-dist/
cd pdftk
make -f Makefile.Redhat
find / -iname libgcj.so.10.0.0
mkdir -p /tmp/pdftk
cp pdftk /tmp/pdftk
find / -iname libgcj.so.10.0.0
cp /usr/lib64/libgcj.so.10.0.0 /tmp/pdftk
cd /tmp/
tar cvzf pdftk.tar.gz pdftk
Make sure you copy tar package content in target machine (Linux AMI) as follows
libgcj.so.10.0.0 install to /usr/lib64
ls -alh /usr/lib64/libgcj.so.*
lrwxrwxrwx 1 root root 27 Sep 6 06:39 /usr/lib64/libgcj.so.10 -> /usr/lib64/libgcj.so.10.0.0
-rwxr-xr-x 1 root root 47M Sep 6 06:38 /usr/lib64/libgcj.so.10.0.0
I just used to S3 bucket to transfer file:
/usr/bin/s3cmd --force get s3://<your-bucket>/rpm/pdftk.tar.gz /tmp/
pushd /tmp
/bin/tar xzf pdftk.tar.gz
/bin/cp pdftk/pdftk /usr/bin/
/bin/cp pdftk/libgcj.so.10.0.0 /usr/lib64/libgcj.so.10.0.0
/bin/ln -s /usr/lib64/libgcj.so.10.0.0 /usr/lib64/libgcj.so.10.0
/sbin/ldconfig
popd
Very old post, but I've been looking into ways to get pdftk installed on the Amazon distro (which is what the OP is using). Here's a response from an Amazon rep:
GCJ is not supported on the Amazon Linux AMI, which is why you are
running into this problem.
In the interest of getting you moving forward as quickly as possible
on an EC2 instance that is RPM based, I'd recommend that you give
Fedora a try, because pdftk is packaged in their repositories.
Thank you for using EC2, and I hope this suggestion helps you out.
https://forums.aws.amazon.com/thread.jspa?threadID=96919

rpmbuild: how to build the package without %install?

I am trying to build a rpm but unfortunately in my build machine I only have limted permission, which means the operation in %install can't be done inside the build machine. How to build the package(.rpm file) without running %install section? It looks like that no options are available for this purpose:
http://www.rpm.org/max-rpm-snapshot/ch-rpm-b-command.html
My bu.spec file:
Summary: xxxx
Name: xx
Version: 1.0
Release: 1
Group: Applications/Sound
License: Share
%description
%prep
echo "prep"
%build
%install
echo "install"
mkdir -p /opt/xcp_src/
cp scripts.tgz /opt/xcp_src/
%files
/tmp/xcp_src/scripts.tgz
%post
cd /opt/xcp_src/
tar zxvf scripts.tgz
First off, set a buildroot and use that in install, eg:
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
...
%install
mkdir -p %{buildroot}/opt/xcp_src
Second, make sure you can build without being root by moving the RPM build area.
I'd also suggest specifying an actual list of files (rather than having RPM extract a tgz file) as that would make the package cleanly removable.

Resources