summaryrefslogtreecommitdiffstats
path: root/ship/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ship/lib')
-rw-r--r--ship/lib/core9
-rw-r--r--ship/lib/network13
-rw-r--r--ship/lib/tor19
3 files changed, 34 insertions, 7 deletions
diff --git a/ship/lib/core b/ship/lib/core
index 3a6b33ff..1ef1fbf9 100644
--- a/ship/lib/core
+++ b/ship/lib/core
@@ -2,15 +2,22 @@
msg() { printf "$@\n" >&2 ;}
info() { msg "** $@" ;}
error() { msg "!! $@" ;}
+die() { error "$@" ;exit 1;}
exists(){ type "$1" >/dev/null 2>/dev/null; }
is_root(){
test $(id -u) -eq 0
+}
+
+defer(){
+ #close enough
+ trapstr="$1;${trapstr:-exit}"
+ trap "$trapstr" INT TERM EXIT KILL
}
esudo(){
# becomes root with sudo powers
# unless nosudo env is set
- if test "${nosudo-false}" != true || is_root; then
+ if test "${nosudo-false}" != true && ! is_root; then
echo "we're going sudo..." >&2
exec sudo -E "$0" "$@"
exit 23 # go to hell
diff --git a/ship/lib/network b/ship/lib/network
index 0e494514..74edcbac 100644
--- a/ship/lib/network
+++ b/ship/lib/network
@@ -46,15 +46,16 @@ which_telnet(){
# netcat
# busybox telnet
if [ -e "${TELNET:-does_not_exist}" ]; then
- info"Will be using $TELNET as Telnet Client"
+ info "Will be using $TELNET as Telnet Client"
+ echo $TELNET
elif exists telnet ;then
- TELNET="$(command -v telnet)"
+ command -v telnet
elif exists nc ;then
- TELNET="$(command -v nc)"
+ command -v nc
elif exists netcat;then
- echo "$(command -v netcat)"
+ command -v netcat
elif exists busybox;then
- echo "$(command -v busybox) telnet"
+ echo `command -v busybox` telnet
else
error "Cannot find telnet binary, please install either telnet-client or busybox or netcat or provided TELNET environment.\nbailing out!"
return 1
@@ -64,7 +65,7 @@ which_telnet(){
run_telnet(){
host="$1"
port="$2"
- $(which_telnet) $host $port
+ $(which_telnet) "$host" "$port"
}
send_irc(){
diff --git a/ship/lib/tor b/ship/lib/tor
new file mode 100644
index 00000000..8d9e33f1
--- /dev/null
+++ b/ship/lib/tor
@@ -0,0 +1,19 @@
+# can be set via env:
+# torrc - path to torrc (default: /etc/tor/torrc )
+# hidden_service_dir - path to hidden service (default: /var/lib/tor/hidden_service/ )
+
+
+torrc=${torrc:-/etc/tor/torrc}
+hidden_service_dir=${hidden_service_dir:-/var/lib/tor/hidden_service/}
+
+configure_hidden_service(){
+ if ! grep -q '^HiddenService' "$torrc" ;then
+ info "adding hidden service to $torrc"
+ cat >> "$torrc" << EOF
+HiddenServiceDir ${hidden_service_dir}
+HiddenServicePort 22 127.0.0.1:22
+EOF
+ else
+ info "HiddenServiceDir or Port already in $torrc, skipping!"
+ fi
+}