-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·104 lines (90 loc) · 2.73 KB
/
build.sh
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
#!/bin/bash
PATH="/bin:/sbin:/usr/bin:/usr/sbin"
do_usage(){
cat <<EOF
скрипт для сборки
умеет:
1. пересобирать rpm-ки по build-репе
2. пересобирать по Source RPM
rpmbuild/ пересоздаётся на каждый вызов $0
логи скрипта искать в ~/log/
EOF
exit 1
}
# vars
SPEC_FILE=$(find /github/workspace/SPECS/ -type f -name "*.spec" | head -1)
BUILD_FROM_SPEC=true
CENTOS_RELEASE=7
TMP_DIR="$HOME/tmp"
RPMBUILD_DIR="$HOME/rpmbuild"
SOURCEDIR="$RPMBUILD_DIR/SOURCES"
# check {{
if ! [[ -s $SPEC_FILE ]]; then
do_usage
fi
if echo $CENTOS_RELEASE | grep -vqP "^[0-9]+"; then
echo "ERROR: bad format CENTOS_RELEASE=$CENTOS_RELEASE" 1>&2
exit 1
fi
# }}
# init {{
if [[ -d $RPMBUILD_DIR ]]; then
rm -rf $RPMBUILD_DIR
fi
install -d $TMP_DIR $RPMBUILD_DIR
install -d $RPMBUILD_DIR/{SOURCES,SPECS,SRPMS}
# }}
# sync rpmbuild dir {{
PATH_TO_REPO=$( dirname $SPEC_FILE | sed 's|/[A-Z]\+$||' )
if [[ -z $PATH_TO_REPO ]]; then
echo "function usage: $FUNCNAME path/to/build-repo"
exit 1
fi
# sync spec and sources
mkdir -p $PATH_TO_REPO/SOURCES/ # не обязательная директория
rsync -a --copy-links $PATH_TO_REPO/SPECS/ $RPMBUILD_DIR/SPECS/
rsync -a --copy-links $PATH_TO_REPO/SOURCES/ $RPMBUILD_DIR/SOURCES/
# }}
# new spec file
SPEC_FILE=$( find $RPMBUILD_DIR/SPECS/ -type f -name "*.spec" | head -1 )
# get sources
if spectool -g -R $SPEC_FILE; then
# fix_archive_names {{
IFS=$'\n'
for LINE in $( grep -P "^Source[0-9]+:\s+http(s)?:.*#/" $SPEC_FILE | awk '{print $2}' ); do
URL=$( echo $LINE | awk -F "#/" '{print $1}' )
NAME=$( echo $LINE | awk -F "#/" '{print $2}' )
VERSION_VAR=$( echo $NAME | sed 's|.*%{||; s|}.*||' )
VERSION=$( grep -P "^%define\s+$VERSION_VAR\s+" $SPEC_FILE | awk '{print $NF}' )
ARCH_NAME=$( echo $NAME | sed "s|%{$VERSION_VAR}|$VERSION|g" )
if [[ -s $SOURCEDIR/v$VERSION ]]; then
mv $SOURCEDIR/v$VERSION $SOURCEDIR/$ARCH_NAME
fi
done
# }}
else
echo "ERROR: failed get sources" 1>&2
exit 1
fi
# build rpm {{
yum-builddep -y $SPEC_FILE
rpmbuild -ba $SPEC_FILE
EXIT_CODE=$?
if [[ $EXIT_CODE != 0 ]]; then
echo "ERROR: failed run 'rpmbuild -ba $SPEC_FILE'" 1>&2
exit 1
fi
# }}
# move rpms and create checksum
mv $RPMBUILD_DIR/SRPMS/* $HOME/
mv $RPMBUILD_DIR/RPMS/*/* $HOME/
cd $HOME
md5sum *.rpm > md5sum
sha256sum *.rpm > sha256sum
# generate artifacts {{
ARTIFACTS=""
for package in *rpm; do ARTIFACTS=${ARTIFACTS}\"$package\",\ ; done
echo ::set-output name=matrix::{\"file\": [${ARTIFACTS} \"sha256sum\", \"md5sum\"]}
# }}
## upload to packagecloud.io
#package_cloud push gefimov/test/el/7 $HOME/*.rpm || true