|
22 | 22 |
|
23 | 23 | set -e
|
24 | 24 |
|
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) |
34 | 36 | ARCH_NAME=$(dpkg --print-architecture)
|
35 | 37 | repo_name=fledge
|
36 | 38 | skip_build=0
|
37 | 39 |
|
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' |
41 | 59 | 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." |
45 | 63 | else
|
46 |
| - echo "No build folder, skipping clean" |
| 64 | + echo "No build folder, skipping clean" |
47 | 65 | fi
|
48 | 66 | exit 0
|
49 | 67 | ;;
|
50 |
| - cleanall) |
| 68 | + -a) # Option for 'cleanall' |
| 69 | + echo "Cleaning all..." |
51 | 70 | 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." |
55 | 74 | else
|
56 |
| - echo "No build folder, skipping cleanall" |
| 75 | + echo "No build folder, skipping cleanall" |
57 | 76 | fi
|
58 | 77 | exit 0
|
59 | 78 | ;;
|
60 |
| - s) |
| 79 | + -s) # Option for 'skip_build' |
61 | 80 | 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 |
62 | 91 | ;;
|
63 |
| - b) |
64 |
| - branch=$OPTARG |
| 92 | + -h) # Option for 'help' |
| 93 | + echo "$usage" |
| 94 | + exit 0 |
65 | 95 | ;;
|
66 |
| - help) |
67 |
| - echo "${usage}" |
68 |
| - exit 1 |
| 96 | + --) # End of options |
| 97 | + shift |
| 98 | + break |
69 | 99 | ;;
|
70 |
| - *) |
71 |
| - echo "Unrecognized option: $i" |
72 |
| - exit 1 |
73 |
| - ;; |
74 |
| - esac |
| 100 | + *) # Positional arguments (not options) |
| 101 | + break |
| 102 | + ;; |
| 103 | + esac |
75 | 104 | done
|
76 | 105 |
|
77 | 106 | #
|
|
0 commit comments