#!/bin/sh # ----------------------------------------------------------------------------- # TANGO D SANDBOX # ----------------------------------------------------------------------------- # This script allows for a very quick installation of DSSS, DMD, and Tango. The # primary objective is to get an environment setup as quickly as possible with # the option to pick and choose which versions you want to run. The resulting # installation is a completely separate environment from your system one, so # it makes for easy testing of code. Always use the binaries provided in the # environment and never anything in your path, otherwise the code will probably # not compile due to conflicts. # # It is encouraged to use this script to setup multiple sandboxes. Each one is # completely separate from your main system and the other sandboxes. # # Please send any bug reports or suggestions to the email below. # # Author: Sean Kerr a.k.a. feti # Version: 0.4 # ----------------------------------------------------------------------------- # Usage: ./tango_sandbox.sh # ----------------------------------------------------------------------------- # REQUIREMENTS: cut, gcc, grep, sed, svn (optional for SVN access), # tar, unzip, wget, libstdc++5 # ----------------------------------------------------------------------------- # WARNING: This script is meant to run on 32bit Linux installs. If you're # running it on something else, please do not complain that it does # not work. # # WARNING: This script may fail to compile code if one or more libraries are # not compatible with DMD or Tango, or because of a conflict between # the Tango version you chose to install with a particular DMD # version. If this occurs it is completely safe to wipe out the # installation directory and start again with new settings. # ----------------------------------------------------------------------------- # CHANGELOG # 0.2 - Added default options # 0.3 - Fixed installation directory bug with tilde and relative paths # - Added SVN support for tango # 0.4 - Added profile feature # - Added MiniD2 installation option # ----------------------------------------------------------------------------- # base profile (default) profile_base_req_svn=0 profile_base_dsss=0.78 profile_base_dmd=1.033 profile_base_tango=0.99.7 profile_base_tango_svn=n profile_base_tango_rev=latest profile_base_minid_inst=n profile_base_minid_rev=latest # minid profile profile_minid_req_svn=1 profile_minid_dsss=0.78 profile_minid_dmd=1.037 profile_minid_tango= profile_minid_tango_svn=y profile_minid_tango_rev=4048 profile_minid_minid_inst=y profile_minid_minid_rev=latest # tango profile_tango_req_svn=1 profile_tango_dsss=0.78 profile_tango_dmd=1.038 profile_tango_tango=0.99.7 profile_tango_tango_svn=y profile_tango_tango_rev=latest profile_tango_minid_inst=n profile_tango_minid_rev=latest # pick a profile while [ 1 ] ; do echo echo "Please select a profile (default: base)" echo echo "[1] base (defaults: DSSS 0.78, DMD 1.033, Tango 0.99.7)" echo "[2] tango (defaults: DSSS 0.78, DMD 1.038, Tango SVN latest)" echo "[3] minid (defaults: DSSS 0.78, DMD 1.037, Tango SVN r4048, MiniD SVN latest)" echo echo -n "profile: " read profile if [ "$profile" = "2" ] ; then profile=tango break elif [ "$profile" = "3" ] ; then profile=minid break else if [ "$profile" != "" -a "$profile" != "1" ] ; then echo "Invalid profile" else profile=base break fi fi done echo echo "You chose profile $profile" echo # set profile defaults eval "req_svn=\$profile_${profile}_req_svn" eval "dsss=\$profile_${profile}_dsss" eval "dmd=\$profile_${profile}_dmd" eval "tango=\$profile_${profile}_tango" eval "tango_svn=\$profile_${profile}_tango_svn" eval "tango_rev=\$profile_${profile}_tango_rev" eval "minid_inst=\$profile_${profile}_minid_inst" eval "minid_rev=\$profile_${profile}_minid_rev" # make sure profile is valid if [ "$dsss" = "" ] ; then echo "Invalid profile: $profile" exit 1 fi # check for wget if [ "$(which wget)" = "" ] ; then echo "Please install wget and start again" exit 1 fi # check for libstdc++5 if [ "$(ldconfig -p | grep 'libstdc++.so.5')" = "" ] ; then echo "Please install libstdc++5 and start again" exit 1 fi # check for svn if [ "$(which svn)" = "" ] ; then if [ $req_svn -eq 1 ] ; then echo "The profile you chose requires Subversion, so please install it and start again" exit 1 else echo "You do not have SVN installed and all related resources will be skipped" fi svn=0 else svn=1 fi # check for tar if [ "$(which tar)" = "" ] ; then echo "Please install tar and start again" exit 1 fi # check for unzip if [ "$(which unzip)" = "" ] ; then echo "Please install unzip and start again" exit 1 fi # where are we installing? while [ 1 ] ; do echo -n "Please enter an installation directory (no spaces): " read install_dir # check install dir details first="$(echo $install_dir | cut -d/ -f1)" if [ "$first" = "~" ] ; then # need to expand tilde in path install_dir="${HOME}$(echo $install_dir | cut -d~ -f2)" elif [ "$first" != "" ] ; then # relative path install_dir=$(pwd)/$install_dir fi log=$install_dir/install.log if [ ! -e $install_dir ] ; then mkdir $install_dir if [ ! -e $install_dir ] ; then echo "Failed to create installation directory $install_dir" exit 1 fi mkdir $install_dir/bin \ $install_dir/etc \ $install_dir/import \ $install_dir/lib \ $install_dir/src touch $log cd $install_dir/src break fi echo echo "$install_dir already exists -- overwrite?" echo "WARNING: This will delete everything but the src (downloaded files) directory (default: n) [y/n] " read overwrite if [ "$overwrite" = "y" -o "$overwrite" = "Y" ] ; then cd $install_dir for i in *; do if [ "$i" != "src" ] ; then rm -rf $i fi done mkdir $install_dir/bin \ $install_dir/etc \ $install_dir/import \ $install_dir/lib echo -n '' > $log cd src break fi done # which version of dsss would you like? echo -n "Which version of DSSS would you like? (default: $dsss) " read dsss_input if [ "$dsss_input" != "" ] ; then dsss="$dsss_input" fi # which version of dmd would you like? echo -n "Which version of DMD would you like? (default: $dmd) " read dmd_input if [ "$dmd_input" != "" ] ; then dmd="$dmd_input" fi if [ $svn -eq 1 ] ; then # tango svn or standard download echo -n "Would you like to download Tango from SVN instead of standard download? (default: $tango_svn) [y/n] " read tango_svn_input if [ "$tango_svn_input" = "y" -o "$tango_svn_input" = "Y" ] ; then tango_svn=y fi if [ "$tango_svn" = "y" -o "$tango_svn" = "Y" ] ; then # which tango revision do you want? echo -n "Which SVN revision of Tango would you like? (default: $tango_rev) " read tango_rev_input if [ "$tango_rev_input" != "" ] ; then tango_rev="$tango_rev_input" fi fi fi if [ $svn -eq 0 ] || [ "$tango_svn" != "y" -a "$tango_svn" != "Y" ] ; then # which version of tango would you like? echo -n "Which version of Tango would you like? (default: $tango) " read tango_input if [ "$tango_input" != "" ] ; then tango="$tango_input" fi fi # would you like to install minid? echo -n "Would you like to install MiniD? (default: $minid_inst) [y/n] " read minid_inst_input if [ "$minid_inst_input" != "" ] ; then minid_inst="$minid_inst_input" fi if [ "$minid_inst" = "y" -o "$minid_inst" = "Y" ] ; then # which minid revision do you want echo -n "Which SVN revision of MiniD would you like? (default: $minid_rev) " read minid_rev_input if [ "$minid_rev_input" != "" ] ; then minid_rev="$minid_rev_input" fi fi # ----- PRINT INSTALL DETAILS ----- echo echo "Installation Dir: $install_dir" echo "Using profile: $profile" echo "DSSS Version: $dsss" echo "DMD Version: $dmd" if [ "$tango_svn" != "y" -a "$tango_svn" != "Y" ] ; then echo "Tango Version: $tango" else echo "Tango Revision: $tango_rev" fi if [ "$minid_inst" = "y" -o "$minid_inst" = "Y" ] ; then echo "MiniD Revision: $minid_rev" fi echo echo "Press any key to start the installation process, or Ctrl+C to cancel" read _ # ----- GET DSSS ----- cd $install_dir/src if [ -e "dsss-${dsss}-x86-gnuWlinux.tar.bz2" ] ; then dsss_dir="dsss-${dsss}-x86-gnuWlinux" dsss_file="${dsss_dir}.tar.bz2" echo "Using existing DSSS source $dsss_file" elif [ -e "dsss-${dsss}-dmd-gnuWlinux-x86.tar.bz2" ] ; then dsss_dir="dsss-${dsss}-dmd-gnuWlinux-x86" dsss_file="${dsss_dir}.tar.bz2" echo "Using existing DSSS source $dsss_file" else # download dsss echo "Downloading DSSS http://svn.dsource.org/projects/dsss/downloads/${dsss}/dsss-${dsss}-x86-gnuWlinux.tar.bz2" wget -a $log "http://svn.dsource.org/projects/dsss/downloads/${dsss}/dsss-${dsss}-x86-gnuWlinux.tar.bz2" dsss_dir="dsss-${dsss}-x86-gnuWlinux" dsss_file="${dsss_dir}.tar.bz2" if [ ! -e "dsss-${dsss}-x86-gnuWlinux.tar.bz2" ] ; then # try the other dsss format echo "Downloading DSSS http://svn.dsource.org/projects/dsss/downloads/${dsss}/dsss-${dsss}-dmd-gnuWlinux-x86.tar.bz2" wget -a $log "http://svn.dsource.org/projects/dsss/downloads/${dsss}/dsss-${dsss}-dmd-gnuWlinux-x86.tar.bz2" dsss_dir="dsss-${dsss}-dmd-gnuWlinux-x86" dsss_file="${dsss_dir}.tar.bz2" if [ ! -e "dsss-${dsss}-dmd-gnuWlinux-x86.tar.bz2" ] ; then echo echo "ERROR: DSSS failed to download (version may be invalid)" echo "View $log for details" exit 1 fi fi fi # setup dsss rm -rf $dsss_dir >> $log 2>&1 echo "Uncompressing DSSS" tar -vjxf $dsss_file >> $log 2>&1 if [ ! -e "$dsss_dir" ] ; then echo echo "ERROR: $install_dir/src/$dsss_file is corrupt and could not be uncompressed, please remove it and start over" echo "View $log for details" exit 1 fi echo "Copying DSSS files" cd .. cp src/$dsss_dir/bin/dsss bin/ >> $log 2>&1 cp src/$dsss_dir/bin/rebuild bin/ >> $log 2>&1 cp src/$dsss_dir/bin/rebuild_choosedc bin/ >> $log 2>&1 cd bin ln -s rebuild rerun >> $log 2>&1 cd .. cp -r src/$dsss_dir/etc/* etc/ >> $log 2>&1 echo 'profile=dmd-posix-tango' > etc/rebuild/default cd $install_dir/src # ----- GET DMD ----- if [ ! -e "dmd.${dmd}.zip" ] ; then # download dmd echo "Downloading DMD http://ftp.digitalmars.com/dmd.${dmd}.zip" wget -a $log "http://ftp.digitalmars.com/dmd.${dmd}.zip" if [ ! -e "dmd.${dmd}.zip" ] ; then echo echo "ERROR: DMD failed to download (version may be invalid)" echo "View $log for details" exit 1 fi fi # setup dmd rm -rf dmd dm >> $log 2>&1 echo "Uncompressing DMD" unzip -o "dmd.${dmd}.zip" >> $log 2>&1 if [ ! -e "dm" -o ! -e "dmd" ] ; then echo echo "ERROR: $install_dir/src/dmd.${dmd}.zip is corrupt and could not be uncompressed, please remove it and start over" echo "View $log for details" exit 1 fi echo "Copying DMD files" cd .. cp src/dmd/bin/* bin/ >> $log 2>&1 cp src/dmd/lib/* lib/ >> $log 2>&1 rm -f bin/*.dll bin/*.exe bin/*.hlp >> $log 2>&1 chmod +x bin/dmd bin/dumpobj bin/obj2asm bin/rdmd >> $log 2>&1 echo "[Environment]" > bin/dmd.conf echo -n "DFLAGS=-I%@P%/../import -L-L%@P%/../lib -version=Posix -version=Tango -defaultlib=tango-base-dmd -debuglib=tango-base-dmd -L-ltango-user-dmd" >> bin/dmd.conf cat etc/rebuild/dmd-posix-tango | sed -e "s#cmd=dmd#cmd=${install_dir}/bin/dmd#g" -e "s#compiler=dmd#compiler=${install_dir}/bin/dmd#g" -e "s#inifile=dmd.conf#inifile=${install_dir}/bin/dmd.conf#g" > .tmp_file mv .tmp_file etc/rebuild/dmd-posix-tango cd $install_dir/src # ----- GET TANGO ----- if [ "$tango_svn" != "y" -a "$tango_svn" != "Y" ] ; then tango_dir="tango-${tango}-src" if [ ! -e "tango-${tango}-src.zip" ] ; then # download tango echo "Downloading Tango http://downloads.dsource.org/projects/tango/${tango}/tango-${tango}-src.zip" wget -a $log "http://downloads.dsource.org/projects/tango/${tango}/tango-${tango}-src.zip" if [ ! -e "tango-${tango}-src.zip" ] ; then echo echo "ERROR: Tango failed to download (version may be invalid)" echo "View $log for details" exit 1 fi fi # uncompress tango rm -rf "tango-${tango}-src" >> $log 2>&1 echo "Uncompressing Tango" unzip -o "tango-${tango}-src.zip" >> $log 2>&1 if [ ! -e "tango-${tango}-src" ] ; then echo echo "ERROR: $install_dir/src/tango-${tango}-src.zip is corrupt and could not be uncompressed, please remove it and start over" echo "View $log for details" exit 1 fi else tango_dir="tango-svn-${tango_rev}" if [ -e "tango-svn-${tango_rev}" -a "$tango_rev" = "latest" ] ; then rm -rf "tango-svn-${tango_rev}" >> $log 2>&1 fi if [ ! -e "tango-svn-${tango_rev}" ] ; then mkdir "tango-svn-${tango_rev}" >> $log 2>&1 # get tango from svn if [ "$tango_rev" = "latest" ] ; then echo "Downloading Tango from SVN (latest)" svn co http://svn.dsource.org/projects/tango/trunk/ "tango-svn-${tango_rev}"/ >> $log 2>&1 else echo "Downloading Tango from SVN r${tango_rev}" svn co -r "$tango_rev" http://svn.dsource.org/projects/tango/trunk/ "tango-svn-${tango_rev}"/ >> $log 2>&1 fi if [ ! -e "tango-svn-${tango_rev}" ] ; then echo echo "ERROR: Tango failed to download from SVN (revision may be invalid)" echo "View $log for details" exit 1 fi fi fi # setup tango cd .. cd src/"$tango_dir"/lib cat dmd-posix.mak | sed -e "s#DC=dmd#DC=${install_dir}/bin/dmd#g" > .tmp_file mv .tmp_file dmd-posix.mak cat build-tango.sh | sed -e "s#build dmd #build ${install_dir}/bin/dmd #g" > .tmp_file mv .tmp_file build-tango.sh chmod +x build-tango.sh echo "Building Tango" ./build-dmd.sh >> $log 2>&1 ./build-tango.sh dmd >> $log 2>&1 if [ ! -e "../lib/libtango-base-dmd.a" -o ! -e "../lib/libtango-user-dmd.a" ] ; then echo echo "ERROR: Tango failed to build" echo "View $log for details" exit 1 fi echo "Copying Tango files" cd .. cp lib/libtango-base-dmd.a ../../lib/ >> $log 2>&1 cp lib/libtango-user-dmd.a ../../lib/ >> $log 2>&1 cp object.di ../../import/ >> $log 2>&1 cp -r std ../../import/ >> $log 2>&1 cp -r tango ../../import/ >> $log 2>&1 cd $install_dir/src # ----- GET MINID ----- if [ $svn -eq 1 ] && [ "$minid_inst" = "y" -o "$minid_inst" = "Y" ] ; then if [ -e "minid-svn-${minid_rev}" -a "$minid_rev" = "latest" ] ; then rm -rf "minid-svn-${minid_rev}" >> $log 2>&1 fi if [ ! -e "minid-svn-${minid_rev}" ] ; then mkdir "minid-svn-${minid_rev}" >> $log 2>&1 # get minid from svn if [ "$minid_rev" = "latest" ] ; then echo "Downloading MiniD from SVN (latest)" svn co http://svn.dsource.org/projects/minid/trunk/ "minid-svn-${minid_rev}"/ >> $log 2>&1 else echo "Downloading MiniD from SVN r${minid_rev}" svn co -r "$minid_rev" http://svn.dsource.org/projects/minid/trunk/ "minid-svn-${minid_rev}"/ >> $log 2>&1 fi fi if [ ! -e "minid-svn-${minid_rev}" ] ; then echo echo "ERROR: MiniD failed to download from SVN (revision may be invalid)" echo "View $log for details" exit 1 fi # setup minid echo "Building MiniD" cd "minid-svn-${minid_rev}" ../../bin/dsss build >> $log 2>&1 if [ ! -e "libDD-minid.a" ] ; then echo echo "ERROR: MiniD failed to build" echo "View $log for details" exit 1 fi echo "Copying MiniD files" cp libDD-minid.a ../../lib/libminid.a >> $log 2>&1 cp -r minid ../../import/ >> $log 2>&1 cat ../../bin/dmd.conf | sed -e 's#DFLAGS=#DFLAGS=-L-lminid #g' > .tmp_file mv .tmp_file ../../bin/dmd.conf fi # ----- POST-INSTALL TEST FILE ----- cd $install_dir echo "import tango.io.Stdout;" > test.d echo "int main () {" >> test.d echo " Stdout(\"Installation Successful\").newline;" >> test.d echo " return 0;" >> test.d echo "}" >> test.d echo echo "Compiling $install_dir/test.d" bin/dmd test.d >> $log 2>&1 if [ -e "test" ] ; then echo ./test echo echo "View $log for installation details" else echo echo "ERROR: Failed to compile $install_dir/test.d" echo "View $log for details" exit 1 fi