-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmyrpm
executable file
·262 lines (216 loc) · 6.65 KB
/
xmyrpm
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
#!/bin/sh
#------------------------------------------------------------------------------
#
# MyRPM - Rpm Utilities
# Copyright (c) Jean-Marie RENOUARD 2014 - LightPath
# Contact : Jean-Marie Renouard <jmrenouard at gmail.com>
#
# This program is open source, licensed under the Artistic Licence v2.0.
#
# Artistic Licence 2.0
# Everyone is permitted to copy and distribute verbatim copies of
# this license document, but changing it is not allowed.
#
#------------------------------------------------------------------------------
NAME="XMyRpm"
VERSION="2.2"
#DIALOG="/usr/bin/Xdialog"
DIALOG="/usr/bin/dialog"
MYRPM="/usr/bin/myrpm"
BUILD_TMPL="/usr/local/myrpm/shells/build_tpl.sh"
INTEGRATION_ROOT="$HOME/integration/"
displayRadioBoxUid() {
CMD="$DIALOG --combobox 'Owner_Selection'"
USERS=`mktemp`
sort /etc/passwd > "$USERS"
exec < $USERS
while read user
do
Uid=$(echo $user | cut -d':' -f 3)
Name=$(echo $user | cut -d':' -f 1)
CMD="$CMD $Name($Uid)"
done
rm -f $USERS
exec $CMD
}
displayRadioBoxGid() {
CMD="$DIALOG --combobox 'Group_Selection'"
GRPS=`mktemp`
sort /etc/group > "$GRPS"
exec < $GRPS
while read group
do
Gid=$(echo $group | cut -d':' -f 3)
Name=$(echo $group | cut -d':' -f 1)
CMD="$CMD $Name($Gid)"
done
rm -f $GRPS
exec $CMD
}
displayRightsSelect() {
OUT_ZEN=`mktemp`
$DIALOG --no-tags --checklist 'Selection des Droits' 0 0 10 OwnerR 'Read rights for Owner' on OwnerX 'Execution rights for Owner' on OwnerW 'Write rights for Owner' on GroupR 'Read rights for Group' on GroupX 'Execution rights for Group' on GroupW 'Write rights for Group' off OtherR 'Read rights for Other users' off OtherX 'Execution rights for Other users' off OtherW 'Write rights for Other users' off 2>$OUT_ZEN
ur=0;
if grep OwnerR $OUT_ZEN > /dev/null; then
let "ur += 4"
fi
if grep OwnerW $OUT_ZEN > /dev/null; then
let "ur += 2"
fi
if grep OwnerX $OUT_ZEN > /dev/null; then
let "ur += 1"
fi
gr=0;
if grep GroupR $OUT_ZEN > /dev/null; then
let "gr += 4"
fi
if grep GroupW $OUT_ZEN > /dev/null; then
let "gr += 2"
fi
if grep GroupX $OUT_ZEN > /dev/null; then
let "gr += 1"
fi
or=0;
if grep OtherR $OUT_ZEN > /dev/null; then
let "or += 4"
fi
if grep OtherW $OUT_ZEN > /dev/null; then
let "or += 2"
fi
if grep OtherX $OUT_ZEN > /dev/null; then
let "or += 1"
fi
echo $ur$gr$or
}
getTopDir() {
echo $(grep topdir $HOME/.rpmmacros | awk '{print $2}')
}
getLastestProperty() {
TOPDIR=$(getTopDir)
SPEC_FILE=$(ls -1t $TOPDIR/SPECS | grep $2 | head -n 1)
echo $(grep $1: $TOPDIR/SPECS/$SPEC_FILE | awk '{print $2}')
}
getChangeLogs() {
TOPDIR=$(getTopDir)
SPEC_FILE=$(ls -1t $TOPDIR/SPECS | grep $1 | head -n 1)
echo $(grep -A 3 %changelog $TOPDIR/SPECS/$SPEC_FILE)
}
printInfo() {
$DIALOG --infobox \"$*\" 0 0 100
}
displayPackageInfo() {
$DIALOG --3inputsbox "Package information" 0 0 "Package Name" "$1" "Version Number" "$2" "Release Number" "$3"
}
displayPackagingInfo() {
$DIALOG --3inputsbox "Packaging information" 0 0 "Required Packages (comma separated)" "$1" "Exclude patterns (comma separated)" "$2" "ChangeLog for this release" "$3"
}
displayFileSelect() {
$DIALOG --title "$1" --fselect "$2" 0 0
}
displayDirSelect() {
$DIALOG --title "$1" --dselect "$2" 0 0
}
displayYesNoSelect() {
$DIALOG --yesno "$1" 0 0
}
APPLI="testAppli"
VERSION=1.0
RELEASE=1
RES=$(displayPackageInfo $APPLI $VERSION $RELEASE 2>&1)
if [ "$?" -ne "0" ]; then
printInfo "Packaging process Canceled :("
exit 1
fi
#Check non null values
APPLI=$(echo $RES| cut -d'/' -f1)
VERSION=$(echo $RES| cut -d'/' -f2)
RELEASE=$(echo $RES| cut -d'/' -f3)
REQUIRES=$(getLastestProperty Requires $APPLI| tr ' ' ',')
RES=$(displayPackagingInfo $REQUIRES 2>&1)
if [ "$?" -ne "0" ]; then
printInfo "Packaging process Canceled :("
exit 1
fi
#Check non null values
REQUIRES=$(echo $RES| cut -d'/' -f1)
ADDITIONAL_EXCLUDES=$(echo $RES| cut -d'/' -f2)
CHANGELOG=$(echo $RES| cut -d'/' -f3)
EXCLUDE="build.sh,post.sh,pre.sh,\.rpm$"
if [ "$ADDITIONAL_EXCLUDES" != "" ]; then
EXCLUDE="$EXCLUDE,$ADDITIONAL_EXCLUDES"
fi
#Check non null values, sh exetension, start with sh shibang
PRE_SCRIPT=$(displayFileSelect "Pre_installation_shell_script" $HOME 2>&1)
if [ "$?" -ne "0" ]; then
printInfo "Packaging process Canceled :("
exit 1
fi
#Check non null values, sh exetension, start with sh shibang
POST_SCRIPT=$(displayFileSelect "Post_installation_shell_script" $HOME 2>&1)
if [ "$?" -ne "0" ]; then
printInfo "Packaging process Canceled :("
exit 1
fi
PACK_TYPE="ARCHIVE"
displayYesNoSelect "Archive based packaging ?"
[ "$?" -ne "0" ] && PACK_TYPE="DIRECTORY"
ROOT_DIR="."
USER_ARCHIVE=""
USER_ARCHIVE=`id -u`
GROUP_ARCHIVE=`id -g`
RIGTHS_ARCHIVE="755"
#check sh extension
if [ "$PACK_TYPE" == "DIRECTORY" ]; then
#check tar, tar.gz or tgz extension
ROOT_DIR=$(displayDirSelect "Select the root directory" $HOME 2>&1)
else
#check tar, tar.gz or tgz extension
ARCHIVE_FILE=$(displayFileSelect "Select a tar or tar.gz file archive" $HOME 2>&1)
USER_ARCHIVE=$(displayRadioBoxUid 2>&1)
USER_ARCHIVE=$(echo $USER_ARCHIVE| cut -d'(' -f1)
GROUP_ARCHIVE=$(displayRadioBoxGid 2>&1)
GROUP_ARCHIVE=$(echo $GROUP_ARCHIVE| cut -d'(' -f1)
RIGTHS_ARCHIVE=$(displayRightsSelect)
fi
# Just build the command myrpm call from there !
echo "* Package : $APPLI-$VERSION-$RELEASE"
echo "* ChangeLog : $CHANGELOG"
echo "* Requires : $REQUIRES"
echo "* Excludes : $EXCLUDE"
echo "* Pre script : $PRE_SCRIPT"
echo "* Post script : $POST_SCRIPT"
echo "* Rpm Packaging type: $PACK_TYPE"
echo "* Archive File : $ARCHIVE_FILE"
echo "* Archive User : $USER_ARCHIVE"
echo "* Archive Group : $GROUP_ARCHIVE"
echo "* Archive Rights : $RIGTHS_ARCHIVE"
echo "* Root Dir : $ROOT_DIR"
TMP_DIR=`mktemp -d`
if [ "$PACK_TYPE" == "ARCHIVE" ]; then
tar xzvf $ARCHIVE_FILE -C $TMP_DIR
chmod -R $RIGTHS_ARCHIVE $TMP_DIR/*
sudo chown -R $USER_ARCHIVE:$GROUP_ARCHIVE $TMP_DIR/*
ROOT_DIR=$TMP_DIR
fi
displayYesNoSelect "Create a rpm factory ?"
if [ "$?" -eq "0" ]; then
sudo rm -Rf $INTEGRATION_ROOT/$APPLI
mkdir -p $INTEGRATION_ROOT/$APPLI
sudo cp -a $ROOT_DIR $INTEGRATION_ROOT/$APPLI
cp $PRE_SCRIPT $INTEGRATION_ROOT/$APPLI/pre.sh
cp $POST_SCRIPT $INTEGRATION_ROOT/$APPLI/post.sh
cp $BUILD_TMPL $INTEGRATION_ROOT/$APPLI/build_t.sh
sed -e "s/%APPLI%/$APPLI/g" \
-e "s/%VERSION%/$VERSION/g" \
-e "s/%RELEASE%/$RELEASE/g" \
-e "s/%REQUIRES%/$REQUIRES/g" \
-e "s/%CHANGELOG%/$CHANGELOG/g" \
-e "s/%EXCLUDE%/$EXCLUDE/g" \
$INTEGRATION_ROOT/$APPLI/build_t.sh > $INTEGRATION_ROOT/$APPLI/build.sh
rm -f $INTEGRATION_ROOT/$APPLI/build_t.sh
else
cd $ROOT_DIR
$MYRPM -N $APPLI -V $VERSION -R $RELEASE -n -d . -r . -b --requires="$REQUIRES" -C "$CHANGELOG" --post-script="$POST_SCRIPT" --pre-script="$PRE_SCRIPT" -x "$EXCLUDE"
cd -
fi
exit 0