Search code examples
rpmfpm

Create rpm package using fpm with --after-install gives error


I'm new to linux packaging so I might be missing something obvious. I'm packing my program to deb and rpm packages and I'm using fpm to help me. I need people to enter their API key at the end of installation so that the configuration file could be updated automatically. I have a blah.postinst file that contains this part:

#!/bin/bash
set -e

read -p 'Please enter your API key(skip this step by just press ENTER): ' apikey_var
if [[ ! -z $apikey_var ]]
then
    echo "The API key is set. You could always change it by editing /etc/agent/process-collector.ini file"
    sed "s/sample_apikey/$apikey_var/" /etc/agent/process-collector.ini.example > /etc/agent/process-collector.ini
else
    echo "You didn't enter any API key, you could always add it by editing /etc/agent/process-collector.ini file"
    mv /etc/agent/process-collector.ini.example /etc/agent/process-collector.ini
fi

and I'm using fpm's --after-install flag to include this script.

This works for deb package, but after I use fpm to create rpm package and try to install it, the line read -p 'Please enter your API key(skip this step by just press ENTER): ' apikey_var(I think) yields error:

warning: %post(process-agent-0.99.0-1.x86_64) scriptlet failed, exit status 1
Non-fatal POSTIN scriptlet failure in rpm package dd-process-agent-0.99.0-1.x86_64

I would imagine that the code in blah.postinst script would just be fitting into the %post section of the spec file if I create an rpm package manually, but I can't figure out what could go wrong. Can anybody help on this? Or at least how do I debug this? Thanks.


Solution

  • This has been discussed before; rpms are designed to be automated. Do not expect a terminal to be there for interaction. It could be in another session (like anaconda or puppet would). It might be backgrounded. It may be a cron job. Have it collect the information on the first run or have them run a script noted in your "Getting Started" guide.