Files
su3-launcher/i2psu3
2020-05-13 07:40:59 -04:00

132 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
#
# handler for i2p su3 files and links
#
# version
#
# zzz
#
if [ $# -ne 1 ]
then
echo "usage: $0 link"
exit 1
fi
ARG="$1"
I2PURL=http://localhost:7657/
wget "$I2PURL" -o /dev/null -O /dev/null
if [ $? -ne 0 ]
then
# check local install
I2PROUTER="$HOME/i2p/i2prouter"
if [ ! -x "$I2PROUTER" ]
then
# check system install
I2PROUTER=i2prouter
type "$I2PROUTER" > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "i2prouter is not installed"
exit 1
fi
fi
"$I2PROUTER" status > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Starting I2P..."
"$I2PROUTER" start
# wait up to 5 minutes
i=0
while [ $i -lt 60 ]
do
wget "$I2PURL" -o /dev/null -O /dev/null
if [ $? -ne 0 ]
then
echo "waiting for i2psnark..."
sleep 10
break;
fi
echo "waiting for i2p..."
sleep 5
true $((i++))
done
else
echo "I2P running but console not up?"
exit 1
fi
fi
BROWSER=`grep '^routerconsole.browser=' "$HOME/.i2p/router.config" 2> /dev/null | cut -d '=' -f 2`
if [ "x$BROWSER" = "x" ]
then
BROWSER=sensible-browser
type "$BROWSER" > /dev/null 2>&1
if [ $? -ne 0 ]
then
BROWSER=firefox
fi
fi
if [ "${ARG##http://}" != "$ARG" -o "${ARG##https://}" != "$ARG" ]
then
#plugin?
# TODO need generic su3 handler page
PAGE="configplugin?pluginFile=$ARG#TODO"
else
if [ ! \( -f "$ARG" -a -r "$ARG" \) ]
then
echo "Cannot open file $ARG"
exit 1
fi
if [ "${ARG%%.su3}" = "$ARG" ]
then
echo "Not a .su3 file: $ARG"
exit 1
fi
# get file type
TYPE=`head -c 28 "$ARG" | tail -c 1 | hd | head -n 1 | cut -c11-12`
if [ "x$TYPE" = "x" ]
then
echo "Not a .su3 file: $ARG"
exit 1
fi
case "$TYPE" in
01)
#update
PAGE=TODO
;;
02)
#plugin
PAGE="configplugins?pluginFile=$ARG#file"
;;
03)
#reseed
PAGE="configreseed?file=$ARG#file"
;;
04)
#news
PAGE=TODO
;;
05)
#blocklist
PAGE=TODO
;;
*)
echo "Unknown su3 file type: $TYPE"
exit 1
;;
esac
fi
# escape URI params
ARG=`echo "$ARG" | sed -e 's/?/%3F/g' | sed -e 's/&/%26/g'`
"$BROWSER" "${I2PURL}${PAGE}"