cic-staff-installer/setup.sh

175 lines
4.6 KiB
Bash
Raw Normal View History

2021-11-08 21:39:42 +01:00
#!/bin/bash
2021-12-04 12:46:33 +01:00
want_cic_cache_version=0.3.0a2
2022-01-24 13:06:26 +01:00
want_cicada_version=0.0.6rc1
#INSTALL_EVM=bloxberg
2021-11-08 21:39:42 +01:00
. aux/bdbg/bdbg.sh
2021-11-10 11:32:14 +01:00
2021-11-08 21:39:42 +01:00
_level=2
_debug=1
PIP_EXTRA_ARGS=$PIP_EXTRA_ARGS
PIP_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL:-https://pip.grassrootseconomics.net}
2021-11-08 21:39:42 +01:00
PIP_INDEX_URL=${PIP_INDEX_URL:-"https://pypi.org/simple"}
CIC_SETUP_TRUSTED_FINGERPRINT=${CIC_SETUP_TRUSTED_FINGERPRINT:-0826EDA1702D1E87C6E2875121D2E7BB88C2A746}
2022-01-25 15:12:57 +01:00
CIC_ROOT_URL=${CIC_ROOT_URL:-https://root.grassrootseconomics.net/env/dev}
CIC_ROOT_CA_FILE=${CIC_ROOT_CA_FILE:-keys/ge.ca}
2021-11-08 21:39:42 +01:00
if [ "$UID" -eq 0 ]; then
dbg $dbg_error "This cannot be run as root"
exit 1
fi
2021-11-10 09:43:30 +01:00
. setup_check.sh
2021-11-10 11:32:14 +01:00
. setup_path.sh
2021-11-10 09:43:30 +01:00
2021-11-16 06:06:49 +01:00
mkdir -vp $HOME/.local/bin
2021-11-10 09:43:30 +01:00
dbg $dbg_debug "importing keys"
mkdir -vp $HOME/.local/share/cic/.gnupg
chmod 700 $HOME/.local/share/cic/.gnupg
2021-11-10 09:43:30 +01:00
for f in ./keys/*.asc; do
gpg --homedir $HOME/.local/share/cic/.gnupg --import $f
2021-11-10 09:43:30 +01:00
done
gpg --homedir $HOME/.local/share/cic/.gnupg --import-ownertrust ./keys/trust
2021-11-10 09:43:30 +01:00
t=`mktemp`
dbg $dbg_debug "identify root values"
2021-11-11 08:29:03 +01:00
set -e
2021-11-10 09:43:30 +01:00
# check if we have existing setup
2022-01-21 16:23:11 +01:00
if [ ! -e "$HOME/.config/cic/staff-client/.envinit" ]; then
2021-11-10 09:43:30 +01:00
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`
2022-01-25 15:12:57 +01:00
curl -X GET --cacert $CIC_ROOT_CA_FILE $CIC_ROOT_URL/$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`
2021-11-10 09:43:30 +01:00
echo $v >> $t
dbg $dbg_debug "fetched environment variable $v"
else
dbg $dbg_debug "using predefined environment variable for $c = $v"
fi
done
2021-11-10 09:43:30 +01:00
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
2021-11-11 08:29:03 +01:00
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
2022-01-21 16:23:11 +01:00
touch "$HOME/.config/cic/staff-client/.envinit"
2021-11-10 09:43:30 +01:00
fi
2021-11-11 08:29:03 +01:00
set +e
2021-11-08 21:39:42 +01:00
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
2021-11-10 09:43:30 +01:00
dbg $dbg_info "cli-cache version $v found"
2021-11-08 21:39:42 +01:00
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
2021-11-10 09:43:30 +01:00
dbg $dbg_info "clicada version $v found"
2021-11-08 21:39:42 +01:00
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
2021-11-10 11:32:14 +01:00
update_path $HOME/.local/bin
2021-11-08 21:39:42 +01:00
fi
2021-11-10 09:43:30 +01:00
dbg $dbg_debug "installing configurations"
2021-11-08 21:39:42 +01:00
t=`mktemp`
if [ -f $HOME/.config/cic/cache/config.ini ]; then
dbg $dbg_debug "migrating existing configuration"
2021-11-10 09:43:30 +01:00
cic_cache_config_flag="-c $HOME/.config/cic/cache"
2021-11-08 21:39:42 +01:00
fi
2021-11-10 09:43:30 +01:00
cic-cache-trackerd --dumpconfig ini $cic_cache_config_flag -vv > $t
2021-11-08 21:39:42 +01:00
mkdir -vp $HOME/.config/cic/cache
2021-11-10 09:43:30 +01:00
mv -v $t $HOME/.config/cic/cache/config.ini
2021-11-08 21:39:42 +01:00
if [ -d $HOME/.config/cic/clicada/config.ini ]; then
dbg $dbg_debug "migrating existing clicada configuration"
2021-11-10 09:43:30 +01:00
clicada_config_flag="-c $HOME/.config/cic/clicada"
2021-11-08 21:39:42 +01:00
fi
2021-11-11 08:29:03 +01:00
2021-11-10 09:43:30 +01:00
clicada --dumpconfig ini $clicada_config_flag > $t
2021-11-08 21:39:42 +01:00
mkdir -vp $HOME/.config/cic/clicada
2021-11-10 09:43:30 +01:00
mv -v $t $HOME/.config/cic/clicada/config.ini
t=`mktemp`
cic-cache-trackerd --dumpconfig env $cic_cache_config_flag -vv > $t
2021-11-11 08:29:03 +01:00
set -a
2021-11-10 09:43:30 +01:00
. $t
2021-11-11 08:29:03 +01:00
set +a
2021-11-10 09:43:30 +01:00
dbg $dbg_debug "execute database migrations"
mkdir -vp $HOME/.local/share/cic/cache
2021-11-14 12:50:32 +01:00
migrate_cic_cache.py -c $HOME/.config/cic/cache/
2021-11-08 21:39:42 +01:00
2021-11-11 08:29:03 +01:00
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