#!/bin/sh

# Comment out/change port number as needed
ssh_port="-p 7822"
# Get password from remote fossil repos
test -z $1 && printf "Usage: $0 <repos>\nExample: $0 b64\n" && exit
dir=/home/redantig/fossil/repos
r=${dir}/$1.fossil
# Newer versions of Fossil databases are not compatible with the 'sqlite3 -line' command
# sql_command="sqlite3 -line ${r} 'select login,pw from user where login="'"redantig"'" or login="'"kuuse"'";'"
# Error: malformed database schema (vcache) - near "WITHOUT": syntax error
sql_command="fossil sql -R ${r} \"select login,pw from user where login='redantig' or login='kuuse';\""
ssh ${ssh_port} redantig@kuu.se \
    "if [ -e ${r} ];then \
       printf \"Querying ${r}:\n\"; \
       printf \" %s\" ${sql_command}; \
       echo; \
       echo '------------------'; \
       ${sql_command}; \
       echo '------------------'; \
     else \
       printf \"Repos ${r} does not exist!\nAvailable repos:\n\"; \
       l="'`ls '${dir}'/*.fossil`'"; \
       for i in \${l} ; do \
         echo -n '  '; \
         basename \$i .fossil; \
       done; \
     fi"
