This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpmbuild-fedora20.sh
executable file
·128 lines (105 loc) · 3.59 KB
/
rpmbuild-fedora20.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
#!/bin/bash
# Argument = -h (shows the help information)
# Argument = -i (Instance type)
# Argument = -o (Owner ID)
# Argument = -p (package name .i.e nginx)
# Argument = -u (ulyaoth package name .i.e ulyaoth-nginx)
usage()
{
cat << EOF
usage: $0 options
OPTIONS:
-h Shows this help information
-i Instance Type
-o Owner ID
-p Package Name
-u Ulyaoth Package Name
EOF
}
function getamiid ()
{
imageid=`aws ec2 describe-images --owners $ownersid --filters "Name=name,Values=rpmbuild-fedora20-*" --query Images[].ImageId --output text`
}
function waitforstate ()
{
while :
do
state=$(aws ec2 describe-instances --filters "Name=image-id,Values=$imageid" "Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped" --query 'Reservations[].Instances[].State[].Name[]' --output text)
/bin/sleep 5
if [[ $state == "running" ]]
then
break
fi
done
}
# Builds the rpm
function build-package ()
{
/bin/sleep 30
/usr/bin/ssh -t -oStrictHostKeyChecking=no -i rpmbuild-old-openssl.pem ulyaoth@$ip "wget https://raw.githubusercontent.com/ulyaoth/repository/master/$ulyaothpackage/build-$package.sh ; chmod +x build-$package.sh ; ./build-$package.sh" >> /dev/null 2>&1
}
# scp the package to local machine
function scp-package ()
{
scp -oStrictHostKeyChecking=no -i rpmbuild-old-openssl.pem ulyaoth@$ip:/home/ulyaoth/rpmbuild/RPMS/x86_64/*debug*.rpm /Users/sbagmeijer/rpmbuild/rpms/fedora/20/x86_64/debug/ >> /dev/null 2>&1
/usr/bin/ssh -t -oStrictHostKeyChecking=no -i rpmbuild.pem ulyaoth@$ip "rm -rf /home/ulyaoth/rpmbuild/RPMS/x86_64/*debug*.rpm && rm -rf /home/ulyaoth/rpmbuild/RPMS/x86_64/*debuginfo*.rpm" >> /dev/null 2>&1
scp -oStrictHostKeyChecking=no -i rpmbuild-old-openssl.pem ulyaoth@$ip:/home/ulyaoth/rpmbuild/RPMS/x86_64/*.rpm /Users/sbagmeijer/rpmbuild/rpms/fedora/20/x86_64/os/ >> /dev/null 2>&1
scp -oStrictHostKeyChecking=no -i rpmbuild-old-openssl.pem ulyaoth@$ip:/home/ulyaoth/rpmbuild/RPMS/noarch/*.rpm /Users/sbagmeijer/rpmbuild/rpms/fedora/20/x86_64/os/ >> /dev/null 2>&1
scp -oStrictHostKeyChecking=no -i rpmbuild-old-openssl.pem ulyaoth@$ip:/home/ulyaoth/rpmbuild/SRPMS/*.rpm /Users/sbagmeijer/rpmbuild/rpms/fedora/20/source/ >> /dev/null 2>&1
}
# Gets the IP of the EC2 instance
getip ()
{
ip=$(aws ec2 describe-instances --filters "Name=image-id,Values=$imageid" "Name=instance-state-name,Values=pending,running" --query 'Reservations[].Instances[].PublicIpAddress[]' --output text)
}
# Start the EC2 instance
function start ()
{
# Get the ami id
getamiid
# Start the instance
aws ec2 run-instances --image-id $imageid --count 1 --instance-type $instance_type --key-name rpmbuild-old-openssl --security-groups rpmbuild >> /dev/null 2>&1
# waiting for instance to be running
waitforstate
# Sleep 90 seconds
/bin/sleep 90
# Get EC2 public IP
getip
# Build the rpm package
build-package
# scp package to local machine
scp-package
# terminate ec2 instance
terminate
}
# Stop the EC2 Instance
function terminate ()
{
instance=$(aws ec2 describe-instances --filters "Name=image-id,Values=$imageid" "Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped" --query 'Reservations[].Instances[].InstanceId[]' --output text)
aws ec2 terminate-instances --instance-ids $instance >> /dev/null 2>&1
exit 0
}
# Set required variables.
instance_type=""
package=""
ulyaothpackage=""
while getopts h:i:o:p:u: opt; do
case $opt in
h)
usage
;;
i)
instance_type=$OPTARG
;;
o)
ownersid=$OPTARG
;;
p)
package=$OPTARG
;;
u)
ulyaothpackage=$OPTARG
;;
esac
done
start