diff options
author | Erich Eckner <git@eckner.net> | 2022-09-13 22:40:35 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2022-09-13 22:40:35 +0200 |
commit | 0e88034af8e2729f51b4e91e0cd73080143800a9 (patch) | |
tree | 7153aff8690e69d6577d05176a8ab4b418e73345 | |
parent | 7b602facf0e68b06e1fb5b5cad2f8d6ced7c8ca5 (diff) | |
download | airgapd-0e88034af8e2729f51b4e91e0cd73080143800a9.tar.xz |
curl new
-rwxr-xr-x | bin/curl | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/bin/curl b/bin/curl new file mode 100755 index 0000000..1570da6 --- /dev/null +++ b/bin/curl @@ -0,0 +1,43 @@ +#!/bin/bash + +usage() { + >&2 echo 'usage: '"$0"' -o file url' + exit +} + +if [ "$#" -ne 3 ] || [ ! "x$1" = 'x-o' ]; then + usage +fi + +file="$2" +url=$( + printf -- '%s' "${3}" \ + | base64 -w0 +) + +work_dir=$(readlink -e "$0") +work_dir="${work_dir%/*/*}/work" + +if [ ! -d "${work_dir}" ]; then + mkdir "${work_dir}" + echo 'files' >"${work_dir}"'/.gitignore' + git -C "${work_dir}" init + git -C "${work_dir}" add '.gitignore' + git -C "${work_dir}" commit -m 'initial commit' +fi + +if [ -s "${work_dir}/files/${url}" ]; then + cp "${work_dir}/files/${url}" "${file}" + exit +fi + +{ + printf -- '%s\n' "${url}" + [ -s "${work_dir}/wishlist" ] \ + && cat "${work_dir}/wishlist" +} \ +| sort -u \ +| sponge "${work_dir}/wishlist" + +git -C "${work_dir}" add 'wishlist' +git -C "${work_dir}" commit -m 'new wishes' |