Publish RPM to Artifactory using FPM
install FPM on centos box,
this script takes files that are in $dev_dir and places them in "real world" places (in section # overwrite model files)
then it uses FPM to generate RPM pkg, uploads the package to Artifactory and deletes the RPM locally
#!/bin/bash
# This script creates a new RPM package from various files and uploads it to Artifactory
# set -x
# Artif settings
artif_server="artifactory.corp.com"
artif_port="8081"
artif_repo_path="test_repo/rpms"
artif_key="xxxyyyyzzzabc1234"
# params
base_dir="/opt/product"
dev_dir="/home/user/dev/product"
if [ ! $(whoami) = "root" ]
then
echo "[ERROR] Not root! run this script as root"
exit 1
fi
function check4error() {
if [ "$?" -ne 0 ]; then echo "${1} step failed"; exit 1; fi
}
# check if FPM is installed and version 1.4
fpmver=$(gem list | grep fpm)
if [ ! "${fpmver}" == "fpm (1.4.0)" ]
then
echo "[ERROR] FPM is not installed here or not version 1.4, exiting"
exit 1
fi
# cleanup model files
rm -rf /opt/product
check4error "rm -rf model files"
rm -rf /etc/init.d/product
check4error "rm -rf model files"
mkdir $base_dir
check4error "mkdir base_dir"
echo "----- building pkg in directory:" $dev_dir
cd $dev_dir
# overwrite model files
yes | cp -rf product /etc/init.d/
yes | cp -rf script.py $base_dir/
yes | cp -rf conf $base_dir/conf
yes | cp -rf modules $base_dir/modules
yes | cp -rf repos $base_dir/repos
yes | cp -rf projects $base_dir/projects
version=$(cat version)
echo "----- FPM time!"
fpm -s dir -t rpm -n "myProduct" -v $version /opt/product /etc/init.d/product
check4error "fpm make new RPM"
rpm_name=$(ls myProduct*.rpm)
echo "----- upload RPM to artifactory using API key"
curl -H "X-JFrog-Art-Api:${artif_key}" -X PUT "http://${artif_server}:${artif_port}/artifactory/${artif_repo_path}/${rpm_name}" -T $rpm_name
printf "\n----- delete RPM after upload..."
rm -rf myProduct*.rpm
check4error "rm -rf RPM"
printf "\n----- done packaging -----\n"