All pastes #734003 Raw Edit

Meins

public text v1 · immutable
·published 2007-10-12 08:56 UTC
rendered paste body
#! /bin/bash
#-
#- *** truecrypt installer for debian etch (kernel 2.6.18) ***
#-
#-                   *** Version 0.0.2 ***
#-
#- Copyright (c) 2007, Juergen Heine - sysdef@debiancenter.org
#-
#  --------------------------------------------------------------------------
#  History:
#  version - date       - name      - description
#  0.0.1   - 2007-07-30 - sysdef    - initial, tests and routines
#  0.0.2   - 2007-08-03 - sysdef    - check for root rights, OS and
#                                     add -y to aptitute
#  --------------------------------------------------------------------------
#
#- All rights reserved.
#-
#- Released under BSD License
#-
#- Redistribution and use in source and binary forms, with or without
#- modification, are permitted provided that the following conditions
#- are met:
#-
#- * Redistributions of source code must retain the above copyright notice,
#-   this list of conditions and the following disclaimer.
#- * Redistributions in binary form must reproduce the above copyright notice,
#-   thislist of conditions and the following disclaimer in the documentation
#-   and/or other materials provided with the distribution.
#- * Neither the name of Debian Center Org. nor the names of its contributors
#-   may be used to endorse or promote products derived from this software
#-   without specific prior written permission.
#-
#- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
#- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
#- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
#- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
#- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
#- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
#- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-

