2020-06-20 22:13:30 +00:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
2020-06-28 13:38:15 +00:00
|
|
|
download="$( cat "$__object/parameter/download" )"
|
|
|
|
|
|
|
|
state_is="$( cat "$__object/explorer/state" )"
|
|
|
|
|
|
|
|
if [ "$download" = 'remote' ] && [ "$state_is" != 'present' ]
|
|
|
|
then
|
2021-06-22 13:36:30 +00:00
|
|
|
cmd_get="$( cat "$__object/explorer/remote_cmd_get" )"
|
2020-06-28 13:38:15 +00:00
|
|
|
|
|
|
|
url="$( cat "$__object/parameter/url" )"
|
|
|
|
|
2021-06-22 13:36:30 +00:00
|
|
|
if [ -f "$__object/parameter/destination" ]
|
|
|
|
then
|
|
|
|
dst="$( cat "$__object/parameter/destination" )"
|
|
|
|
else
|
|
|
|
dst="/$__object_id"
|
|
|
|
fi
|
2020-06-28 13:38:15 +00:00
|
|
|
|
2021-06-22 13:36:30 +00:00
|
|
|
echo "download_tmp=\"\$( mktemp )\""
|
2020-06-28 13:38:15 +00:00
|
|
|
|
2021-06-22 13:36:30 +00:00
|
|
|
# shellcheck disable=SC2059
|
|
|
|
printf "$cmd_get > \"\$download_tmp\"\n" "$url"
|
|
|
|
|
|
|
|
if [ -f "$__object/parameter/sum" ]
|
|
|
|
then
|
|
|
|
sum_should="$( cat "$__object/parameter/sum" )"
|
|
|
|
|
|
|
|
if [ -f "$__object/parameter/cmd-sum" ]
|
|
|
|
then
|
|
|
|
remote_cmd_sum="$( cat "$__object/parameter/cmd-sum" )"
|
|
|
|
else
|
|
|
|
remote_cmd_sum="$( cat "$__object/explorer/remote_cmd_sum" )"
|
|
|
|
|
|
|
|
if echo "$sum_should" | grep -Fq ':'
|
|
|
|
then
|
|
|
|
sum_should="$( echo "$sum_should" | cut -d : -f 2 )"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# shellcheck disable=SC2059
|
|
|
|
echo "sum_is=\"\$( $( printf "$remote_cmd_sum" "\"\$download_tmp\"" ) )\""
|
|
|
|
|
|
|
|
echo "if [ \"\$sum_is\" != '$sum_should' ]; then"
|
|
|
|
|
|
|
|
echo "echo 'remote download checksum mismatch' >&2"
|
|
|
|
|
|
|
|
echo "rm -f \"\$download_tmp\""
|
|
|
|
|
|
|
|
echo 'exit 1; fi'
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "mv \"\$download_tmp\" '$dst'"
|
2020-06-28 13:38:15 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-08 10:43:55 +00:00
|
|
|
if [ -f "$__object/parameter/onchange" ] && [ "$state_is" != "present" ]
|
2020-06-20 22:13:30 +00:00
|
|
|
then
|
|
|
|
cat "$__object/parameter/onchange"
|
|
|
|
fi
|