summaryrefslogtreecommitdiffstats
path: root/cac
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2015-11-25 22:37:58 +0100
committermakefu <github@syntax-fehler.de>2015-11-25 22:37:58 +0100
commit55347fef150377a33352168c73a04d5b8c25f343 (patch)
tree2bdc9f2066abb7b64d22f76b6169be1144ac400a /cac
parent14de1d3c78385e3f8b6d694f5d799eb1b613159e (diff)
refactor
Diffstat (limited to 'cac')
-rwxr-xr-xcac159
1 files changed, 90 insertions, 69 deletions
diff --git a/cac b/cac
index 25029e1..47cde3d 100755
--- a/cac
+++ b/cac
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /usr/bin/env bash
#
#? cac - CloudAtCost command line interface
#?
@@ -9,58 +9,6 @@ set -euf
#PATH=$PWD/bin:$PATH
#export PATH
-urlencode() {
-#! /bin/sh
-sed '
- s/%/%25/g
- s/ /%20/g
- s/!/%21/g
- s/"/%22/g
- s/#/%23/g
- s/\$/%24/g
- s/\&/%26/g
- s/'\''/%27/g
- s/(/%28/g
- s/)/%29/g
- s/\*/%2a/g
- s/+/%2b/g
- s/,/%2c/g
- s/-/%2d/g
- s/\./%2e/g
- s/\//%2f/g
- s/:/%3a/g
- s/;/%3b/g
- s//%3e/g
- s/?/%3f/g
- s/@/%40/g
- s/\[/%5b/g
- s/\\/%5c/g
- s/\]/%5d/g
- s/\^/%5e/g
- s/_/%5f/g
- s/`/%60/g
- s/{/%7b/g
- s/|/%7c/g
- s/}/%7d/g
- s/~/%7e/g
-'
-}
-netmask_to_prefix() {(
-#! /bin/sh
-set -euf
-
-netmask=$1
-
-binaryNetmask=$(echo $1 | sed 's/^/obase=2;/;s/\./;/g' | bc | tr -d \\n)
-binaryPrefix=$(echo $binaryNetmask | sed -n 's/^\(1*\)0*$/\1/p')
-if ! echo $binaryPrefix | grep -q .; then
- echo $0: bad netmask: $netmask >&2
- exit 4
-fi
-printf %s $binaryPrefix | tr -d 0 | wc -c
-)}
-#
-
cac_resources_cache=${cac_resources_cache-$HOME/tmp/cac_resources_cache.json}
cac_servers_cache=${cac_servers_cache-$HOME/tmp/cac_servers_cache.json}
cac_tasks_cache=${cac_tasks_cache-$HOME/tmp/cac_tasks_cache.json}
@@ -68,8 +16,14 @@ cac_templates_cache=${cac_templates_cache-$HOME/tmp/cac_templates_cache.json}
cac_secrets=${cac_secrets-$HOME/.secrets/cac}
-
-. "$cac_secrets" >/dev/null 2>&1 || :
+_load_secrets() {
+ if test -e "$cac_secrets" ;then
+ echo "unable to load secrets from '$cac_secrets'" >&2
+ __cac_cli_help
+ else
+ . "$cac_secrets"
+ fi
+}
cac() {
@@ -368,7 +322,18 @@ __cac_cli__delete() {(
_cac_handle_reply 'cac delete' "$reply"
)}
-
+#?
+#? Uses the following `environment variables`:
+#? cac_resources_cache=$HOME/tmp/cac_resources_cache.json
+#? cac_servers_cache=$HOME/tmp/cac_servers_cache.json
+#? cac_tasks_cache=$HOME/tmp/cac_tasks_cache.json
+#? cac_templates_cache=$HOME/tmp/cac_templates_cache.json
+#? cac_secrets=$HOME/.secrets/cac
+#? You can override these by setting them beforehand.
+#?
+#? `cac_secrets` will be sourced and may provide the following two entries:
+#? cac_login=<cac-email>
+#? cac_key=<cac-api-key>
#?
#? SERVERSPEC is a query like "mode:Safe", "sdate:08/04/2015", etc.
#? See `cac servers` to get an inspiration.
@@ -425,16 +390,6 @@ _cac_fetch_resources() {(
)}
-# rsyncfiles : lines filename |> local-dir x rsync-target -> ? |> ?
-rsyncfiles() {(
- set -x
- rsync \
- --rsync-path="mkdir -p \"$2\" && rsync" \
- -vzrlptD \
- --files-from=- \
- "$1"/ \
- "$2"
-)}
@@ -483,10 +438,76 @@ _cac_exec() {
fi
}
+_main() {
+ _load_secrets
+ case ${run-true} in
+ true) cac "$@";;
+ esac
+}
+#
+# imported:
+urlencode() {
+sed '
+ s/%/%25/g
+ s/ /%20/g
+ s/!/%21/g
+ s/"/%22/g
+ s/#/%23/g
+ s/\$/%24/g
+ s/\&/%26/g
+ s/'\''/%27/g
+ s/(/%28/g
+ s/)/%29/g
+ s/\*/%2a/g
+ s/+/%2b/g
+ s/,/%2c/g
+ s/-/%2d/g
+ s/\./%2e/g
+ s/\//%2f/g
+ s/:/%3a/g
+ s/;/%3b/g
+ s//%3e/g
+ s/?/%3f/g
+ s/@/%40/g
+ s/\[/%5b/g
+ s/\\/%5c/g
+ s/\]/%5d/g
+ s/\^/%5e/g
+ s/_/%5f/g
+ s/`/%60/g
+ s/{/%7b/g
+ s/|/%7c/g
+ s/}/%7d/g
+ s/~/%7e/g
+'
+}
+
+netmask_to_prefix() {(
+ set -euf
+
+ netmask=$1
+ binaryNetmask=$(echo $1 | sed 's/^/obase=2;/;s/\./;/g' | bc | tr -d \\n)
+ binaryPrefix=$(echo $binaryNetmask | sed -n 's/^\(1*\)0*$/\1/p')
+ if ! echo $binaryPrefix | grep -q .; then
+ echo $0: bad netmask: $netmask >&2
+ exit 4
+ fi
+ printf %s $binaryPrefix | tr -d 0 | wc -c
+)}
+
+# rsyncfiles : lines filename |> local-dir x rsync-target -> ? |> ?
+rsyncfiles() {(
+ set -x
+ rsync \
+ --rsync-path="mkdir -p \"$2\" && rsync" \
+ -vzrlptD \
+ --files-from=- \
+ "$1"/ \
+ "$2"
+)}
+#
-case ${run-true} in
- true) cac "$@";;
-esac
+_main "$@"