[ "$1" == "--license" ] && { grep \^#- $0 | sed s/^#-//; exit; }

# functions
log()  { tee -a $LOG; }
plog() { echo -n ' # '|log; echo -e $@ |log; }
ok()   { echo "done." |log; }
fail() { echo "failed." |log; }

# logging
LOG=$(pwd)/truecrypt.log
echo " ### START INSTALLATION at $(date) ###" |log
echo " ### $(uname -a) ###" |log

# running debian?
[ -f /etc/debian_version ] || {
  echo " # OS is not Debian -> exit" |log
  echo
  echo " This script is written for Debian only!"
  sleep 2
  echo " Don't ask the maintainer for help if you're not using Debian!"
  sleep 3
  echo " ... and NO! Ubuntu or Knoppix is NOT Debian! Don't discuss!"
  rm -v $0
  exit 0
}

# are we root?
[ $UID == 0 ] || {
  echo " # User ${USERNAME} try to start installer" |log
  plog "Failed to get setuid 0 (root rights). Start script as root!"
  exit 0
}

echo -e "\n ***   TrueCrypt Installer for Debian GNU/Linux 4.0 (etch)   ***"
echo      " ***                   with kernel 2.6.18                    ***"
echo -e   " ***   (c) 2007 by Juergen Heine - sysdef@debiancenter.org   ***\n"
echo -e   " *** Released under BSD License, type truecrypt.sh --license ***\n"
sleep 5

# get the system kernel version
KERNEL=$( uname -r )
plog "RUNNING KERNEL == $KERNEL"

# get the packages
plog -n "Install dependencies ... "
aptitude -y install build-essential dmsetup linux-source-$( uname -r | sed s/-.*// ) >>$LOG
ok

# expand linux kernel sources
[ -d /usr/src/linux-source-$( uname -r | sed s/-.*// ) ] || {
  plog -n "Expand linux sources ... "
  cd /usr/src
  tar -xvjf linux-source-$( uname -r|sed s/-.*// ).tar.bz2 >>$LOG 2>&1 && ok || fail
  cd - >/dev/null
}

# get linux version
LINUX_SOURCE=$( basename $( find /usr/src/ -maxdepth 1 -name "linux-source-2.6*" -type d | tail -1 ) )
plog "LINUX_SOURCE == $LINUX_SOURCE"

# set linux link
plog -n
ln -svf /usr/src/linux /usr/src/$LINUX_SOURCE |log

# get kernel GCC version
K_GCC_L=$( cat /proc/version | grep -o "gcc version [^ ]*" | cut -d \  -f 3 )
plog "KERNEL GCC LONG VERSION == $K_GCC_L"
K_GCC_S=$( cat /proc/version | grep -o "gcc version [^ ]*" | cut -d \  -f 3 | cut -d . -f 1,2 )
plog "KERNEL GCC SHORT VERSION == $K_GCC_S"

# if kernel GCC version NOT installed, install it
[ $(dpkg -l | grep gcc | grep -c $K_GCC_S) ] && {
  plog "KERNEL GCC VERSION is installed"
} || {
  plog "KERNEL GCC VERSION is NOT installed"
  aptitude install gcc-${K_GCC_S} gcc-${K_GCC_S}-base >>$LOG
}

# save old gcc link
[ -h gcc.sik ] || {
  plog -n
  cp -Rvp /usr/bin/gcc gcc.sik |log
} && {
  plog "WARNING: gcc link already saved (interrupted installation?)"
}

# set link to kernel gcc
plog -n
ln -sfv /usr/bin/gcc-${K_GCC_S} /usr/bin/gcc |log

# get VER(sion) from truecrypt site
VER_T=$( wget -qO- http://www.truecrypt.org/downloads.php | grep "Latest Stable Version - " | sed 's/ //g;s/.*-//;s/<.*//' )
plog "VERSION FROM Truecrypt.org == $VER_T"

# get VER(sion) from wikipedia
VER_W=$( wget -qO- http://de.wikipedia.org/wiki/TrueCrypt?action=raw| grep "|AktuelleVersion=.*" | sed 's/ //g;s/.*=//' )
plog "VERSION FROM Wikipedia.org == $VER_W"

[ -f truecrypt-*-source-code.tar.gz ] && {
  VER=$( ls truecrypt-*-source-code.tar.gz | cut -d - -f 2 )
  plog "Version ${VER} is already downloaded"
} || {
  [ "$VER_T" == "$VER_W" ] && {
    plog "Version informations are equal"
    plog -n "Downloading truecrypt-${VER_T}-source-code ... "
    wget -O truecrypt-${VER_T}-source-code.tar.gz http://www.truecrypt.org/downloads/truecrypt-${VER_T}-source-code.tar.gz >>$LOG 2>&1 && ok
    VER=$VER_T
  } || {
    plog "WARNING: Version informations are NOT equal"
    plog -n "Try to download truecrypt-${VER_T}-source-code ... "
    wget -O truecrypt-${VER_T}-source-code.tar.gz http://www.truecrypt.org/downloads/truecrypt-${VER_T}-source-code.tar.gz >>$LOG 2>&1 && {
      VER=$VER_T
      ok
    } || {
      fail
    }
    plog -n "Try to download truecrypt-${VER_W}-source-code ... "
    wget -O truecrypt-${VER_W}-source-code.tar.gz http://www.truecrypt.org/downloads/truecrypt-${VER_W}-source-code.tar.gz >>$LOG 2>&1 && {
      VER=$VER_W
      ok
    } || {
      fail
    }
    [ "$VER" == "$VER_T" ] && plog "The TrueCrypt Site information (Version ${VER_T}) was right"
    [ "$VER" == "$VER_W" ] && plog "The Wikipedia Site information (Version ${VER_W}) was right"
  }
}

# extract archive
[ -d truecrypt-${VER}-source-code ] && {
  plog "Archive is allready extracted"
} || {
  plog -n "extract archive ... "
  tar xvzf truecrypt-${VER}-source-code.tar.gz >>$LOG 2>&1 && ok

  # kernel >= 2.6.18
  plog -n "Patch sources ... "
  wget -O Linux_gt_eq_2.6.18.diff http://privat.heinzelzwerg.de/howtos/debian/truecrypt/Linux_gt_eq_2.6.18.diff >>$LOG 2>&1
  patch truecrypt-${VER}-source-code/Linux/Kernel/Dm-target.c Linux_gt_eq_2.6.18.diff >>$LOG 2>&1 && {
    ok
  } || {
    fail
    exit
  }
}

cd truecrypt-${VER}-source-code/Linux/
./Cli/truecrypt --help >/dev/null 2>&1 && {
  plog "truecrypt is already build"
} || {
  echo "Y" | ./build.sh |log && {
    ok
  } || {
    fail
    exit
  }
}

truecrypt --help >/dev/null && {
  plog "WARNING: truecrypt is already installed"
} || {
  echo -e "\n\n\nY" | ./install.sh >/dev/null 2>&1 && {
    ok
  } || {
    fail
    exit
  }
}

# restore old gcc link
[ -h gcc.sik ] && {
  plog -n
  cp -Rvp gcc.sik /usr/bin/gcc |log
  plog -n
  rm -v gcc.sik |log
} || {
  plog "WARNING: can't find saved gcc link"
}

# status
truecrypt --help >/dev/null && {
  plog "Version Informations: ...\n\n"
  truecrypt --version |log
  echo -e " ### END SUCCESSFULL INSTALLATION at $(date) ###\n" >>$LOG
  exit 1;
} || {
  plog "ERROR: truecrypt is NOT installed. See logfile for details"
  echo " ### END FAILED INSTALLATION at $(date) ###\n" >>$LOG
  exit 0;
}

# EOF