184 lines
4.9 KiB
Bash
184 lines
4.9 KiB
Bash
#!/bin/bash
|
|
|
|
want_cic_cache_version=0.2.1a10
|
|
want_cicada_version=0.0.1a9
|
|
#INSTALL_EVM=bloxberg
|
|
|
|
. aux/bdbg/bdbg.sh
|
|
|
|
_level=2
|
|
_debug=1
|
|
|
|
PIP_EXTRA_ARGS=$PIP_EXTRA_ARGS
|
|
PIP_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL:-https://pip.grassrootseconomics.net:8433}
|
|
PIP_INDEX_URL=${PIP_INDEX_URL:-"https://pypi.org/simple"}
|
|
CIC_SETUP_TRUSTED_FINGERPRINT=${CIC_SETUP_TRUSTED_FINGERPRINT:-0826EDA1702D1E87C6E2875121D2E7BB88C2A746}
|
|
CIC_ROOT_URL=${CIC_ROOT_URL:-https://root.grassrootseconomics.net}
|
|
|
|
if [ "$UID" -eq 0 ]; then
|
|
dbg $dbg_error "This cannot be run as root"
|
|
exit 1
|
|
fi
|
|
|
|
. setup_check.sh
|
|
. setup_path.sh
|
|
|
|
dbg $dbg_debug "importing keys"
|
|
|
|
mkdir -vp $HOME/.local/share/cic/.gnupg
|
|
chmod 700 $HOME/.local/share/cic/.gnupg
|
|
for f in ./keys/*.asc; do
|
|
gpg --homedir $HOME/.local/share/cic/.gnupg --import $f
|
|
done
|
|
gpg --homedir $HOME/.local/share/cic/.gnupg --import-ownertrust ./keys/trust
|
|
|
|
t=`mktemp`
|
|
dbg $dbg_debug "identify root values"
|
|
|
|
set -e
|
|
# check if we have existing setup
|
|
if [ ! -f "$HOME/.config/cic/staff-client/key_fingerprint" ]; then
|
|
dbg $dbg_debug "load default environment"
|
|
|
|
config_directives=(CIC_REGISTRY_ADDRESS CIC_TRUST_ADDRESS META_URL TX_CACHE_URL CHAIN_SPEC)
|
|
|
|
for c in ${config_directives[@]}; do
|
|
v=${!c}
|
|
if [ -z "$v" ]; then
|
|
d=`mktemp -d`
|
|
curl -X GET $CIC_ROOT_URL/cic-staff-client/$c -o $d/$c
|
|
gpg --homedir $HOME/.local/share/cic/.gnupg --verify $d/$c
|
|
v=`gpg --homedir $HOME/.local/share/cic/.gnupg -d $d/$c`
|
|
echo $v >> $t
|
|
dbg $dbg_debug "fetched environment variable $v"
|
|
else
|
|
dbg $dbg_debug "using predefined environment variable for $c = $v"
|
|
fi
|
|
done
|
|
|
|
set -a
|
|
. $t
|
|
set +a
|
|
|
|
# DATABASE_NAME set here works as long as only one database is involved...
|
|
export DATABASE_PREFIX=$HOME/.local/share/cic/cache/${DATABASE_PREFIX:-staffclient}
|
|
export DATABASE_ENGINE=sqlite
|
|
export DATABASE_DRIVER=pysqlite
|
|
export DATABASE_DEBUG=0
|
|
export DATABASE_POOL_SIZE=0
|
|
export DATABASE_USER=postgres
|
|
export DATABASE_PASSWORD=`dd if=/dev/urandom bs=32 count=1 2> /dev/null | hexdump -v -n 32 -e '1/1 "%02x"'`
|
|
|
|
dbg $dbg_debug "set up keys"
|
|
if [ -z "$AUTH_KEY" ]; then
|
|
. setup_key.sh
|
|
else
|
|
t=`mktemp`
|
|
gpg --export -a $AUTH_KEY > $t
|
|
echo -n $AUTH_KEY > $HOME/.config/cic/staff-client/key_fingerprint
|
|
dbg $dbg_info "using key $AUTH_KEY"
|
|
fi
|
|
export AUTH_KEY=`cat $HOME/.config/cic/staff-client/key_fingerprint`
|
|
export AUTH_KEYRING_PATH=$HOME/.config/cic/staff-client/.gnupg
|
|
export AUTH_DB_PATH=$HOME/.local/share/cic/clicada
|
|
fi
|
|
set +e
|
|
|
|
dbg $dbg_debug "checking installed versions"
|
|
|
|
update=0
|
|
v=`pip show cic-cache | awk '/^Version/ {print $2;}'`
|
|
if [ "$?" -ne 0 ]; then
|
|
dbg $dbg_warn "cic-cache is not installed. will update"
|
|
update=1
|
|
elif [ "$v" != "$want_cic_cache_version" ]; then
|
|
dbg $dbg_warn "cli-cache version $v installed but need $want_cic_cache_version, will update"
|
|
update=1
|
|
else
|
|
dbg $dbg_info "cli-cache version $v found"
|
|
fi
|
|
|
|
v=`pip show clicada | awk '/^Version/ {print $2;}'`
|
|
if [ "$?" -ne 0 ]; then
|
|
dbg $dbg_warn "clicada is not installed, will update"
|
|
update=1
|
|
elif [ "$v" != "$want_cicada_version" ]; then
|
|
dbg $dbg_warn "clicada version $v installed but need $want_cicada_version, will update"
|
|
update=1
|
|
else
|
|
dbg $dbg_info "clicada version $v found"
|
|
fi
|
|
|
|
set -e
|
|
|
|
if [ $update -gt 0 ]; then
|
|
dbg $dbg_debug "installing application files"
|
|
|
|
debug_flag=
|
|
if [ "$_level" -eq 1 ]; then
|
|
debug_flag="-v"
|
|
fi
|
|
pip install --index-url $PIP_INDEX_URL --extra-index-url $PIP_EXTRA_INDEX_URL $PIP_EXTRA_ARGS $debug_flag -r requirements.txt
|
|
update_path $HOME/.local/bin
|
|
fi
|
|
|
|
|
|
#dbg $dbg_info "using CIC_REGISTRY $CIC_REGISTRY_ADDRESS"
|
|
|
|
#if [ -z "$CIC_TRUST_ADDRESS" ]; then
|
|
# u="$CIC_ROOT_URL/cic_trust_address"
|
|
# dbg $dbg_trace "retrieve trust address from $u"
|
|
# curl -X GET $u -o cic_trust_address
|
|
# gpg --verify cic_trust_address
|
|
# export CIC_TRUST_ADDRESS=`gpg -d cic_trust_address`
|
|
#fi
|
|
#dbg $dbg_info "using CIC_TRUST_ADDRESS $CIC_TRUST_ADDRESS"
|
|
|
|
#popd
|
|
|
|
dbg $dbg_debug "installing configurations"
|
|
t=`mktemp`
|
|
if [ -f $HOME/.config/cic/cache/config.ini ]; then
|
|
dbg $dbg_debug "migrating existing configuration"
|
|
cic_cache_config_flag="-c $HOME/.config/cic/cache"
|
|
fi
|
|
cic-cache-trackerd --dumpconfig ini $cic_cache_config_flag -vv > $t
|
|
mkdir -vp $HOME/.config/cic/cache
|
|
mv -v $t $HOME/.config/cic/cache/config.ini
|
|
|
|
if [ -d $HOME/.config/cic/clicada/config.ini ]; then
|
|
dbg $dbg_debug "migrating existing clicada configuration"
|
|
clicada_config_flag="-c $HOME/.config/cic/clicada"
|
|
fi
|
|
|
|
clicada --dumpconfig ini $clicada_config_flag > $t
|
|
mkdir -vp $HOME/.config/cic/clicada
|
|
mv -v $t $HOME/.config/cic/clicada/config.ini
|
|
|
|
t=`mktemp`
|
|
cic-cache-trackerd --dumpconfig env $cic_cache_config_flag -vv > $t
|
|
set -a
|
|
. $t
|
|
set +a
|
|
|
|
dbg $dbg_debug "execute database migrations"
|
|
|
|
mkdir -vp $HOME/.local/share/cic/cache
|
|
|
|
python ../cic-internal-integration/apps/cic-cache/scripts/migrate.py -c $HOME/.config/cic/cache/
|
|
|
|
t=`mktemp`
|
|
clicada --dumpconfig env $clicada_config_flag -vv > $t
|
|
set -a
|
|
. $t
|
|
set +a
|
|
|
|
. setup_systemd.sh
|
|
|
|
echo foo $INSTALL_EVM
|
|
if [ ! -z $INSTALL_EVM ]; then
|
|
. setup_${INSTALL_EVM}.sh
|
|
fi
|
|
|
|
|