Skip to content

Commit 1006616

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

File tree

1 file changed

+61
-32
lines changed

1 file changed

+61
-32
lines changed

make_deb

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,56 +22,85 @@
2222

2323
set -e
2424

25-
usage="$(basename "$0") [help|clean|cleanall]
26-
This script is used to create the Debian package of Fledge
27-
Arguments:
28-
help - Display this help text
29-
clean - Remove all the old versions saved in format .XXXX
30-
cleanall - Remove all the versions, including the last one"
31-
32-
PKG_ROOT=`pwd`
33-
architecture=`arch`
25+
usage="$(basename "$0") [-h] [-c] [-a] [-s] [-b branch]
26+
This script is used to create the Debian package of Fledge.
27+
Options:
28+
-h - Display this help text
29+
-c - Clean old versions, removing packages saved in the format .XXXX (but keep the latest version)
30+
-a - Clean all versions, including the latest one (removes everything in the build directory)
31+
-s - Skip the build process (useful if the build is already done or needs to be skipped for testing)
32+
-b - Specify the branch name to use for the build (required argument following -b)"
33+
34+
PKG_ROOT=$(pwd)
35+
architecture=$(arch)
3436
ARCH_NAME=$(dpkg --print-architecture)
3537
repo_name=fledge
3638
skip_build=0
3739

38-
while getopts ":hcasb:" opt; do
39-
case "$opt" in
40-
clean)
40+
# Function to check if an option is valid
41+
is_valid_option() {
42+
case "$1" in
43+
-h | -c | -a | -s | -b) return 0 ;; # Valid options
44+
*) return 1 ;; # Invalid option
45+
esac
46+
}
47+
48+
# Parse the options
49+
while [[ $# -gt 0 ]]; do
50+
# Check if the current option is valid using the is_valid_option function
51+
if ! is_valid_option "$1"; then
52+
echo "Unrecognized option: $1"
53+
echo "$usage"
54+
exit 1
55+
fi
56+
57+
case "$1" in
58+
-c) # Option for 'clean'
4159
if [ -d "${PKG_ROOT}/packages/Debian/build" ]; then
42-
echo -n "Cleaning the build folder from older versions..."
43-
find "${PKG_ROOT}/packages/Debian/build/${architecture}" -maxdepth 2 | grep '.*\.[0-9][0-9][0-9][0-9]' | xargs rm -rf
44-
echo "Done."
60+
echo -n "Cleaning the build folder from older versions..."
61+
find "${PKG_ROOT}/packages/Debian/build/${architecture}" -maxdepth 2 | grep '.*\.[0-9][0-9][0-9][0-9]' | xargs rm -rf
62+
echo "Done."
4563
else
46-
echo "No build folder, skipping clean"
64+
echo "No build folder, skipping clean"
4765
fi
4866
exit 0
4967
;;
50-
cleanall)
68+
-a) # Option for 'cleanall'
69+
echo "Cleaning all..."
5170
if [ -d "${PKG_ROOT}/packages/Debian/build" ]; then
52-
echo -n "Cleaning the build folder..."
53-
rm -rf ${PKG_ROOT}/packages/Debian/build
54-
echo "Done."
71+
echo -n "Cleaning the build folder..."
72+
rm -rf ${PKG_ROOT}/packages/Debian/build
73+
echo "Done."
5574
else
56-
echo "No build folder, skipping cleanall"
75+
echo "No build folder, skipping cleanall"
5776
fi
5877
exit 0
5978
;;
60-
s)
79+
-s) # Option for 'skip_build'
6180
skip_build=1
81+
shift
82+
;;
83+
-b) # Option for 'branch'
84+
if [[ -z "$2" || "$2" =~ ^- ]]; then
85+
echo "Option -b requires a branch argument."
86+
echo "$usage"
87+
exit 1
88+
fi
89+
branch=$2
90+
shift 2
6291
;;
63-
b)
64-
branch=$OPTARG
92+
-h) # Option for 'help'
93+
echo "$usage"
94+
exit 0
6595
;;
66-
help)
67-
echo "${usage}"
68-
exit 1
96+
--) # End of options
97+
shift
98+
break
6999
;;
70-
*)
71-
echo "Unrecognized option: $i"
72-
exit 1
73-
;;
74-
esac
100+
*) # Positional arguments (not options)
101+
break
102+
;;
103+
esac
75104
done
76105

77106
#

0 commit comments

Comments
 (0)