-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshell.sh
More file actions
executable file
·122 lines (101 loc) · 2.3 KB
/
Copy pathshell.sh
File metadata and controls
executable file
·122 lines (101 loc) · 2.3 KB
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
#!/bin/sh
show_usage() {
cat <<TEMPLATE_USAGE
Usage: $v_PROGRAM_NAME [OPTION]...
...Description [REPLACE-ME]...
Example: $v_PROGRAM_NAME -h [REPLACE-ME]
Options:
-h, --help Show this message and exit
-v, --verbose Enable verbose output
-----------------------------------------------------"
TEMPLATE_USAGE
}
###
# Set default color codes for colorful prints
###
v_RED_COLOR="\033[0;31m"
v_GREEN_COLOR="\033[0;32m"
v_YELLOW_COLOR="\033[1;33m"
v_BLUE_COLOR="\033[0;34m"
v_NEUTRAL_COLOR="\033[0m"
error() {
printf "${v_RED_COLOR}%s${v_NEUTRAL_COLOR}\n" "$@"
}
warning() {
printf "${v_YELLOW_COLOR}%s${v_NEUTRAL_COLOR}\n" "$@"
}
info() {
printf "${v_BLUE_COLOR}%s${v_NEUTRAL_COLOR}\n" "$@"
}
success() {
printf "${v_GREEN_COLOR}%s${v_NEUTRAL_COLOR}\n" "$@"
}
###
# Function Docs [REPLACE-ME]
###
do_something() {
: # [REPLACE-ME]
}
###
# Set global variables.
###
set_globals() {
:
}
###
# Parse arguments/options by traversing all input arguments.
###
parse_arguments() {
while [ "$#" -gt 0 ]; do
case $1 in
-h | --help)
show_usage
exit 0
;;
-v | --verbose)
v_VERBOSE=true
shift
;;
*)
# Unrecognizable options, skip (or treat as positional argument)
shift
;;
esac
done
}
###
# Set default values to be used throughout the script (global variables).
###
set_defaults() {
v_VERBOSE=false
}
main() {
case "$(uname -s)" in
Linux*) v_READLINK_PROGRAM="readlink" ;;
Darwin*) v_READLINK_PROGRAM="greadlink" ;;
esac
v_PROGRAM_PATH="$($v_READLINK_PROGRAM -f "$0")"
v_PROGRAM_NAME="$(basename "$v_PROGRAM_PATH")"
v_PROGRAM_DIR="$(dirname "$v_PROGRAM_PATH")"
if ! set_defaults; then
error "Failed setting defaults, aborting"
return 1
fi
if ! parse_arguments "$@"; then
error "Failed parsing arguments, aborting"
return 2
fi
if ! set_globals; then
error "Failed setting globals, aborting"
return 3
fi
if ! do_something "$@"; then
error "Failed [REPLACE-ME]"
return 4
fi
success "Successfully [REPLACE-ME]"
return 0
}
# Call main and don't do anything else
# It will pass the correct exit code to the OS
main "$@"