truecrypt_init.sh
author ft
Wed, 03 Dec 2014 11:35:21 +0100
changeset 4 9c3105aa50e0
parent 0 28b7682d5476
permissions -rwxr-xr-x
chnaged init sucess message so the user has to click away the message
     1 #!/bin/sh
     2 
     3 # ------------------------------------------------------------
     4 # opensecurity package file
     5 #
     6 # Autor: X-Net Services GmbH <office@x-net.at>
     7 #
     8 # Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology
     9 #
    10 #
    11 #     X-Net Technologies GmbH
    12 #     Elisabethstrasse 1
    13 #     4020 Linz
    14 #     AUSTRIA
    15 #     https://www.x-net.at
    16 #
    17 #     AIT Austrian Institute of Technology
    18 #     Donau City Strasse 1
    19 #     1220 Wien
    20 #     AUSTRIA
    21 #     http://www.ait.ac.at
    22 #
    23 #
    24 # Licensed under the Apache License, Version 2.0 (the "License");
    25 # you may not use this file except in compliance with the License.
    26 # You may obtain a copy of the License at
    27 #
    28 #    http://www.apache.org/licenses/LICENSE-2.0
    29 #
    30 # Unless required by applicable law or agreed to in writing, software
    31 # distributed under the License is distributed on an "AS IS" BASIS,
    32 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    33 # See the License for the specific language governing permissions and
    34 # limitations under the License.
    35 # ------------------------------------------------------------
    36 
    37 BASEDIR="$(dirname $0)"
    38 DEVICE="$1"
    39 MOUNTPOINT="$2"
    40 PASSWORD="$3"
    41 KEYFILE="$4"
    42 
    43 
    44 getRemoteIp ()
    45 {
    46 	ip_address=$(ifconfig eth0 | grep "inet " | awk '{ print $2 }' | cut -d ":" -f 2)
    47 	ip_netmask=$(ifconfig eth0 | grep "inet " | awk '{ print $4 }' | cut -d ":" -f 2)
    48 	remote_ip=$(ipcalc $ip_address/$ip_netmask | grep HostMin | awk '{ print $2}')
    49 
    50 	echo $remote_ip
    51 }
    52 
    53 sendInfoNotification ()
    54 {
    55 	MESSAGE="$1"
    56 	wget -q -T 3 -t 1 -O /dev/null "http://$(getRemoteIp):8090/message?msgtype=information&text=$MESSAGE"
    57 }
    58 
    59 sendErrorNotification ()
    60 {
    61 	MESSAGE="$1"
    62 	wget -q -T 3 -t 1 -O /dev/null "http://$(getRemoteIp):8090/notification?msgtype=critical&text=$MESSAGE"
    63 }
    64 
    65 
    66 if [ -r "$BASEDIR/truecrypt_config.cfg" ]
    67 then
    68 	. "$BASEDIR/truecrypt_config.cfg"
    69 else
    70 	echo "truecrypt_config.cfg not found" >&2
    71 	exit 1
    72 fi
    73 
    74 # make sure to have "/dev/sdb" (not "/dev/sdb1")
    75 #DEVICE="${DEVICE:0:8}" the bash way does not work in dash -.-
    76 DEVICE="$(echo "$DEVICE" | awk '{print substr($1,0,9)}')"
    77 
    78 sendInfoNotification "Encrypt device"
    79 if [ -z "$KEYFILE" ]
    80 then
    81 	message="$($tc_cmd -c --non-interactive --quick --filesystem=none --encryption=AES --hash=RIPEMD-160 -p "$PASSWORD" "$DEVICE")"
    82 	result="$?"
    83 else
    84 	message="$($tc_cmd -c --non-interactive --quick --filesystem=none --encryption=AES --hash=RIPEMD-160 -p "$PASSWORD" -k "$KEYFILE" "$DEVICE")"
    85 	result="$?"
    86 fi
    87 
    88 	
    89 if [ "$result" != "0" ]
    90 then
    91 	sendErrorNotification "Encryption failed"
    92 	exit 1
    93 fi
    94 
    95 sendInfoNotification "Device encrypted"
    96 
    97 
    98 
    99 if [ -z "$KEYFILE" ]
   100 then
   101 	message="$message\n$($tc_cmd --non-interactive --filesystem=none -p "$PASSWORD" "$DEVICE")"
   102 	result="$?"
   103 else
   104 	message="$message\n$($tc_cmd --non-interactive --filesystem=none -p "$PASSWORD" -k "$KEYFILE" "$DEVICE")"
   105 	result="$?"
   106 fi
   107 	
   108 if [ "$result" != "0" ]
   109 then
   110 	exit 1
   111 fi
   112 
   113 
   114 
   115 sendInfoNotification "Create NTFS filesystem on encrypted device"
   116 
   117 TC_DEVICE=$(truecrypt -l | awk '{print $3}')
   118 
   119 message="$message\n$(mkfs.ntfs --quick "$TC_DEVICE")"
   120 result="$?"
   121 
   122 if [ "$result" != "0" ]
   123 then
   124 	sendErrorNotification "Filesystem creation failed"
   125 	exit 1
   126 fi
   127 
   128 sendInfoNotification "Filesystem successfully created"
   129 
   130 mount "$TC_DEVICE" "$MOUNTPOINT" 
   131 
   132 # Not an Error but the User should click away this message
   133 sendErrorNotification "Stick is now initialized"
   134 
   135 echo "$message"
   136 exit 0