-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpm-test.spec
189 lines (152 loc) · 4.54 KB
/
rpm-test.spec
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
Name: rpm-test
Version: 0.1.0
Release: 1
Summary: Test rpm package
License: BSD
Vendor: typesafe
URL: http://github.com/sbt/sbt-native-packager
AutoProv: yes
AutoReq: yes
BuildRoot: /home/andreas/dev/scriptlets-override-rpm/target/rpm/buildroot
BuildArch: noarch
%description
Description
%install
if [ -e "$RPM_BUILD_ROOT" ]; then
mv "/home/andreas/dev/scriptlets-override-rpm/target/rpm/tmp-buildroot"/* "$RPM_BUILD_ROOT"
else
mv "/home/andreas/dev/scriptlets-override-rpm/target/rpm/tmp-buildroot" "$RPM_BUILD_ROOT"
fi
%pre
# #######################################
# ## SBT Native Packager Bash Library ##
# #######################################
# Adding system user
# $1 = user
# $2 = uid
# $3 = group
# $4 = description
# $5 = shell (defaults to /bin/false)
addUser() {
user="$1"
if [ -z "$user" ]; then
echo "usage: addUser user [group] [description] [shell]"
exit 1
fi
uid="$2"
if [ -z "$uid" ]; then
uid_flags=""
else
uid_flags="--uid $uid"
fi
group=${3:-$user}
descr=${4:-No description}
shell=${5:-/bin/false}
if ! getent passwd | grep -q "^$user:";
then
echo "Creating system user: $user in $group with $descr and shell $shell"
useradd $uid_flags --gid $group -r --shell $shell -c "$descr" $user
fi
}
# Adding system group
# $1 = group
# $2 = gid
addGroup() {
group="$1"
gid="$2"
if [ -z "$gid" ]; then
gid_flags=""
else
gid_flags="--gid $gid"
fi
if ! getent group | grep -q "^$group:" ;
then
echo "Creating system group: $group"
groupadd $gid_flags -r $group
fi
}
# Will return true even if deletion fails
# $1 = user
deleteUser() {
if hash deluser 2>/dev/null; then
deluser --quiet --system $1 > /dev/null || true
elif hash userdel 2>/dev/null; then
userdel $1
else
echo "WARNING: Could not delete user $1 . No suitable program (deluser, userdel) found"
fi
}
# Will return true even if deletion fails
# $1 = group
deleteGroup() {
if hash delgroup 2>/dev/null; then
delgroup --quiet --system $1 > /dev/null || true
elif hash groupdel 2>/dev/null; then
groupdel $1
else
echo "WARNING: Could not delete user $1 . No suitable program (delgroup, groupdel) found"
fi
}
# #######################################
# Scriptlet syntax: http://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Syntax
# $1 == 1 is first installation and $1 == 2 is upgrade
if [ $1 -eq 1 ] ;
then
# Adding system user/group : rpm-test and rpm-test
addGroup rpm-test ""
addUser rpm-test "" rpm-test "rpm-test user-daemon" "/bin/false"
fi
if [ -e /etc/sysconfig/rpm-test ] ;
then
sed -i 's/PACKAGE_PREFIX\=.*//g' /etc/sysconfig/rpm-test
fi
if [ -n "$RPM_INSTALL_PREFIX" ] ;
then
echo "PACKAGE_PREFIX=${RPM_INSTALL_PREFIX}" >> /etc/sysconfig/rpm-test
fi
%post
# POST
## This POST entry will be 2 times in the SPEC file
# POST
## This POST entry will be 2 times in the SPEC file
relocateLink() {
if [ -n "$4" ] ;
then
RELOCATED_INSTALL_DIR="$4/$3"
echo "${1/$2/$RELOCATED_INSTALL_DIR}"
else
echo "$1"
fi
}
rm -rf $(relocateLink /usr/bin/rpm-test /usr/share/rpm-test rpm-test $RPM_INSTALL_PREFIX) && ln -s $(relocateLink /usr/share/rpm-test/bin/rpm-test /usr/share/rpm-test rpm-test $RPM_INSTALL_PREFIX) $(relocateLink /usr/bin/rpm-test /usr/share/rpm-test rpm-test $RPM_INSTALL_PREFIX)
rm -rf $(relocateLink /usr/share/rpm-test/logs /usr/share/rpm-test rpm-test $RPM_INSTALL_PREFIX) && ln -s $(relocateLink /var/log/rpm-test /usr/share/rpm-test rpm-test $RPM_INSTALL_PREFIX) $(relocateLink /usr/share/rpm-test/logs /usr/share/rpm-test rpm-test $RPM_INSTALL_PREFIX)
%preun
echo preun
echo preun
%postun
echo postun
# POSTUN
## This POSTUN entry will be 2 times in the SPEC file
echo postun
# POSTUN
## This POSTUN entry will be 2 times in the SPEC file
relocateLink() {
if [ -n "$4" ] ;
then
RELOCATED_INSTALL_DIR="$4/$3"
echo "${1/$2/$RELOCATED_INSTALL_DIR}"
else
echo "$1"
fi
}
[ -e /etc/sysconfig/rpm-test ] && . /etc/sysconfig/rpm-test
rm -rf $(relocateLink /usr/bin/rpm-test /usr/share/rpm-test rpm-test $PACKAGE_PREFIX)
rm -rf $(relocateLink /usr/share/rpm-test/logs /usr/share/rpm-test rpm-test $PACKAGE_PREFIX)
%files
%attr(0755,root,root) /usr/share/rpm-test/bin/rpm-test
%attr(0644,root,root) /usr/share/rpm-test/lib/rpm-test.rpm-test-0.1.0.jar
%attr(0644,root,root) /usr/share/rpm-test/lib/org.scala-lang.scala-library-2.11.8.jar
%dir %attr(755,rpm-test,rpm-test) /var/log/rpm-test
%config %attr(644,root,root) /etc/default/rpm-test
%dir %attr(755,rpm-test,rpm-test) /var/run/rpm-test
%attr(0755,root,root) /etc/init.d/rpm-test