-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_rpm_package.sh
executable file
·142 lines (114 loc) · 2.79 KB
/
create_rpm_package.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
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
#!/bin/bash
#
# Nvkeep RPM Package Creator
DIST_DIR="dist"
PACKAGING_DIR="packaging"
VER_FILE=".version"
# Print usage info and exit
usage()
{
echo "Nvkeep RPM Package Creator v${VERSION}"
echo
echo "Usage:"
echo " $ $0"
echo
exit 1
}
# Parse command line arguments and set defaults
parse_args()
{
local OPTIND # local to prevent effects from other subscripts
while getopts ":h" opt; do
case "${opt}" in
h)
# User requested help
usage
;;
*)
# Other option arguments are invalid
usage
;;
esac
done
shift $((OPTIND-1))
}
# Remove any leftovers from previous rpm build
cleanup_buildroot()
{
rm -rf ./${PACKAGING_DIR}/BUILDROOT/* ./${PACKAGING_DIR}/SPECS/rpm.spec \
./${PACKAGING_DIR}/RPMS/*
}
# Copy files to rpm buildroot
copy_to_buildroot()
{
# copy files from "dist" directory to corresponding rpm paths
for src_path in $(find dist -type f); do
# remove leading DIST_DIR from paths
dest_base_path="${PACKAGING_DIR}/BUILDROOT"
dest_relative_path=$(echo $src_path | sed -e "s@^${DIST_DIR}/@@g");
dest_path="${dest_base_path}/${dest_relative_path}"
mkdir -pv $(dirname "$dest_path")
if [ $? -ne 0 ]; then
echo "ERROR: Directory creation failed. Aborting."
exit 1
fi
if [ $(basename "$dest_path") = ".gitignore" ]; then
continue; # skip .gitignore files
fi
cp -v --no-dereference --preserve=links,timestamps "$src_path" "$dest_path"
if [ $? -ne 0 ]; then
echo "ERROR: File copy failed. Aborting."
exit 1
fi
done
}
prepare_spec_file()
{
cp ${PACKAGING_DIR}/SPECS/rpm.spec.TEMPLATE ${PACKAGING_DIR}/SPECS/rpm.spec
sed -i "s/__VERSION__/${VER_MAJOR}.${VER_MINOR}.${VER_PATCHLEVEL}/" \
${PACKAGING_DIR}/SPECS/rpm.spec
}
build_rpm()
{
rpmbuild ${PACKAGING_DIR}/SPECS/rpm.spec --bb --define "_topdir $(pwd)/${PACKAGING_DIR}" \
--define "__spec_install_pre /bin/true" --buildroot=$(pwd)/${PACKAGING_DIR}/BUILDROOT
if [ $? -ne 0 ]; then
echo "ERROR: Building rpm package failed."
exit 1
fi
}
show_rpm_package()
{
find packaging/RPMS -name "*.rpm"
}
# load version file
. $VER_FILE
if [ $? -ne 0 ]; then
echo "ERROR: Unable to load version file ("$VER_FILE"). Aborting."
exit 1
fi
# parse command line args
parse_args "$@"
echo "Nvkeep RPM Package Creator v${VERSION}"
echo
# change to installer dir
cd $(dirname $0)
if [ ! -e "dist" ]; then
echo "ERROR: 'dist' directory not found."
exit 1
fi
echo "* Cleaning up any previous rpm build files..."
cleanup_buildroot
echo "* Preparing files for new rpm package..."
copy_to_buildroot
echo "* Preparing rpm spec file..."
prepare_spec_file
echo "* Building rpm package..."
build_rpm
echo
echo "All done. Your rpm package is here:"
show_rpm_package
echo
echo "NEXT STEP:"
echo "After installing the rpm package, run nvkeep_apply_config as root on the first"
echo "host of this failover group."