ONOS-2895 Updating onos-package for rpm creation
Change-Id: I5db3b2991e12f65caef6c29f29ab5ed915748cb3
Showing
3 changed files
with
81 additions
and
49 deletions
... | @@ -120,64 +120,26 @@ function build_deb() { | ... | @@ -120,64 +120,26 @@ function build_deb() { |
120 | # Build an RPM package | 120 | # Build an RPM package |
121 | function build_rpm() { | 121 | function build_rpm() { |
122 | read -r -p "WARN: rpm-build utility and root priviledges are need to build the package. Do you want to continue? [Y/n] " response | 122 | read -r -p "WARN: rpm-build utility and root priviledges are need to build the package. Do you want to continue? [Y/n] " response |
123 | - case $response in | 123 | + [[ "$response" =~ ^[Nn] ]] && exit 0 |
124 | - [nN][oO]) | 124 | + |
125 | - exit 0 | ||
126 | - ;; | ||
127 | - *) | ||
128 | sudo rm -fr $ONOS_RPM_ROOT | 125 | sudo rm -fr $ONOS_RPM_ROOT |
129 | 126 | ||
130 | sudo yum -y install rpm-build | 127 | sudo yum -y install rpm-build |
131 | 128 | ||
132 | - mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/ONOS-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS} | 129 | + mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/onos-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS} |
133 | 130 | ||
134 | - cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/ONOS-$ONOS_RPM_VERSION/opt/onos | 131 | + cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/opt/onos |
135 | - cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_RPM_ROOT/SOURCES/ONOS-$ONOS_RPM_VERSION/etc/init/ | 132 | + cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/etc/init/ |
136 | 133 | ||
137 | cd $ONOS_RPM_ROOT/SOURCES | 134 | cd $ONOS_RPM_ROOT/SOURCES |
138 | - COPYFILE_DISABLE=1 tar zcf ONOS-$ONOS_RPM_VERSION.tar.gz ONOS-$ONOS_RPM_VERSION | 135 | + COPYFILE_DISABLE=1 tar zcf onos-$ONOS_RPM_VERSION.tar.gz onos-$ONOS_RPM_VERSION |
139 | - | 136 | + |
140 | - { | 137 | + cp $ONOS_ROOT/tools/package/rpm/onos.spec $ONOS_RPM_ROOT/SPECS/ |
141 | - echo "Name: ONOS" | 138 | + sed -i'' -E "s/@ONOS_RPM_VERSION/$ONOS_RPM_VERSION/g" $ONOS_RPM_ROOT/SPECS/onos.spec |
142 | - echo "Version: $ONOS_RPM_VERSION" | ||
143 | - echo "Release: 1" | ||
144 | - echo "Summary: Open Networking Operating System (ONOS)" | ||
145 | - echo "Vendor: ONOS Project" | ||
146 | - echo "Packager: ONOS Project" | ||
147 | - echo "Group: Applications/Engineering" | ||
148 | - echo "Requires: jre >= 1:8" | ||
149 | - echo "License: Apache 2.0" | ||
150 | - echo "URL: http://www.onosproject.org" | ||
151 | - echo "Source0: ONOS-$ONOS_RPM_VERSION.tar.gz" | ||
152 | - echo "BuildArch: noarch" | ||
153 | - echo "BuildRoot: %{_tmppath}/%{name}-buildroot" | ||
154 | - echo "%description" | ||
155 | - echo "Open Network Operating System (ONOS) is an opensource SDN controller." | ||
156 | - echo -e "\n" | ||
157 | - echo "%prep" | ||
158 | - echo "%setup -q" | ||
159 | - echo -e "\n" | ||
160 | - echo "%install" | ||
161 | - echo "mkdir -p %{buildroot}" | ||
162 | - echo "cp -R * %{buildroot}" | ||
163 | - echo -e "\n" | ||
164 | - echo "%clean" | ||
165 | - echo "rm -rf %{buildroot}" | ||
166 | - echo -e "\n" | ||
167 | - echo "%files" | ||
168 | - echo "%defattr(-,root,root,-)" | ||
169 | - echo "/etc/init/onos.conf" | ||
170 | - echo "/opt/onos/" | ||
171 | - echo -e "\n" | ||
172 | - echo "%post" | ||
173 | - echo "echo ONOS successfully installed at /opt/onos" | ||
174 | - } > $ONOS_RPM_ROOT/SPECS/onos.spec | ||
175 | 139 | ||
176 | rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec | 140 | rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec |
177 | 141 | ||
178 | - cp $ONOS_RPM_ROOT/RPMS/noarch/ONOS-$ONOS_RPM_VERSION-1.noarch.rpm $ONOS_STAGE_ROOT && ls -l $ONOS_STAGE_ROOT/ONOS-$ONOS_RPM_VERSION-1.noarch.rpm | 142 | + cp $ONOS_RPM_ROOT/RPMS/noarch/onos-$ONOS_RPM_VERSION-1.noarch.rpm $ONOS_STAGE_ROOT && ls -l $ONOS_STAGE_ROOT/onos-$ONOS_RPM_VERSION-1.noarch.rpm |
179 | - ;; | ||
180 | - esac | ||
181 | } | 143 | } |
182 | 144 | ||
183 | # Script entry point | 145 | # Script entry point | ... | ... |
... | @@ -10,7 +10,6 @@ | ... | @@ -10,7 +10,6 @@ |
10 | sleep 1 | 10 | sleep 1 |
11 | done | 11 | done |
12 | [ -z "$(ps -ef | grep karaf.jar | grep -v grep)" ] && echo 'Stopped onos service' || echo 'Failed to stop onos' | 12 | [ -z "$(ps -ef | grep karaf.jar | grep -v grep)" ] && echo 'Stopped onos service' || echo 'Failed to stop onos' |
13 | - ps -ef | grep karaf.jar | grep -v grep | ||
14 | ) | 13 | ) |
15 | 14 | ||
16 | # Clean up onos runtime directories | 15 | # Clean up onos runtime directories | ... | ... |
tools/package/rpm/onos.spec
0 → 100644
1 | +Name: onos | ||
2 | +Version: @ONOS_RPM_VERSION | ||
3 | +Release: 1 | ||
4 | +Summary: Open Networking Operating System (ONOS) | ||
5 | +Vendor: ONOS Project | ||
6 | +Packager: ONOS Project | ||
7 | + | ||
8 | +Group: Applications/Engineering | ||
9 | +License: Apache 2.0 | ||
10 | +Requires: jre >= 1:8 | ||
11 | +URL: http://www.onosproject.org | ||
12 | +Source0: %{name}-@ONOS_RPM_VERSION.tar.gz | ||
13 | + | ||
14 | +BuildArch: noarch | ||
15 | +BuildRoot: %{_tmppath}/%{name}-buildroot | ||
16 | + | ||
17 | +%description | ||
18 | +Open Network Operating System (ONOS) is an open source SDN controller. | ||
19 | + | ||
20 | +%prep | ||
21 | +%setup -q | ||
22 | + | ||
23 | +%install | ||
24 | +mkdir -p %{buildroot} | ||
25 | +cp -R * %{buildroot} | ||
26 | + | ||
27 | +%clean | ||
28 | +rm -rf %{buildroot} | ||
29 | + | ||
30 | +%files | ||
31 | +%defattr(-,root,root,-) | ||
32 | +/etc/init/onos.conf | ||
33 | +/opt/onos/ | ||
34 | + | ||
35 | +%post | ||
36 | +ONOS_USER=sdn | ||
37 | + | ||
38 | +# Check to see if user exists, and if not, create a service account | ||
39 | +getent passwd $ONOS_USER >/dev/null 2&>1 || ( useradd -M $ONOS_USER && usermod -L $ONOS_USER ) | ||
40 | + | ||
41 | +# Create ONOS options file | ||
42 | +[ ! -f /opt/onos/options ] && cat << EOF > /opt/onos/options | ||
43 | +export ONOS_OPTS=server | ||
44 | +export ONOS_USER="$ONOS_USER" | ||
45 | +EOF | ||
46 | + | ||
47 | +# Change permissions for onos directory | ||
48 | +[ -d /opt/onos ] && chown -R $ONOS_USER.$ONOS_USER /opt/onos | ||
49 | + | ||
50 | +echo ONOS successfully installed at /opt/onos | ||
51 | + | ||
52 | +%preun | ||
53 | +# Check if onos is running; if it is, stop onos | ||
54 | +[ -z "$(status onos 2>/dev/null | grep start)" ] && echo "onos is not running." || ( | ||
55 | + stop onos | ||
56 | + | ||
57 | + # Wait for onos to stop up to 5 seconds | ||
58 | + for i in $(seq 1 5); do | ||
59 | + [ -z "$(ps -ef | grep karaf.jar | grep -v grep)" ] && break | ||
60 | + sleep 1 | ||
61 | + done | ||
62 | + [ -z "$(ps -ef | grep karaf.jar | grep -v grep)" ] && echo 'Stopped onos service' || echo 'Failed to stop onos' | ||
63 | +) | ||
64 | + | ||
65 | +%postun | ||
66 | +#TODO this should be less brute-force | ||
67 | +rm -rf /opt/onos | ||
68 | + | ||
69 | +%changelog | ||
70 | +# TODO | ||
71 | + |
-
Please register or login to post a comment