#!/bin/bash want_cic_cache_version=0.3.0a2 want_cicada_version=0.0.6rc1 #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} 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 mkdir -vp $HOME/.local/bin 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 [ ! -e "$HOME/.config/cic/staff-client/.envinit" ]; 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 touch "$HOME/.config/cic/staff-client/.envinit" 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_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 migrate_cic_cache.py -c $HOME/.config/cic/cache/ t=`mktemp` clicada --dumpconfig env $clicada_config_flag -vv > $t set -a . $t set +a . setup_systemd.sh if [ ! -z $INSTALL_EVM ]; then . setup_${INSTALL_EVM}.sh fi