aboutsummaryrefslogtreecommitdiff
path: root/genclient-embed.sh
diff options
context:
space:
mode:
Diffstat (limited to 'genclient-embed.sh')
-rwxr-xr-xgenclient-embed.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/genclient-embed.sh b/genclient-embed.sh
new file mode 100755
index 0000000..8c4c144
--- /dev/null
+++ b/genclient-embed.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+. ./vars
+
+help() {
+cat <<EOF
+Usage: $0
+
+ Generates a client shell script based on the variables set in 'vars'
+ and prints to stdout
+
+EOF
+exit 1;
+}
+
+while [ $# -gt 0 ] ; do case $1 in
+ *) help ;;
+esac; done
+
+cat <<EOF
+#!/bin/sh
+socat="\$(mktemp)"
+
+sed -ne'/^__BEGIN'_'SOCAT__/,\$p' "\$0" | sed 1d | base64 -d \\
+ | gzip -dc > "\$socat"
+
+chmod +x "\$socat"
+
+_shell="\$(which zsh mksh bash ksh zsh ash sh 2>/dev/null | sed 1q)"
+certificate='$(cat ${basename}.crt)'
+crt_tmp="\$(mktemp)"
+trap 'rm -f \$crt_tmp \$socat; exit 0' EXIT INT
+echo "\$certificate" > "\$crt_tmp"
+while [ $loop -ne 0 ] ; do
+"\$socat" exec:"\$_shell",pty,stderr,setsid,sigint,sane \\
+ "OPENSSL:$hostname:$port,verify=$verify,cafile=\$crt_tmp"
+sleep $timeout
+done
+
+exit 0
+
+__BEGIN_SOCAT__
+EOF
+
+if [ -e socat/socat ] ; then
+ gzip -9c < socat/socat | base64
+fi
+