ft@1: #!/bin/sh ft@1: ft@27: # ------------------------------------------------------------ ft@27: # opensecurity package file ft@27: # ft@27: # Autor: X-Net Services GmbH ft@27: # ft@27: # Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology ft@27: # ft@27: # ft@27: # X-Net Technologies GmbH ft@27: # Elisabethstrasse 1 ft@27: # 4020 Linz ft@27: # AUSTRIA ft@27: # https://www.x-net.at ft@27: # ft@27: # AIT Austrian Institute of Technology ft@27: # Donau City Strasse 1 ft@27: # 1220 Wien ft@27: # AUSTRIA ft@27: # http://www.ait.ac.at ft@27: # ft@27: # ft@27: # Licensed under the Apache License, Version 2.0 (the "License"); ft@27: # you may not use this file except in compliance with the License. ft@27: # You may obtain a copy of the License at ft@27: # ft@27: # http://www.apache.org/licenses/LICENSE-2.0 ft@27: # ft@27: # Unless required by applicable law or agreed to in writing, software ft@27: # distributed under the License is distributed on an "AS IS" BASIS, ft@27: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ft@27: # See the License for the specific language governing permissions and ft@27: # limitations under the License. ft@27: # ------------------------------------------------------------ ft@27: ft@1: BASEDIR="$(dirname $0)" ft@1: DEVICE="$1" ft@1: MOUNTPOINT="$2" ft@1: PASSWORD="$3" ft@1: KEYFILE="$4" ft@1: ft@16: ft@16: getRemoteIp () ft@16: { ft@16: ip_address=$(ifconfig eth0 | grep "inet " | awk '{ print $2 }' | cut -d ":" -f 2) ft@16: ip_netmask=$(ifconfig eth0 | grep "inet " | awk '{ print $4 }' | cut -d ":" -f 2) ft@16: remote_ip=$(ipcalc $ip_address/$ip_netmask | grep HostMin | awk '{ print $2}') ft@16: ft@16: echo $remote_ip ft@16: } ft@16: ft@16: sendInfoNotification () ft@16: { ft@16: MESSAGE="$1" ft@25: wget -q -T 3 -t 1 -O /dev/null "http://$(getRemoteIp):8090/message?msgtype=information&text=$MESSAGE" ft@16: } ft@16: ft@16: sendErrorNotification () ft@16: { ft@16: MESSAGE="$1" ft@17: wget -q -T 3 -t 1 -O /dev/null "http://$(getRemoteIp):8090/notification?msgtype=critical&text=$MESSAGE" ft@16: } ft@16: ft@16: ft@1: if [ -r "$BASEDIR/truecrypt_config.cfg" ] ft@1: then ft@1: . "$BASEDIR/truecrypt_config.cfg" ft@1: else ft@1: echo "truecrypt_config.cfg not found" >&2 ft@1: exit 1 ft@1: fi ft@1: ft@8: # make sure to have "/dev/sdb" (not "/dev/sdb1") ft@15: #DEVICE="${DEVICE:0:8}" the bash way does not work in dash -.- ft@13: DEVICE="$(echo "$DEVICE" | awk '{print substr($1,0,9)}')" ft@8: ft@16: sendInfoNotification "Encrypt device" ft@7: if [ -z "$KEYFILE" ] ft@7: then ft@7: message="$($tc_cmd -c --non-interactive --quick --filesystem=none --encryption=AES --hash=RIPEMD-160 -p "$PASSWORD" "$DEVICE")" ft@7: result="$?" ft@7: else ft@7: message="$($tc_cmd -c --non-interactive --quick --filesystem=none --encryption=AES --hash=RIPEMD-160 -p "$PASSWORD" -k "$KEYFILE" "$DEVICE")" ft@7: result="$?" ft@7: fi ft@16: ft@7: ft@7: if [ "$result" != "0" ] ft@7: then ft@16: sendErrorNotification "Encryption failed" ft@7: exit 1 ft@7: fi ft@1: ft@16: sendInfoNotification "Device encrypted" ft@16: ft@1: ft@1: ft@1: if [ -z "$KEYFILE" ] ft@1: then ft@7: message="$message\n$($tc_cmd --non-interactive --filesystem=none -p "$PASSWORD" "$DEVICE")" ft@7: result="$?" ft@1: else ft@7: message="$message\n$($tc_cmd --non-interactive --filesystem=none -p "$PASSWORD" -k "$KEYFILE" "$DEVICE")" ft@7: result="$?" ft@1: fi ft@1: ft@7: if [ "$result" != "0" ] ft@7: then ft@7: exit 1 ft@7: fi ft@7: ft@7: ft@7: ft@16: sendInfoNotification "Create NTFS filesystem on encrypted device" ft@7: ft@7: TC_DEVICE=$(truecrypt -l | awk '{print $3}') ft@7: ft@7: message="$message\n$(mkfs.ntfs --quick "$TC_DEVICE")" ft@1: result="$?" ft@1: ft@1: if [ "$result" != "0" ] ft@1: then ft@16: sendErrorNotification "Filesystem creation failed" ft@1: exit 1 ft@1: fi ft@1: ft@16: sendInfoNotification "Filesystem successfully created" ft@16: ft@7: mount "$TC_DEVICE" "$MOUNTPOINT" ft@7: ft@33: # Not an Error but the User should click away this message ft@33: sendErrorNotification "Stick is now initialized" ft@16: ft@1: echo "$message" ft@33: exit 0