-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildrpm.sh
136 lines (115 loc) · 3.84 KB
/
buildrpm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#! /usr/bin/env bash
#title :buildrpm.sh
#description :This script downloads all individual jar files and builds them into rpms
#author :Naga Deepak Pothuraju
#date :20170525
#version :0.1
#usage :bash buildrpm.sh
#notes :Install vim to use this script.
#==============================================================================
# This script assumes that the machine this is being run on has an active yum repo server running on it at the location $repodir below.
# Setting some fancy colors
red=`tput setaf 1`
yellow=`tput setaf 3`
reset=`tput sgr0`
ip=`hostname -i`
# Check if rpmbuild tools are already installed
if [ "$ip" == "10.242.251.245" ];
then
if rpm -qa | grep rpmdevtools 2>&1 > /dev/null && rpm -qa | grep rpm-build 2>&1 > /dev/null ;
then
continue
else
printf $yellow"ERROR: Please install packages "rpmdevtools" & "rpm-build" before continuing.\n"$reset
printf $reset"Type [$red y $reset] to allow me to install them now: "
read agree
if [ $agree == "y" ];
then
yum install rpmdevtools rpm-build
continue
else
printf $yellow"This script is exiting now.\n"$reset
exit 1
fi
fi
else
echo "This script is not yet fully designed to run on any other machine except 10.242.251.245. Please take a look at the script before proceeding."
exit 1
fi
# Start of the script
printf "This script builds the rpms for a given sprint & build number\n ================\n"
# Take user input
printf "Enter the sprint number: "
read sprint
printf "Enter the build number: "
read build
# Variables
url="http://gec-maven-nexus.walmart.com/nexus/content/repositories/inkiru_releases/ink_sprint$sprint/$build/"
lst=( $(wget -qO- $url | grep -oE "\"http://.*.jar\"" | tr -d '"') )
rpmroot="$HOME/rpmbuild"
repodir="/var/www/html/repos/inkiru/$sprint-$build"
numbuilds=6
# Download all the jars
for i in "${lst[@]}"
do
filename=$( echo $i | awk -F "/" '{print $NF}' )
filewithoutext=$( echo $i | awk -F "/" '{print $NF}' | awk -F "." '{print $1}' )
if [ -a $filename ]
then rm -f $filename
fi
curl $i --create-dirs -o $rpmroot/SOURCES/$filewithoutext-$sprint/$filename
# Tar the jars before rolling into rpms
cd $rpmroot/SOURCES/
tar cvzf $filewithoutext-$sprint.tar.gz $filewithoutext-$sprint
cd -
# Create individual spec files from the template
cat > /tmp/$filewithoutext.spec <<-EOF
Name: $filewithoutext
Version: $sprint
Release: $build
Summary: Inkiru Apps
URL: $url
BuildArch: noarch
Source0: %{name}-%{version}.tar.gz
License: Proprietary
Group: Inkiru
BuildRoot: %{_tmppath}/%{name}-buildroot
%description
This package installs the $filewithoutext application.
%prep
%setup -q
%build
%install
rm -rf %{buildroot}
install -m 0755 -d \$RPM_BUILD_ROOT/home/inkadmin/inkiru/lib/
install -m 0755 $filename \$RPM_BUILD_ROOT/home/inkadmin/inkiru/lib/$filename
%clean
rm -rf \$RPM_BUILD_ROOT
%post
%files
%defattr(755,inkadmin,inkadmin)
%dir /home/inkadmin/inkiru/lib/
/home/inkadmin/inkiru/lib/$filename
EOF
# Build the rpms
rpmbuild -ba /tmp/$filewithoutext.spec
#yum install -y $rpmroot/RPMS/noarch/$filewithoutext*noarch.rpm
# Copy the rpms to the repositories
cp -ra $rpmroot/RPMS/noarch/$filewithoutext-$sprint-$build.noarch.rpm $repodir/
done
# Creating the repodir if it doesn't exist
if [ ! -d $repodir ]; then
mkdir $repodir
fi
# Cleaning repositories older than 4 builds
if [ $(find $repodir/../* -maxdepth 0 -type d -print | wc -l) -gt $numbuilds ] ; then
ls -d -1 $repodir/../* | head -n -$numbuilds | xargs echo
fi
# Initialize the repo with fresh data
if find "$repodir" -mindepth 1 -print -quit | grep -q .; then
echo "Updating repository..."
createrepo --update $repodir/../.
else
echo "This looks like a new repository, initializing it..."
createrepo $repodir/../.
fi