dotfiles

config files and scripts at HOME.
git clone git://git.ricketyspace.net/dotfiles.git
Log | Files | Refs

commit b93aced2bb0bc10971f9a9dde643a73fccdf9412
parent 9b991ca6f1fb2b0c5f191406d8ed19afc6b81632
Author: rsiddharth <s@ricketyspace.net>
Date:   Tue,  1 Nov 2016 00:59:51 +0000

Add .bin/create-lo

Diffstat:
.bin/create-lo | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+), 0 deletions(-)

diff --git a/.bin/create-lo b/.bin/create-lo @@ -0,0 +1,69 @@ +#!/usr/bin/zsh +# +# Copyright (C) 2016 rsiddharth <s@ricketyspace.net> +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program (see COPYING). If not, see +# <http://www.gnu.org/licenses/>. + +LO_NAME=$1 +LO_FILE_PATH=$2 +LO_SIZE=$3 # in gigs, minimum is 1 gig. + +[[ -z $LO_NAME ]] && + echo 'ERROR: Name for lo device not given!' && + exit 1 + +[[ -z $LO_FILE_PATH ]] && + echo 'ERROR: File path not given!' && + exit 1 + +[[ -z $LO_SIZE ]] && + echo 'ERROR: File size not given!' && + exit 1 + +# create file +echo 'Creating file' $LO_FILE_PATH '(size' $LO_SIZE 'GB)...Might take a while :|' +((LO_SIZE=$LO_SIZE * 100)) && + dd if=/dev/urandom iflag=fullblock of=$LO_FILE_PATH bs=10M count=$LO_SIZE && + + # get a unused loop device. + LO_DEV=$(losetup -f) && + + # map file to loop device. + echo 'Mapping file to loop device...' && + losetup $LO_DEV $LO_FILE_PATH && + + # encrypt device. + echo 'Encrypting loop device...' && + cryptsetup luksFormat $LO_DEV && + + # open the now encrypted device. + echo 'Opening loop device...' && + cryptsetup open $LO_DEV $LO_NAME && + + # format the device. + echo 'Formatting loop device (ext4)...' && + mkfs.ext4 -L $LO_NAME /dev/mapper/$LO_NAME && + echo 'Finished formatting (ext4)...' && + + # close device. + echo 'Closing device...' && + # close loop back device + cryptsetup close $LO_NAME && + + # detach + echo 'Detaching...' && + LO_DEV=$(losetup -n -O name -j $LO_FILE_PATH) && + losetup -d $LO_DEV && + exit 0