#!/bin/sh


[ -f /etc/default/dcache ] && . /etc/default/dcache       
[ -f /etc/dcache.env ] && . /etc/dcache.env               

if [ -z "$DCACHE_HOME" ]; then                            
DCACHE_HOME="/usr/share/dcache"                         
fi                                                        
if [ ! -d "$DCACHE_HOME" ]; then                          
echo "$DCACHE_HOME is not a directory"                  
exit 2                                                  
fi                                                        

DCACHE_CLASSPATH=${DCACHE_HOME}/classes/*                 
DCACHE_DEFAULTS=${DCACHE_HOME}/defaults                   
DCACHE_CACHED_CONFIG=/var/lib/dcache/config/cache         
. ${DCACHE_HOME}/lib/loadConfig.sh                        
if [ "$(id -u)" -eq 0                                       -a -f /lib/systemd/system-generators/dcache-generator  -a "$(basename $0)" != "dcache-generator"              -a -f /bin/systemctl ]; then                         
for unit in /run/systemd/generator/dcache@*.service; do 
if [ "$DCACHE_CACHED_CONFIG" -nt "$unit" ]; then      
systemctl daemon-reload                             
break                                               
fi                                                    
done                                                    
fi

lib="$(getProperty dcache.paths.share.lib)"
. ${lib}/utils.sh

classpath=$(printLimitedClassPath dcache-vehicles dcache-chimera chimera HikariCP javassist \
    guava jline common-cli dcache-common acl-vehicles acl \
    slf4j-api logback-classic logback-core logback-console-config jcl-over-slf4j \
    spring-core spring-beans spring-jdbc spring-tx \
    postgresql h2 hsqldb)

CLASSPATH="$classpath" quickJava -Dlog=${DCACHE_LOG:-warn} \
    org.dcache.chimera.cli.Shell \
    "$(getProperty chimerashell.db.url)" \
    "$(getProperty chimerashell.db.user)" \
    "$(getProperty chimerashell.db.password)" \
    "$(getProperty chimerashell.db.password.file)" \
    "$(getProperty chimerashell.plugins.storage-info-extractor)" \
    "$(getProperty chimerashell.default-access-latency)" \
    "$(getProperty chimerashell.default-retention-policy)" \
    "$@"

