#!/bin/bash # # Copyright (c) 2006 Alexander Panek # # This software is provided 'as-is', without any express or implied warranty. # In no event will the authors be held liable for any damages arising from the # use of this software. # # Permission is granted to anyone to use this software for any purpose, # including commercial applications, and to alter it and redistribute it # freely, subject to the following restrictions: # # 1. The origin of this software must not be misrepresented; you must not claim # that you wrote the original software. If you use this software in a # product, an acknowledgment in the product documentation would be # appreciated but is not required. # # 2. Altered source versions must be plainly marked as such, and must not # be misrepresented as being the original software. # # 3. This notice may not be removed or altered from any source distribution. # DMD_MIRROR=http://ftp.digitalmars.com/dmd.zip MAN_DIR=/usr/share/man/man1 PREFIX=/usr/local NOROOT=0 DMD_DOWNLOAD=0 TANGO_DOWNLOAD=0 die() { echo "$1" exit 0 } usage() { echo 'Usage: install-dmd.sh [OPTIONS]' echo '' echo 'Options:' echo ' --download: Download a fresh copy of DMD and Tango' echo ' --no-root: Do not install man pages, /etc/dmd.conf or any other pieces, that would require root access' echo ' --uninstall: Uninstall Tango and DMD' echo ' --uninstall-tango: Uninstall only Tango and switch back to Phobos' echo ' ' } download_dmd() { echo "Downloading dmd.zip from \"${DMD_MIRROR}\"..." wget ${DMD_MIRROR} || die "Error downloading DMD. Aborting." } download_tango() { } unzip_dmd() { echo "Trying to extract dmd.zip..." if [ ! -f dmd.zip ] then die "Could not find dmd.zip. Please use --download or manually download the file from ${DMD_MIRROR}. Aborting." fi echo " Creating temporary directory ./d..." mkdir d || die 'Could not create temporary directory ./d' echo " Extracting..." unzip -q -d ./d dmd.zip || die 'Could not unzip dmd.zip. Aborting.' } copy_dmd() { echo "Copying compiler binaries..." mkdir -p ${PREFIX}/bin || die cp d/dmd/bin/dmd ${PREFIX}/bin || die cp d/dmd/bin/obj2asm ${PREFIX}/bin || die cp d/dmd/bin/dumpobj ${PREFIX}/bin || die cp d/dmd/bin/rdmd ${PREFIX}/bin || die } copy_doc() { mkdir -p {${PREFIX}/doc/dmd/samples, ${PREFIX}/doc/dmd/src} || die cp d/dmd/html/d/* ${PREFIX}/doc/dmd/ || die cp d/dmd/samples/d/* ${PREFIX}/doc/dmd/samples/ || die cp d/dmd/src/dmd/* ${PREFIX}/dmd/src/ || die } copy_lib() { mkdir -p ${PREFIX}/lib || die cp d/dmd/lib/libphobos.a ${PREFIX}/lib/ || die cp d/dmd/lib/phobos.lib ${PREFIX}/lib/ || die } copy_man() { cp d/dmd/man/man1/* ${MAN_DIR} || die } cleanup() { rm -r d/ || die if [ ${CLEANALL} = 1 ] then rm -r dmd.zip || die fi } for i in $*; do case "$i" in --download-dmd) DMD_DOWNLOAD=1 ;; --download-tango) TANGO_DOWNLOAD=1 ;; --download) DMD_DOWNLOAD=1 TANGO_DOWNLOAD=1 ;; esac done if [ ${DMD_DOWNLOAD} = 1 ] then download_dmd fi if [ ${TANGO_DOWNLOAD} = 1 ] then download_tango fi