Skip to content

Commit 9067f43

Browse files
committed
Updated options in the Fledge RPM package script
Signed-off-by: ashish-jabble <[email protected]>
1 parent 1006616 commit 9067f43

File tree

1 file changed

+74
-51
lines changed

1 file changed

+74
-51
lines changed

make_rpm

Lines changed: 74 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,57 +32,80 @@ skip_build=0 # 1=skip Git repo extraction and Fledge build
3232
os_name=$(grep -o '^NAME=.*' /etc/os-release | cut -f2 -d\" | sed 's/"//g')
3333
os_version=$(grep -o '^VERSION_ID=.*' /etc/os-release | cut -f2 -d\" | sed 's/"//g')
3434

35-
usage="$(basename "$0") [-h] [-c] [-a] [-s] [-b <branch>]
36-
This script is used to create the RPM package of Fledge
37-
38-
Arguments:
39-
-h - Display this help text
40-
-c - Remove all the old versions saved in format .XXXX
41-
-a - Remove all the versions, including the last one
42-
-s - Skip Fledge building using the binaries already available
43-
-b - Branch to base package on"
44-
45-
while getopts ":hcasb:" opt; do
46-
case "$opt" in
47-
h)
48-
echo "${usage}"
49-
exit 0
50-
;;
51-
c)
52-
if [ -d "${GIT_ROOT}/packages/RPM/build" ]; then
53-
echo -n "Cleaning the build folder from older versions..."
54-
find "${PKG_ROOT}/packages/RPM/build/BUILDROOT" -maxdepth 1 | grep '.*\.[0-9][0-9][0-9][0-9]' | sudo xargs rm -rf
55-
find "${PKG_ROOT}/packages/RPM/build/RPMS/${architecture}" -maxdepth 1 | grep '.*\.[0-9][0-9][0-9][0-9]' | sudo xargs rm -rf
56-
echo "Done."
57-
else
58-
echo "No build folder, skipping clean old versions"
59-
fi
60-
exit 0
61-
;;
62-
a)
63-
if [ -d "${PKG_ROOT}/packages/RPM/build" ]; then
64-
echo -n "Cleaning the build folder..."
65-
sudo rm -rf ${PKG_ROOT}/packages/RPM/build/*
66-
echo "Done."
67-
else
68-
echo "No build folder, skipping cleanall"
69-
fi
70-
exit 0
71-
;;
72-
s)
73-
skip_build=1
74-
;;
75-
b)
76-
branch=$OPTARG
77-
;;
78-
\?)
79-
echo "Invalid option -$OPTARG"
80-
exit 1
81-
;;
82-
:)
83-
echo "-$OPTARG requires an argument"
84-
exit 1
35+
usage="$(basename "$0") [-h] [-c] [-a] [-s] [-b branch]
36+
This script is used to create the RPM package of Fledge.
37+
Options:
38+
-h - Display this help text
39+
-c - Clean old versions, removing packages saved in the format .XXXX (but keep the latest version)
40+
-a - Clean all versions, including the latest one (removes everything in the build directory)
41+
-s - Skip the build process (useful if the build is already done or needs to be skipped for testing)
42+
-b - Specify the branch name to use for the build (required argument following -b)"
43+
44+
# Function to check if an option is valid
45+
is_valid_option() {
46+
case "$1" in
47+
-h | -c | -a | -s | -b) return 0 ;; # Valid options
48+
*) return 1 ;; # Invalid option
8549
esac
50+
}
51+
52+
# Parse the options
53+
while [[ $# -gt 0 ]]; do
54+
# Check if the current option is valid using the is_valid_option function
55+
if ! is_valid_option "$1"; then
56+
echo "Unrecognized option: $1"
57+
echo "$usage"
58+
exit 1
59+
fi
60+
61+
case "$1" in
62+
-c) # Option for 'clean'
63+
if [ -d "${GIT_ROOT}/packages/RPM/build" ]; then
64+
echo -n "Cleaning the build folder from older versions..."
65+
find "${PKG_ROOT}/packages/RPM/build/BUILDROOT" -maxdepth 1 | grep '.*\.[0-9][0-9][0-9][0-9]' | sudo xargs rm -rf
66+
find "${PKG_ROOT}/packages/RPM/build/RPMS/${architecture}" -maxdepth 1 | grep '.*\.[0-9][0-9][0-9][0-9]' | sudo xargs rm -rf
67+
echo "Done."
68+
else
69+
echo "No build folder, skipping clean old versions"
70+
fi
71+
exit 0
72+
;;
73+
-a) # Option for 'cleanall'
74+
echo "Cleaning all..."
75+
if [ -d "${PKG_ROOT}/packages/RPM/build" ]; then
76+
echo -n "Cleaning the build folder..."
77+
sudo rm -rf ${PKG_ROOT}/packages/RPM/build/*
78+
echo "Done."
79+
else
80+
echo "No build folder, skipping cleanall"
81+
fi
82+
exit 0
83+
;;
84+
-s) # Option for 'skip_build'
85+
skip_build=1
86+
shift
87+
;;
88+
-b) # Option for 'branch'
89+
if [[ -z "$2" || "$2" =~ ^- ]]; then
90+
echo "Option -b requires a branch argument."
91+
echo "$usage"
92+
exit 1
93+
fi
94+
branch=$2
95+
shift 2
96+
;;
97+
-h) # Option for 'help'
98+
echo "$usage"
99+
exit 0
100+
;;
101+
--) # End of options
102+
shift
103+
break
104+
;;
105+
*) # Positional arguments (not options)
106+
break
107+
;;
108+
esac
86109
done
87110

88111
if [ ! -f packages/RPM/SPECS/fledge.spec ] ; then
@@ -211,7 +234,7 @@ if [ -d "${package_name}" ]; then
211234
fi
212235
mkdir "${package_name}"
213236

214-
# Populate the package directory with Debian files
237+
# Populate the package directory with RPM files
215238
# First with files common to all pla
216239
echo -n "Populating the package and updating version in control file..."
217240
cd "${package_name}"

0 commit comments

Comments
 (0)