summaryrefslogtreecommitdiff
path: root/url_to_id
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2018-08-01 10:27:54 +0100
committerKatolaZ <katolaz@freaknet.org>2018-08-01 10:27:54 +0100
commit11856792221c7faa2f423bc106d1f4b1482bcdb8 (patch)
tree10f5bb3a40ab184272efb31bfecc3bcc3da136e9 /url_to_id
parent040ba18f7fd17b4d6dc3a93549a19263fb0b8a95 (diff)
new url_to_id and added dry-run in burrow
Diffstat (limited to 'url_to_id')
-rwxr-xr-xurl_to_id57
1 files changed, 54 insertions, 3 deletions
diff --git a/url_to_id b/url_to_id
index 69cc0fc..4d96442 100755
--- a/url_to_id
+++ b/url_to_id
@@ -1,15 +1,25 @@
#!/bin/sh
-## get a selector in gph format:
+##
+## Get a gopherlink in the format:
+##
+## gopher://domain.org:port/*/my/cool/selector
+##
+## or a selector in gph format:
##
## [TYPE|SEL|HOST|PORT]
##
-## and print on output the corresponding selectorid:
+## and print on output the corresponding "unique" selectorid:
##
## TYPE|SEL|HOST|PORT|SHA256
##
## which is understood by `burrow`
+
+###
+### get a selector in gph format and transform it in a selectorid
+###
+## function
gph_to_id(){
gph="$( echo $1| sed 's/\[//g;s/\]//g')"
OLDIFS=$IFS
@@ -20,4 +30,45 @@ gph_to_id(){
IFS="$OLDIFS"
}
-gph_to_id "$1"
+###
+### Get a gopherurl and transform it in a selectorid
+###
+## function
+gopherurl_to_id(){
+ URL="$(echo $1 | sed 's,gopher://,,g')"
+ hostport=$(echo "$URL" | cut -d "/" -f 1)
+ host="$(echo $hostport | cut -d ":" -f 1)"
+ port="$(echo $hostport | cut -s -d ":" -f 2)"
+ [ -z "$port" ] && port='70'
+ type=$(echo "$URL" | cut -s -d "/" -f 2)
+ [ -z "$type" ] && {
+ type='1'
+ sel="/"
+ gph_to_id "[${type}|${sel}|${host}|$port]"
+ exit 0
+ }
+ [ -n "${type#?}" ] && echo "Invalid Gopher URL" >&2 && exit 1
+ ## Check if type is a valid one
+ type="$(echo $type | sed -n '/^[0-9ITghis+]$/p')"
+ [ -z "${type}" ] && echo "Invalid Gopher URL" >&2 && exit 1
+ sel=/$(echo "$URL" | cut -s -d "/" -f 3-)
+ gph_to_id "[${type}|${sel}|${host}|$port]"
+
+}
+
+
+
+[ $# -lt 1 ] && echo "Usage: $0 <gopherurl>" && echo " $0 <gphselector>" && exit 1
+
+
+[ -n "$(echo $1 | sed -n '/^gopher:\/\//p')" ] && {
+ gopherurl_to_id "$1"
+ exit 0
+}
+
+[ -n "$(echo $1 | sed -n '/^\[.*\]$/p')" ] && {
+ gph_to_id "$1"
+ exit 0
+}
+echo "No valid URL or gph selector provided" >&2
+exit 1