Skip to content

Commit 646ec30

Browse files
authored
Implement error checking for curl; add checks for required param args
1 parent dc5eaf3 commit 646ec30

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

tools/wled-tools

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,22 @@ backup_one() {
104104
local curl_command_cfg="curl -s "$cfg_url" -o "$cfg_dest.tmp""
105105
local curl_command_presets="curl -s "$presets_url" -o "$presets_dest.tmp""
106106

107-
curl_handler "$curl_command_cfg" "$hostname"
108-
curl_handler "$curl_command_presets" "$hostname"
107+
if ! curl_handler "$curl_command_cfg" "$hostname"; then
108+
log "ERROR" "$RED" "Failed to backup configuration for $hostname"
109+
rm -f "$cfg_dest.tmp"
110+
return 1
111+
fi
112+
113+
if ! curl_handler "$curl_command_presets" "$hostname"; then
114+
log "ERROR" "$RED" "Failed to backup presets for $hostname"
115+
rm -f "$presets_dest.tmp"
116+
return 1
117+
fi
109118

110119
mv "$cfg_dest.tmp" "$cfg_dest"
111120
mv "$presets_dest.tmp" "$presets_dest"
121+
log "INFO" "$GREEN" "Successfully backed up config and presets for $hostname"
122+
return 0
112123
}
113124

114125
# Update one device
@@ -146,6 +157,10 @@ while [[ $# -gt 0 ]]; do
146157
exit 0
147158
;;
148159
-t|--target)
160+
if [ -z "$2" ] || [[ "$2" == -* ]]; then
161+
log "ERROR" "$RED" "The --target option requires an argument."
162+
exit 1
163+
fi
149164
target="$2"
150165
shift 2
151166
;;
@@ -154,10 +169,18 @@ while [[ $# -gt 0 ]]; do
154169
shift
155170
;;
156171
-d|--directory)
172+
if [ -z "$2" ] || [[ "$2" == -* ]]; then
173+
log "ERROR" "$RED" "The --directory option requires an argument."
174+
exit 1
175+
fi
157176
backup_dir="$2"
158177
shift 2
159178
;;
160179
-f|--firmware)
180+
if [ -z "$2" ] || [[ "$2" == -* ]]; then
181+
log "ERROR" "$RED" "The --firmware option requires an argument."
182+
exit 1
183+
fi
161184
firmware_file="$2"
162185
shift 2
163186
;;
@@ -174,7 +197,6 @@ while [[ $# -gt 0 ]]; do
174197
exit 1
175198
;;
176199
esac
177-
178200
done
179201

180202
# Execute the appropriate command

0 commit comments

Comments
 (0)