Skip to content

Instantly share code, notes, and snippets.

@gaelicWizard
Forked from gunlock/dcm4chee_install.sh
Last active October 18, 2022 14:44
Show Gist options
  • Save gaelicWizard/8937ec2418128ea205ef to your computer and use it in GitHub Desktop.
Save gaelicWizard/8937ec2418128ea205ef to your computer and use it in GitHub Desktop.
bash script to install dcm4chee and components on fresh Ubuntu 12.04 image
#!/bin/bash
set -e
function usage()
{
echo "Usage: $0 -u <Postgres_Username> -p <Password>"
}
USER=""
PASSWORD=""
while getopts "hu:p:" opt; do
case "$opt" in
h)
usage
exit 1
;;
u)
USER=$OPTARG
;;
p)
PASSWORD=$OPTARG
;;
esac
done
if [ -z "$USER" ] || [ -z "$PASSWORD" ]; then
usage
exit 1
fi
ROOT_DIR="/home/${USER}"
DB_NAME=pacsdb
INSTALL=$ROOT_DIR/dcm4chee
DCM4CHEE_VERSION=2.18.3
DCM4CHEE_NAME=dcm4chee-$DCM4CHEE_VERSION-psql
DCM4CHEE_LIB=$INSTALL/server/default/lib
JBOSS_UPPR=JBoss
JBOSS_DOWN=jboss
JBOSS_ver=4.2.3.GA
JBOSS_CAP=${JBOSS_UPPR}-4.2.3.GA
JBOSS=${JBOSS_DOWN}-4.2.3.GA
POSTGRES_VERSION=9.1
POSTGRES_JDBC_VERSION=9.4.1208
POSTGRES_DRIVER=postgresql-$POSTGRES_JDBC_VERSION.jre7.jar
PG_HBA_CONF_PATH=/etc/postgresql/$POSTGRES_VERSION/main/pg_hba.conf
source /etc/lsb-release
UBUNTU_VERSION=$DISTRIB_CODENAME # Precise (12.04), used to add postgres apt repo
JAI_IMAGEIO_64=jai_imageio-1_1-lib-linux-amd64.tar.gz
# We need zip, postgres, htop, glances
echo "Installing and upgrading packages..."
export DEBIAN_FRONTEND=noninteractive
apt-get -qq install software-properties-common
apt-get -qq install python-software-properties
# First add the PostgreSQL Apt repository
# see: http://www.postgresql.org/download/linux/ubuntu/
echo 'Adding PostgreSQL Apt Repository...'
[ ! -e "/etc/apt/sources.list.d/pgdg.list" ] && {
echo "deb http://apt.postgresql.org/pub/repos/apt/ $UBUNTU_VERSION-pgdg main" \
>> /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
}
echo 'Adding Web Update Team Apt Repository...'
[ ! -e /etc/apt/sources.list.d/webupd8team-java-precise.list ] && {
add-apt-repository -y ppa:webupd8team/java
apt-get -qq update
}
echo "Updating Apt..."
apt-get -qq update
echo "Installing packages..."
apt-get -qq install postgresql-$POSTGRES_VERSION postgresql-contrib-$POSTGRES_VERSION
apt-get -qq install htop execstack # used to "fix" /dcm4chee/bin/native libclib_jiio.so
apt-get -qq install unzip zip
apt-get -qq install oracle-java7-installer
apt-get -qq upgrade
# create dcm4chee user
echo "Creating $USER user..."
[ ! -d $ROOT_DIR ] && useradd --shell=/bin/bash --create-home $USER
# switch user (su) to $USER. All command between EOF are run as $USER user
su - $USER <<EOF
set -e
cd ${ROOT_DIR}
echo "Downloading dcm4chee $DCM4CHEE_NAME..."
wget -nv "http://sourceforge.net/projects/dcm4che/files/dcm4chee/$DCM4CHEE_VERSION/$DCM4CHEE_NAME.zip"
if [ -d "$INSTALL" ]; then
rm -rf $INSTALL
fi
unzip -uoq ${DCM4CHEE_NAME}.zip
#rm ${DCM4CHEE_NAME}.zip
mv ${DCM4CHEE_NAME} dcm4chee
echo "Downloading JBoss 4.2.3..."
# Download JBoss (current version of dcm4chee as of Aug 2014 requires JBoss 4.2.3)
wget -nv "http://sourceforge.net/projects/jboss/files/JBoss/${JBOSS_CAP}/${JBOSS}.zip"
unzip -uoq ${JBOSS}.zip
#rm ${JBOSS}.zip
# Copy files form JBoss to dcm4chee
#${INSTALL}/bin/install_jboss.sh $ROOT_DIR/${JBOSS}
rm -rf ${JBOSS}
# In order to use postgres 9 need to update driver
wget -nv "http://jdbc.postgresql.org/download/$POSTGRES_DRIVER"
mv $POSTGRES_DRIVER ${DCM4CHEE_LIB}
mv ${DCM4CHEE_LIB}/postgresql-9.1-901.jdbc4.jar ${DCM4CHEE_LIB}/postgresql-9.1-901.jdbc4.jar.old
# correct the permission on directories recursively
find . -type d -exec chmod 755 {} +
# DCM4CHEE by default includes Sun's Advanced Imaging I/O Tools (JAI_IMAGEIO) for
# i586 platforms. If install in a 32 bit platform need to replace this with
# compatibile library
# see: http://www.dcm4che.org/confluence/display/ee2/Installation#Installation-CompressionNotes
if [ `getconf LONG_BIT` == 64 ]; then
echo "Must change libclib_jiio.so to 64 bit version..."
wget -nv "http://download.java.net/media/jai-imageio/builds/release/1.1/$JAI_IMAGEIO_64" -O $JAI_IMAGEIO_64
tar xfz $JAI_IMAGEIO_64
#rm $JAI_IMAGEIO_64
rm $INSTALL/bin/native/libclib_jiio.so
cp -v jai_imageio-1_1/lib/libclib_jiio.so $INSTALL/bin/native/libclib_jiio.so
rm -rf jai_imageio-1_1
fi
echo "Installing Weasis..."
wget -nv "http://sourceforge.net/projects/dcm4che/files/Weasis/2.0.6/weasis.war"
wget -nv "http://sourceforge.net/projects/dcm4che/files/Weasis/weasis-pacs-connector/5.0.1/weasis-pacs-connector.war"
wget -nv "http://sourceforge.net/projects/dcm4che/files/Weasis/weasis-pacs-connector/5.0.1/dcm4chee-web-weasis.jar"
mv weasis.war $INSTALL/server/default/deploy
mv weasis-pacs-connector.war $INSTALL/server/default/deploy
mv dcm4chee-web-weasis.jar $INSTALL/server/default/deploy
EOF
export LUSER="$(echo $USER | tr '[:upper:]' '[:lower:]')"
# Switch to posgres user...NOTE: posgres is postgresql default superuser
psql -lqt | cut -d \| -f 1 | grep -w $DB_NAME && su - postgres <<EOF
set -e
export PGUSER=postgres
# Create the database
echo "Creating $DB_NAME database for dcm4chee..."
createdb $DB_NAME
psql $DB_NAME -f ${INSTALL}/sql/create.psql
# Configure postgres user (roll)
echo "Configuring postgres user ($LUSER) with appropriate permissions..."
psql -c "CREATE USER $LUSER WITH SUPERUSER;"
psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $LUSER;"
psql -c "ALTER USER $LUSER WITH PASSWORD '$PASSWORD'";
EOF
#The following is reported as an erorr on JBoss startup, so lets fix it
echo "Running execstack on dcm4chee/bin/native/libclib_jiio..."
execstack -c $INSTALL/bin/native/libclib_jiio.so
# Modify config files with the new postgres user ($USER) we created
echo "Updating pacs-postgres-ds.xml with user and password information..."
sed -i.bak "s#<user-name>postgres</user-name>#<user-name>$LUSER</user-name>#g" \
$INSTALL/server/default/deploy/pacs-postgres-ds.xml
sed -i.bak "s#<password></password>#<password>$PASSWORD</password>#g" \
$INSTALL/server/default/deploy/pacs-postgres-ds.xml
# Modify permissions on pacs-postgres-ds.xml since we have password in there
echo "Locking down permissions on pacs-postgres-ds.xml.."
chmod 600 $INSTALL/server/default/deploy/pacs-postgres-ds.xml
chmod 600 $INSTALL/server/default/deploy/pacs-postgres-ds.xml.bak
# Insert this one line below search string, but first read this long line to STRING
echo "Adding connection permissions to pg_hba.conf..."
sed -i.bak \
"/# Database administrative login by Unix domain socket/a local all $LUSER peer" \
$PG_HBA_CONF_PATH
echo "Creating init.d script for dcm4chee..."
wget -nv "https://gist.githubusercontent.com/gunlock/a7c0cf36221d71f8792b/raw/10b8ea0cc9cf1e110ef06f2f5730b24f8f4291fd/dcm4chee_daemon.sh" \
-O dcm4chee
chmod 755 dcm4chee
sed -i "s#DAEMON=/home/pacs/run.sh#DAEMON=$INSTALL/bin/run.sh#g" dcm4chee
sed -i "s#USER=pacs#USER=$USER#g" dcm4chee
mv dcm4chee /etc/init.d/dcm4chee
update-rc.d dcm4chee defaults
# We need to replace the stock run.sh script that ships with dcm4chee
wget -nv "https://gist.githubusercontent.com/gunlock/016dc201473851ba4441/raw/c92fe11d3e57d63925cfead458ddbdb2225f36fb/dcm4chee_run.sh" \
-O run.sh
chmod 750 run.sh
chown $USER:$USER run.sh
sed -i "s#export JBOSS_HOME=/home/pacs/dcm4chee#export JBOSS_HOME=$INSTALL#g" run.sh
mv $INSTALL/bin/run.sh $INSTALL/bin/run.sh.bak
mv run.sh $INSTALL/bin
#restart posgres
service postgresql restart
echo "To configure Weasis go to http://host_name_here/jmx-console"
echo "and set WebviewerNames = weasis and WebviewerBaseUrl = NONE"
echo "and click APPLY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment