forked from DMTF/python-redfish-utility
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathrdmc.spec10.in
More file actions
314 lines (273 loc) · 12.3 KB
/
rdmc.spec10.in
File metadata and controls
314 lines (273 loc) · 12.3 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#
# spec file for package ilorest (Version %VERSION%)
#
# norootforbuild
Name: ilorest
License: Copyright 2016-2024 Hewlett Packard Enterprise Development LP
Group: System/Configuration/Packaging
AutoReqProv: on
Version: %VERSION%
Release: %RELEASE%
Source0: ilorest-%{version}.tar.bz2
Url: https://www.hpe.com/info/restfulapi
Vendor: Hewlett Packard Enterprise
Packager: Hewlett Packard Enterprise
Summary: RESTful Interface Tool
BuildRoot: %{_tmppath}/%{name}-%{version}-build
#BuildRequires: which
%description
Command line interface for managing HPE ProLiant Servers
%global debug_package %{nil}
##%global __requires_exclude_from ^%{_libdir}/ilorest/libcrypt.so.1$
##%global __provides_exclude_from ^%{_libdir}/ilorest/libcrypt.so.1$
Authors:
--------
Hewlett Packard Enterprise
%prep
%setup -n ilorest-%{version}
%build
mv rdmc-pyinstaller-lin.spc rdmc-pyinstaller-lin.spec
/usr/local/python3.10/bin/pyinstaller rdmc-pyinstaller-lin.spec
cp dist/ilorest ilorest
# Discover and resolve the real path of libcrypt.so.1
#LIBCRYPT_SYMLINK=$(ldconfig -p | awk '/libcrypt\.so\.1/{print $NF; exit}')
#if [ -z "$LIBCRYPT_SYMLINK" ]; then
# echo "Error: libcrypt.so.1 not found on build system." >&2
# exit 1
#fi
#LIBCRYPT_REAL=$(realpath "/lib64/libcrypt.so.1")
#cp $LIBCRYPT_REAL libcrypt.so.1
#echo "Resolved libcrypt.so.1 to $LIBCRYPT_REAL"
%install
# Install the main executable
install -D -m 0755 dist/ilorest $RPM_BUILD_ROOT%{_sbindir}/ilorest
# Install configuration files
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/ilorest
install -D -m 0644 rdmc-linux.conf $RPM_BUILD_ROOT%{_sysconfdir}/ilorest/redfish.conf
rm -rf %{_bindir}/genapptoken
rm -rf %{_bindir}/delapptoken
rm -rf %{_bindir}/detectonly
# Build and install helper binaries
gcc -o genapptoken genapptoken.c -ldl
gcc -o delapptoken delapptoken.c -ldl
gcc -o detectonly detectonly.c -ldl
install -D -m 0755 ./genapptoken $RPM_BUILD_ROOT%{_bindir}/genapptoken
install -D -m 0755 ./delapptoken $RPM_BUILD_ROOT%{_bindir}/delapptoken
install -D -m 0755 ./detectonly $RPM_BUILD_ROOT%{_bindir}/detectonly
# Install shared libraries
mkdir -p $RPM_BUILD_ROOT%{_libdir}/
install -D -m 0644 ./externals/*.so $RPM_BUILD_ROOT%{_libdir}/
# Packaged but not installed libcrypt
mkdir -p $RPM_BUILD_ROOT%{_libdir}/.nostrip/ilorest
cp libcrypt.so.1 $RPM_BUILD_ROOT%{_libdir}/.nostrip/ilorest/
%post
sync
LOGFILE="/var/log/ilorest_rpm_script.log"
# RHEL 10: Create symlink libcrypt.so.1 -> libcrypt.so.2
if [ -f /etc/redhat-release ] && grep -q "Red Hat Enterprise Linux release 10" /etc/redhat-release; then
LIBCRYPT2_PATH=$(find /lib64 /usr/lib64 -name libcrypt.so.2 2>/dev/null | head -n 1)
if [ -n "$LIBCRYPT2_PATH" ]; then
LIB_DIR=$(dirname "$LIBCRYPT2_PATH")
if [ ! -e "$LIB_DIR/libcrypt.so.1" ]; then
ln -s libcrypt.so.2 "$LIB_DIR/libcrypt.so.1"
logger -t RPM_SCRIPT "Created symlink: $LIB_DIR/libcrypt.so.1 -> libcrypt.so.2"
echo "Created symlink: $LIB_DIR/libcrypt.so.1 -> libcrypt.so.2" >> "$LOGFILE"
fi
fi
fi
# Function to ask for confirmation
ask_confirmation() {
local prompt="Proceed with application account creation? (yes/no): "
local attempts=0
local max_attempts=3 # Limit the number of attempts
echo -e "\nUnable to find an application account. For communication using virtual NIC,"
echo "an application account in iLO is required. Creation of the account requires"
echo "iLO credentials with 'Administer User Accounts' privilege."
echo -e "\nNote: The application account will be automatically removed during uninstallation."
echo -e "\nFor more information, refer to the documentation.\n"
while (( attempts < max_attempts )); do
read -p "$prompt" CONFIRMATION < /dev/tty
CONFIRMATION=$(echo "$CONFIRMATION" | tr '[:upper:]' '[:lower:]') # Normalize input
echo "DEBUG: CONFIRMATION='$CONFIRMATION'" >> "$LOGFILE"
case "$CONFIRMATION" in
yes|y)
echo "Proceeding with application account creation..." >> "$LOGFILE"
read -p "Enter iLO username: " USERNAME < /dev/tty
if [ -z "$USERNAME" ]; then
echo "Username not provided. Skipping application account creation." | tee -a "$LOGFILE"
return 1
fi
read -s -p "Enter iLO password (input will be hidden): " PASSWORD < /dev/tty
echo
if [ -z "$PASSWORD" ]; then
echo "Password not provided. Skipping application account creation." | tee -a "$LOGFILE"
return 1
fi
export USERNAME PASSWORD
echo "Creating application account for username: $USERNAME" >> "$LOGFILE"
return 0
;;
no|n)
echo "Installing application without creating an application account." >> "$LOGFILE"
echo -e "\nThe application account can be created later using:"
echo "'ilorest appaccount create -u <ilo_username> -p <ilo_password>'"
echo -e "\nIf an application account is not created, iLO credentials must be provided during ilorest login."
return 1
;;
*)
echo "Invalid input. Please answer 'yes' or 'no'." | tee -a "$LOGFILE"
((attempts++))
;;
esac
done
echo -e "Maximum attempts reached. Skipping application account creation.\n" | tee -a "$LOGFILE"
return 1
}
main() {
if [ -n "$PS1" ] || [ -t 1 ]; then
echo "Detecting system..." >> "$LOGFILE"
logger -t RPM_SCRIPT "Detecting system..."
%{_bindir}/detectonly
ret_val=$?
if [ $ret_val -eq 0 ]; then
ret_val_confirm=0
echo "Detecting iLO version succeeded." >> "$LOGFILE"
if [[ -z "${ILO_USERNAME+x}" || -z "${ILO_PASSWORD+x}" || -z "$ILO_USERNAME" || -z "$ILO_PASSWORD" ]]; then
echo "Environment variable ILO_USERNAME or ILO_PASSWORD is unset or empty." >> "$LOGFILE"
logger -t RPM_SCRIPT "Environment variable ILO_USERNAME or ILO_PASSWORD is unset."
if [ "$QUIET_MODE" = "no" ]; then
ask_confirmation
ret_val_confirm=$?
else
ret_val_confirm=2
echo "Silent installtion of RPM. No application account created." >> "$LOGFILE"
fi
else
ret_val_confirm=0
echo "Environment variable ILO_USERNAME and ILO_PASSWORD are set and non-empty." | tee -a "$LOGFILE"
logger -t RPM_SCRIPT "Environment variable ILO_USERNAME is set and non-empty."
{
echo
echo "Unable to find an application account. For communication using virtual NIC, an application account in iLO is required."
echo
echo "Using iLO credentials found in environment variables to create an application account."
echo
echo "Note: The application account will be automatically removed during uninstallation."
echo
echo "For more information application account, please refer to the documentation."
echo
} | tee -a "$LOGFILE"
USERNAME="$ILO_USERNAME"
PASSWORD="$ILO_PASSWORD"
fi
if [ $ret_val_confirm -eq 0 ]; then
echo "Creating application account for username: $USERNAME" >> "$LOGFILE"
%{_bindir}/genapptoken "$USERNAME" "$PASSWORD"
ret_val_create=$?
if [ $ret_val_create -eq 0 ]; then
echo "Successfully installed and created application account." >> "$LOGFILE"
logger -t RPM_SCRIPT "Successfully created application account"
else
echo
echo "Failed to create the application account. The application will still work but requires iLO credentials."
echo "To create application account after installation, use the command: 'ilorest appaccount create -u <username> -p <password>'"
echo
logger -t RPM_SCRIPT "Application account creation failed, fallback to iLO credentials"
fi
fi
else
echo "Detecting iLO version failed." >> "$LOGFILE"
logger -t RPM_SCRIPT "Detecting iLO version failed"
fi
fi
}
# Detect --quiet mode
QUIET_MODE=$(ps -o args= $PPID | grep -q -- "--quiet" && echo "yes" || echo "no")
UPGRADE_MODE=$(ps -o args= $PPID | grep -q -- "-U" && echo "yes" || echo "no")
if [ "$UPGRADE_MODE" = "yes" ] && [ "$QUIET_MODE" = "yes" ]; then
echo "Detected upgrade (-U) with --quiet mode." >> "$LOGFILE"
logger -t RPM_SCRIPT "Upgrade (-U) with --quiet mode detected"
elif [ "$UPGRADE_MODE" = "yes" ]; then
echo "Detected upgrade (-U) without --quiet mode." >> "$LOGFILE"
logger -t RPM_SCRIPT "Upgrade (-U) without --quiet mode detected"
elif [ "$QUIET_MODE" = "yes" ]; then
echo "RPM was called with --quiet mode." >> "$LOGFILE"
logger -t RPM_SCRIPT "RPM called with --quiet mode"
main
else
echo "Regular installation/removal without --quiet mode." >> "$LOGFILE"
logger -t RPM_SCRIPT "Regular install/removal"
main
fi
%preun
# Remove application token during uninstallation
LOGFILE="/var/log/ilorest_rpm_script.log"
%{_bindir}/detectonly
ret_val=$?
if [ $ret_val -eq 0 ]; then
if [ "$1" -gt 1 ] || rpm -q mypackage > /dev/null 2>&1; then
echo "Detected upgrade (-U) without --quiet mode." >> "$LOGFILE"
echo "Application uninstalled successfully."
else
echo "Removing application account and uninstalling the application..."
%{_bindir}/delapptoken
ret_val_delete=$?
if [ $ret_val_delete -eq 0 ]; then
echo "Successfully deleted application account" >> "$LOGFILE"
logger -t RPM_SCRIPT "Successfully deleted application account"
echo "Application account deleted successfully."
echo "Application uninstalled successfully."
elif [ $ret_val_delete -eq 2 ]; then
echo "Application account does not exist" >> "$LOGFILE"
logger -t RPM_SCRIPT "Application account does not exist"
echo "Application account does not exist."
echo "Application uninstalled successfully."
else
echo "Failed to delete application account" >> "$LOGFILE"
logger -t RPM_SCRIPT "Failed to delete application account"
echo "Removing application account and uninstalling the application.."
echo "Failed to remove application account."
echo "Application uninstalled successfully."
fi
fi
else
echo "Application uninstalled successfully."
fi
# RHEL 10 compatibility: Remove symlink for libcrypt.so.1 if it exists
if [ -f /etc/redhat-release ] && grep -q "Red Hat Enterprise Linux release 10" /etc/redhat-release; then
LIBCRYPT2_PATH=$(find /lib64 /usr/lib64 -name libcrypt.so.2 2>/dev/null | head -n 1)
if [ -n "$LIBCRYPT2_PATH" ]; then
LIB_DIR=$(dirname "$LIBCRYPT2_PATH")
if [ -L "$LIB_DIR/libcrypt.so.1" ]; then
rm -f "$LIB_DIR/libcrypt.so.1"
echo "Removed symlink: $LIB_DIR/libcrypt.so.1" >> "$LOGFILE"
logger -t RPM_SCRIPT "Removed symlink: $LIB_DIR/libcrypt.so.1"
fi
fi
fi
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%{_sbindir}/ilorest
%{_bindir}/genapptoken
%{_bindir}/delapptoken
%{_bindir}/detectonly
%attr(755, root, root) %{_libdir}/ilorest_chif.so
%config(noreplace) %{_sysconfdir}/ilorest/*
%dir %{_sysconfdir}/ilorest
# Include in RPM payload, but don’t install (packaged from .nostrip)
%dir %{_libdir}/.nostrip
%{_libdir}/.nostrip/ilorest/libcrypt.so.1
%changelog
* Fri Dec 12 2024 rajeevalochana.kallur@hpe.com
* Fri Mar 26 2021 rajeevalochana.kallur@hpe.com
- Modified
* Thu Jan 19 2017 prithvi.subrahmanya.v@hpe.com
- Added post section.
* Mon Dec 07 2015 jack.g.garcia@hpe.com
- Changes for the new code.
* Fri Jun 19 2014 jorge.cisneros@hp.com
- Changes for the new code.
* Thu Jun 01 2014 james.ayvaz@hp.com
- initial version %VERSION%