ONOS-2895 Updating onos-package for rpm creation
Change-Id: I5db3b2991e12f65caef6c29f29ab5ed915748cb3
Showing
3 changed files
with
91 additions
and
59 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 | 125 | + sudo rm -fr $ONOS_RPM_ROOT |
126 | - ;; | 126 | + |
127 | - *) | 127 | + sudo yum -y install rpm-build |
128 | - sudo rm -fr $ONOS_RPM_ROOT | 128 | + |
129 | - | 129 | + mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/onos-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS} |
130 | - sudo yum -y install rpm-build | 130 | + |
131 | - | 131 | + cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/opt/onos |
132 | - mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/ONOS-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS} | 132 | + cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/etc/init/ |
133 | - | 133 | + |
134 | - cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/ONOS-$ONOS_RPM_VERSION/opt/onos | 134 | + cd $ONOS_RPM_ROOT/SOURCES |
135 | - cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_RPM_ROOT/SOURCES/ONOS-$ONOS_RPM_VERSION/etc/init/ | 135 | + COPYFILE_DISABLE=1 tar zcf onos-$ONOS_RPM_VERSION.tar.gz onos-$ONOS_RPM_VERSION |
136 | - | 136 | + |
137 | - cd $ONOS_RPM_ROOT/SOURCES | 137 | + cp $ONOS_ROOT/tools/package/rpm/onos.spec $ONOS_RPM_ROOT/SPECS/ |
138 | - COPYFILE_DISABLE=1 tar zcf ONOS-$ONOS_RPM_VERSION.tar.gz ONOS-$ONOS_RPM_VERSION | 138 | + sed -i'' -E "s/@ONOS_RPM_VERSION/$ONOS_RPM_VERSION/g" $ONOS_RPM_ROOT/SPECS/onos.spec |
139 | - | 139 | + |
140 | - { | 140 | + rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec |
141 | - echo "Name: ONOS" | 141 | + |
142 | - echo "Version: $ONOS_RPM_VERSION" | 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 |
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 | - | ||
176 | - rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec | ||
177 | - | ||
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 | ||
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