Last active
August 10, 2017 13:24
-
-
Save Dantali0n/ddd305e9857914df3a5fe7b8d6fd0548 to your computer and use it in GitHub Desktop.
Script to create crypt-luks drives formated in btrfs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# List of commands required for execution of the setup script | |
commandsRequire=("cryptsetup" "dd" "mkfs.btrfs") | |
err11="I require" | |
err12="but it's not installed. Aborting..." | |
mes11="Found" | |
#verify current execution environment has root permission | |
if [ "$EUID" -ne 0 ] | |
then echo "Please run as root" | |
exit | |
fi | |
echo "verifying requirements..."; | |
for i in "${commandsRequire[@]}" | |
do | |
if hash $i 2>/dev/null; then | |
echo >&2 "$mes11 ${i}"; | |
else | |
echo >&2 "$err11 ${i} $err12"; | |
exit 1; | |
fi | |
done | |
if hash apt 2>/dev/null; then | |
apt install btrfs-tools cryptsetup lvm2 | |
fi | |
if hash pacman 2>/dev/null; then | |
pacman -S btrfs-progs cryptsetup lvm2 | |
fi | |
read -p "Specify the name of the device as identified by udev WITHOUT '/dev/' (sda,sdb,mmcblk0 etc..) :" device | |
# Better safe then sorry | |
read -p "Erasing a device cannot be undone are you sure you want to continue? [y]yes / [n]no :" yn | |
case $yn in | |
[Yy]* ) ;; | |
[Nn]* ) exit; ;; | |
* ) echo "Please answer: yes[y] / no[n]";; | |
esac | |
echo "Creating encrypted disc" | |
#cryptsetup -v --cipher aes-xts-plain64 --key-size 512 --hash sha512 --iter-time 5000 --use-urandom --verify-passphrase luksFormat /dev/$device | |
cryptsetup -y -v luksFormat /dev/$device | |
echo "Mounting new disc" | |
cryptsetup luksOpen /dev/$device TEMP_MAP | |
echo "Wiping disc with /dev/zero" | |
dd if=/dev/zero of=/dev/mapper/TEMP_MAP | |
echo "Formating disc with btrfs" | |
mkfs.btrfs /dev/mapper/TEMP_MAP | |
echo "Unmounting disc" | |
cryptsetup luksClose TEMP_MAP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment