mirror of
https://github.com/kevinveenbirkenbach/linux-image-manager.git
synced 2024-11-26 00:41:04 +01:00
Finished automatic mount draft
This commit is contained in:
parent
a03a4adc96
commit
596aea41cb
@ -1,11 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
source "$(dirname "$(readlink -f "${0}")")/../../base.sh" || (echo "Loading base.sh failed." && exit 1)
|
source "$(dirname "$(readlink -f "${0}")")/../../base.sh" || (echo "Loading base.sh failed." && exit 1)
|
||||||
|
|
||||||
set_device_mount_and_mapper_paths(){
|
set_device_mount_partition_and_mapper_paths(){
|
||||||
set_device_path &&
|
set_device_path &&
|
||||||
mapper_name="encrypteddrive-$device" &&
|
mapper_name="encrypteddrive-$device" &&
|
||||||
mapper_path="/dev/mapper/$mapper_name" &&
|
mapper_path="/dev/mapper/$mapper_name" &&
|
||||||
mount_path="/media/$mapper_name" &&
|
mount_path="/media/$mapper_name" &&
|
||||||
|
partition_path="$device_path""1" &&
|
||||||
info "mapper name set to : $mapper_name" &&
|
info "mapper name set to : $mapper_name" &&
|
||||||
info "mapper path set to : $mapper_path" ||
|
info "mapper path set to : $mapper_path" ||
|
||||||
info "mount path set to : $mount_path" ||
|
info "mount path set to : $mount_path" ||
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
|
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
|
||||||
echo "Mounts encrypted storages"
|
echo "Mounts encrypted storages"
|
||||||
|
|
||||||
set_device_mount_and_mapper_paths
|
set_device_mount_partition_and_mapper_paths
|
||||||
|
|
||||||
partition_path="$device_path""1"
|
|
||||||
info "Unlock partition..." &&
|
info "Unlock partition..." &&
|
||||||
sudo cryptsetup luksOpen $partition_path $mapper_name ||
|
sudo cryptsetup luksOpen $partition_path $mapper_name ||
|
||||||
error
|
error
|
||||||
|
@ -2,44 +2,69 @@
|
|||||||
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
|
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
|
||||||
echo "Automount encrypted storages"
|
echo "Automount encrypted storages"
|
||||||
echo
|
echo
|
||||||
set_device_mount_and_mapper_paths
|
set_device_mount_partition_and_mapper_paths
|
||||||
|
|
||||||
secret_key_path="/etc/luks-keys/$mapper""_name_secret_key" &&
|
info "Creating key luks-key-directory..." &&
|
||||||
|
key_directory="/etc/luks-keys/" &&
|
||||||
|
sudo mkdir $key_directory || warning "Directory exists: $key_directory"
|
||||||
|
luks_key_name="$mapper_name""_name_secret_key" &&
|
||||||
|
secret_key_path="$key_directory$luks_key_name" &&
|
||||||
info "Generate secret key under: $secret_key_path" &&
|
info "Generate secret key under: $secret_key_path" &&
|
||||||
dd if=/dev/urandom of=$secret_key_path bs=512 count=8 &&
|
if [ -f "$secret_key_path" ]
|
||||||
sudo cryptsetup -v luksAddKey $device_path $secret_key_path ||
|
then
|
||||||
|
warning "File allready exist. Overwritting!"
|
||||||
|
fi
|
||||||
|
sudo dd if=/dev/urandom of=$secret_key_path bs=512 count=8 &&
|
||||||
|
sudo cryptsetup -v luksAddKey $partition_path $secret_key_path ||
|
||||||
error
|
error
|
||||||
|
|
||||||
info "Opening and closing device to verify that that everything works fine..." &&
|
info "Opening and closing device to verify that that everything works fine..." &&
|
||||||
sudo cryptsetup -v luksOpen $device_path $mapper_name --key-file=$secret_key_path &&
|
sudo cryptsetup -v luksOpen $partition_path $mapper_name --key-file=$secret_key_path &&
|
||||||
sudo cryptsetup -v luksClose $mapper_name ||
|
sudo cryptsetup -v luksClose $mapper_name ||
|
||||||
error
|
error
|
||||||
|
|
||||||
uuid_line=$(sudo cryptsetup luksDump $device_path | grep "UUID")
|
info "Reading UUID..."
|
||||||
uuid=$(uuid_line "${test/UUID:/""}"|sed -e "s/[[:space:]]\+//g")
|
uuid_line=$(sudo cryptsetup luksDump $partition_path | grep "UUID") &&
|
||||||
crypttab_path="/etc/crypttab"
|
uuid=$(echo "${uuid_line/UUID:/""}"|sed -e "s/[[:space:]]\+//g") ||
|
||||||
if grep -q "$uuid" "$crypttab_path"; then
|
error
|
||||||
error "File $crypttab_path contains allready a string with the UUID:$uuid"
|
|
||||||
fi
|
|
||||||
"$mapper_name UUID=$uuid $secret_key_path luks" >> $crypttab_path
|
|
||||||
|
|
||||||
info "The file $crypttab_path contains the following:" &&
|
crypttab_path="/etc/crypttab"
|
||||||
|
crypttab_entry="$mapper_name UUID=$uuid $secret_key_path luks"
|
||||||
|
info "Adding crypttab entry..."
|
||||||
|
if sudo grep -q "$crypttab_entry" "$crypttab_path";
|
||||||
|
then
|
||||||
|
warning "File $crypttab_path contains allready a the following entry:" &&
|
||||||
|
echo "$crypttab_entry" &&
|
||||||
|
info "Skipped." ||
|
||||||
|
error
|
||||||
|
else
|
||||||
|
sudo sh -c "echo '$crypttab_entry' >> $crypttab_path" ||
|
||||||
|
error
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "The file $crypttab_path contains now the following:" &&
|
||||||
sudo cat $crypttab_path ||
|
sudo cat $crypttab_path ||
|
||||||
error
|
error
|
||||||
|
|
||||||
info "Verifying crypttab configuration..." &&
|
# info "Verifying crypttab configuration..." &&
|
||||||
sudo cryptdisks_start $mapper_name ||
|
# sudo cryptdisks_start $mapper_name ||
|
||||||
error
|
# error
|
||||||
|
|
||||||
fstab_path="/etc/fstab"
|
fstab_path="/etc/fstab"
|
||||||
if grep -q "$uuid" "f$stab_path"; then
|
fstab_entry="$mapper_path $mount_path btrfs defaults 0 2"
|
||||||
error "File $fstab_path contains allready a string with the UUID:$uuid"
|
info "Adding fstab entry..."
|
||||||
|
if sudo grep -q "$fstab_entry" "$fstab_path"; then
|
||||||
|
warning "File $crypttab_path contains allready a the following entry:" &&
|
||||||
|
echo "$fstab_entry" &&
|
||||||
|
info "Skipped." ||
|
||||||
|
error
|
||||||
|
else
|
||||||
|
sudo sh -c "echo '$fstab_entry' >> $fstab_path" ||
|
||||||
|
error
|
||||||
fi
|
fi
|
||||||
"$mapper_path $mount_path btrfs defaults 0 2" >> $fstab_path ||
|
|
||||||
error
|
|
||||||
|
|
||||||
info "The file $crypttab_path contains the following:" &&
|
info "The file $fstab_path contains now the following:" &&
|
||||||
sudo cat $crypttab_path ||
|
sudo cat $fstab_path ||
|
||||||
error
|
error
|
||||||
|
|
||||||
success "Installation finished. Please restart :)"
|
success "Installation finished. Please restart :)"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
|
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
|
||||||
echo "Setups disk encryption"
|
echo "Setups disk encryption"
|
||||||
|
|
||||||
set_device_mount_and_mapper_paths
|
set_device_mount_partition_and_mapper_paths
|
||||||
|
|
||||||
overwritte_device_with_zeros
|
overwritte_device_with_zeros
|
||||||
|
|
||||||
@ -21,7 +21,6 @@ info "Creating partition table..."
|
|||||||
)| sudo fdisk --wipe always "$device_path" ||
|
)| sudo fdisk --wipe always "$device_path" ||
|
||||||
error
|
error
|
||||||
|
|
||||||
partition_path="$device_path""1"
|
|
||||||
info "Encrypt $device_path..." &&
|
info "Encrypt $device_path..." &&
|
||||||
sudo cryptsetup -v -y luksFormat $partition_path ||
|
sudo cryptsetup -v -y luksFormat $partition_path ||
|
||||||
error
|
error
|
||||||
@ -43,3 +42,5 @@ error
|
|||||||
info "Own partition by user..." &&
|
info "Own partition by user..." &&
|
||||||
sudo chown -R $USER:$USER $mount_path ||
|
sudo chown -R $USER:$USER $mount_path ||
|
||||||
error
|
error
|
||||||
|
|
||||||
|
success "Encryption successfull :)"
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
|
||||||
|
echo "Unmount encrypted storages"
|
||||||
|
|
||||||
|
set_device_mount_partition_and_mapper_paths
|
||||||
|
|
||||||
|
info "Unmount $mapper_path..."
|
||||||
|
sudo umount $mapper_path &&
|
||||||
|
sudo cryptsetup luksClose $mapper_path ||
|
||||||
|
error
|
||||||
|
|
||||||
|
success "Successfull :)"
|
Loading…
Reference in New Issue
Block a user