Skip to content

Instantly share code, notes, and snippets.

@gunlock
Last active March 1, 2016 21:56
Show Gist options
  • Save gunlock/e17e369d021c37eb42a4 to your computer and use it in GitHub Desktop.
Save gunlock/e17e369d021c37eb42a4 to your computer and use it in GitHub Desktop.
bash script to install dcm4chee and components on fresh Ubuntu 12.04 image
#!/bin/bash
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}"
INSTALL=$ROOT_DIR/dcm4chee
DCM4CHEE_NAME=dcm4chee-2.17.1-psql
DCM4CHEE_LIB=$INSTALL/server/default/lib
JBOSS=jboss-4.2.3.GA
POSTGRES_VERSION=9.3
POSTGRES_DRIVER=postgresql-9.3-1102.jdbc41.jar
PG_HBA_CONF_PATH=/etc/postgresql/$POSTGRES_VERSION/main/pg_hba.conf
UBUNTU_VERSION=precise # Precise (12.04), used to add postgres apt repo
JAI_IMAGEIO_64=jai_imageio-1_1-lib-linux-amd64.tar.gz
# First add the PostgreSQL Apt repository
# see: http://www.postgresql.org/download/linux/ubuntu/
echo 'Adding PostgreSQL Apt Repository...'
if [ ! -f "/etc/apt/sources.list.d/pgdg.list" ]; then
touch /etc/apt/sources.list.d/pgdg.list
fi
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 "Updating Apt..."
apt-get update > /dev/null
# We need zip, postgres, htop, glances
echo "Upgrading system..."
DEBIAN_FRONTEND=noninteractive apt-get -y upgrade > /dev/null
DEBIAN_FRONTEND=noninteractive apt-get -y install unzip zip > /dev/null
DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql-$POSTGRES_VERSION \
postgresql-contrib htop execstack > /dev/null
DEBIAN_FRONTEND=noninteractive apt-get -y install execstack > /dev/null # used to "fix" /dcm4chee/bin/native libclib_jiio.so
# install Java
wget -nv "https://gist.githubusercontent.com/gunlock/aa6729dcb386a85a99cb/raw/c4ccf541351260a9235088024470270a27f4f03d/java_install.sh"
chmod 700 java_install.sh
./java_install.sh
export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin
export JRE_HOME=$JAVA_HOME/jre
# create dcm4chee user
echo "Creating $USER user..."
useradd --shell=/bin/bash --create-home $USER
# switch user (su) to $USER. All command between EOF are run as $USER user
su - $USER <<EOF
cd ${ROOT_DIR}
echo "Downloading dcm4chee $DCM4CHEE_NAME..."
wget -nv "http://sourceforge.net/projects/dcm4che/files/dcm4chee/2.17.1/$DCM4CHEE_NAME.zip"
if [ -d "$INSTALL" ]; then
rm -rf $INSTALL
fi
unzip ${DCM4CHEE_NAME}.zip > /dev/null
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-4.2.3.GA/${JBOSS}.zip"
unzip ${JBOSS}.zip > /dev/null
rm ${JBOSS}.zip
# Copy files form JBoss to dcm4chee
${INSTALL}/bin/install_jboss.sh $ROOT_DIR/${JBOSS} > /dev/null
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.2/weasis.war"
wget -nv "http://sourceforge.net/projects/dcm4che/files/Weasis/weasis-pacs-connector/4.0.0/weasis-pacs-connector.war"
wget -nv "http://sourceforge.net/projects/dcm4che/files/Weasis/weasis-pacs-connector/4.0.0/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
# Switch to posgres user...NOTE: posgres is postgresql default superuser
su - postgres <<EOF
export PGUSER=postgres
# Create the pacsdb
echo "Creating pacsdb database for dcm4chee..."
createdb pacsdb
psql pacsdb -f ${INSTALL}/sql/create.psql > /dev/null
# Configure postgres user (roll)
echo "Configuring postgres user ($USER) with appropriate permissions..."
psql -c "CREATE USER $USER WITH SUPERUSER;"
psql -c "GRANT ALL PRIVILEGES ON DATABASE pacsdb TO $USER;"
psql -c "ALTER USER $USER 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>$USER</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 $USER 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"
@gunlock
Copy link
Author

gunlock commented Aug 20, 2014

Usage

sudo ./dcm4chee_install.sh -u USER_HERE -p PASSWORD_HERE

Notes

  • Limited to JBoss 4.2.3.GA based on dmc4chee requirements.
  • Script arguments: The scripts creates a system user and postgres superuser using the username supplied as script argument. The password is only used for the postgres superuser...and not the system user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment