Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
freedombone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Context Sensitive Group
freedombone
Commits
ff48df3d
Commit
ff48df3d
authored
7 years ago
by
Bob Mottram
Browse files
Options
Downloads
Patches
Plain Diff
Tidying
parent
127d6431
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/freedombone-keydrive
+127
-127
127 additions, 127 deletions
src/freedombone-keydrive
with
127 additions
and
127 deletions
src/freedombone-keydrive
+
127
−
127
View file @
ff48df3d
...
...
@@ -13,7 +13,7 @@
# License
# =======
#
# Copyright (C) 2015-201
6
Bob Mottram <bob@freedombone.net>
# Copyright (C) 2015-201
7
Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
...
...
@@ -50,41 +50,41 @@ function show_help {
while
[[
$#
>
1
]]
do
key
=
"
$1
"
case
$key
in
-h
|
--help
)
show_help
;;
-u
|
--user
)
shift
MY_USERNAME
=
"
$1
"
;;
-d
|
--dev
)
shift
if
[[
"
${
1
}
"
!=
'/dev/'
*
]]
;
then
USB_DRIVE
=
/dev/
${
1
}
1
else
USB_DRIVE
=
${
1
}
fi
;;
-m
|
--master
)
shift
MASTER_DRIVE
=
"
$1
"
;;
-n
|
--fragments
)
key
=
"
$1
"
case
$key
in
-h
|
--help
)
show_help
;;
-u
|
--user
)
shift
MY_USERNAME
=
"
$1
"
;;
-d
|
--dev
)
shift
if
[[
"
${
1
}
"
!=
'/dev/'
*
]]
;
then
USB_DRIVE
=
/dev/
${
1
}
1
else
USB_DRIVE
=
${
1
}
fi
;;
-m
|
--master
)
shift
MASTER_DRIVE
=
"
$1
"
;;
-n
|
--fragments
)
shift
KEY_FRAGMENTS
=
$1
;;
-f
|
--format
)
shift
FORMAT
=
"yes"
;;
*
)
# unknown option
;;
esac
shift
KEY_FRAGMENTS
=
$1
;;
-f
|
--format
)
shift
FORMAT
=
"yes"
;;
*
)
# unknown option
;;
esac
shift
done
if
[
!
$MY_USERNAME
]
;
then
...
...
@@ -98,118 +98,118 @@ if [ ! -d /home/$MY_USERNAME ]; then
fi
if
[
!
-b
$USB_DRIVE
]
;
then
echo
$'Please attach a USB drive'
exit
65743
echo
$'Please attach a USB drive'
exit
65743
fi
umount
-f
$USB_MOUNT
if
[
!
-d
$USB_MOUNT
]
;
then
mkdir
$USB_MOUNT
mkdir
$USB_MOUNT
fi
if
[
-f
/dev/mapper/encrypted_usb
]
;
then
rm
-rf
/dev/mapper/encrypted_usb
rm
-rf
/dev/mapper/encrypted_usb
fi
cryptsetup luksClose encrypted_usb
# optionally format the drive
if
[[
$FORMAT
==
"yes"
]]
;
then
${
PROJECT_NAME
}
-format
${
USB_DRIVE
::-1
}
if
[
!
"
$?
"
=
"0"
]
;
then
exit
36823
fi
${
PROJECT_NAME
}
-format
${
USB_DRIVE
::-1
}
if
[
!
"
$?
"
=
"0"
]
;
then
exit
36823
fi
fi
cryptsetup luksOpen
$USB_DRIVE
encrypted_usb
if
[
"
$?
"
=
"0"
]
;
then
USB_DRIVE
=
/dev/mapper/encrypted_usb
USB_DRIVE
=
/dev/mapper/encrypted_usb
fi
mount
$USB_DRIVE
$USB_MOUNT
if
[
!
"
$?
"
=
"0"
]
;
then
echo
$"There was a problem mounting the USB drive to
$USB_MOUNT
"
rm
-rf
$USB_MOUNT
exit
78543
echo
$"There was a problem mounting the USB drive to
$USB_MOUNT
"
rm
-rf
$USB_MOUNT
exit
78543
fi
# optionally create a master drive which contains the full GPG keyring
if
[[
$MASTER_DRIVE
==
"yes"
||
$MASTER_DRIVE
==
"y"
||
$MASTER_DRIVE
==
"1"
]]
;
then
if
[
!
-d
/home/
$MY_USERNAME
/.gnupg
]
;
then
echo
$"No .gnupg directory was found for
$MY_USERNAME
"
umount
-f
$USB_MOUNT
rm
-rf
$USB_MOUNT
exit
73025
fi
# export the gpg key and backup key as text
# so that it may be imported at the beginning of new installs
GPG_TTY
=
$(
tty
)
export
GPG_TTY
USER_EMAIL_ADDRESS
=
$MY_USERNAME
@
$HOSTNAME
GPG_ID
=
$(
su
-m
root
-c
"gpg --list-keys
$USER_EMAIL_ADDRESS
| sed -n '2p' | sed 's/^[
\t
]*//'"
-
$MY_USERNAME
)
GPG_BACKUP_ID
=
$(
su
-m
root
-c
"gpg --list-keys
\"
(backup key)
\"
| sed -n '2p' | sed 's/^[
\t
]*//'"
-
$MY_USERNAME
)
gpgerrstr
=
$'error'
gpgkey
=
$(
gpg
--homedir
=
/home/
$MY_USERNAME
/.gnupg
--armor
--export
$GPG_ID
)
if
[[
"
$gpgkey
"
==
*
"
$gpgerrstr
"
*
]]
;
then
echo
$'Problem exporting public gpg key'
echo
"
$gpgkey
"
exit
735282
fi
echo
''
echo
$'Enter your gpg private key passphrase:'
gpgprivkey
=
$(
gpg
--homedir
=
/home/
$MY_USERNAME
/.gnupg
--armor
--export-secret-key
$GPG_ID
)
if
[[
"
$gpgprivkey
"
==
*
"
$gpgerrstr
"
*
]]
;
then
echo
$'Problem exporting private gpg key'
echo
"
$gpgprivkey
"
gpgprivkey
=
exit
629362
fi
# Dummy password to get around not being able to create a key without passphrase
BACKUP_DUMMY_PASSWORD
=
'backup'
backupgpgkey
=
$(
gpg
--homedir
=
/home/
$MY_USERNAME
/.gnupg
--armor
--export
$GPG_BACKUP_ID
)
if
[[
"
$backupgpgkey
"
==
*
"
$gpgerrstr
"
*
]]
;
then
echo
$'Problem exporting public gpg backup key'
echo
"
$backupgpgkey
"
exit
735282
fi
backupgpgprivkey
=
$(
echo
"
$BACKUP_DUMMY_PASSWORD
"
| gpg
--batch
--passphrase-fd
0
--homedir
=
/home/
$MY_USERNAME
/.gnupg
--armor
--export-secret-key
$GPG_BACKUP_ID
)
if
[[
"
$backupgpgprivkey
"
==
*
"
$gpgerrstr
"
*
]]
;
then
echo
$'Problem exporting private gpg backup key'
echo
"
$backupgpgprivkey
"
backupgpgprivkey
=
exit
629362
fi
echo
"
$gpgkey
"
>
$USB_MOUNT
/.mastergpgkey
echo
"
$gpgprivkey
"
>>
$USB_MOUNT
/.mastergpgkey
echo
"
$backupgpgkey
"
>
$USB_MOUNT
/.backupgpgkey
echo
"
$backupgpgprivkey
"
>>
$USB_MOUNT
/.backupgpgkey
cp
-rf
/home/
$MY_USERNAME
/.gnupg
$USB_MOUNT
if
[
-d
/etc/letsencrypt
]
;
then
cp
-rf
/etc/letsencrypt
$USB_MOUNT
echo
$"LetsEncrypt keys copied to
$USB_DRIVE
"
fi
if
[
-d
$USB_MOUNT
/.gnupg
]
;
then
echo
$"GPG Keyring copied to
$USB_DRIVE
. You may now remove the drive."
else
echo
$"Unable to copy gpg keyring to
$USB_DRIVE
"
fi
umount
-f
$USB_MOUNT
rm
-rf
$USB_MOUNT
exit
0
if
[
!
-d
/home/
$MY_USERNAME
/.gnupg
]
;
then
echo
$"No .gnupg directory was found for
$MY_USERNAME
"
umount
-f
$USB_MOUNT
rm
-rf
$USB_MOUNT
exit
73025
fi
# export the gpg key and backup key as text
# so that it may be imported at the beginning of new installs
GPG_TTY
=
$(
tty
)
export
GPG_TTY
USER_EMAIL_ADDRESS
=
$MY_USERNAME
@
$HOSTNAME
GPG_ID
=
$(
su
-m
root
-c
"gpg --list-keys
$USER_EMAIL_ADDRESS
| sed -n '2p' | sed 's/^[
\t
]*//'"
-
$MY_USERNAME
)
GPG_BACKUP_ID
=
$(
su
-m
root
-c
"gpg --list-keys
\"
(backup key)
\"
| sed -n '2p' | sed 's/^[
\t
]*//'"
-
$MY_USERNAME
)
gpgerrstr
=
$'error'
gpgkey
=
$(
gpg
--homedir
=
/home/
$MY_USERNAME
/.gnupg
--armor
--export
$GPG_ID
)
if
[[
"
$gpgkey
"
==
*
"
$gpgerrstr
"
*
]]
;
then
echo
$'Problem exporting public gpg key'
echo
"
$gpgkey
"
exit
735282
fi
echo
''
echo
$'Enter your gpg private key passphrase:'
gpgprivkey
=
$(
gpg
--homedir
=
/home/
$MY_USERNAME
/.gnupg
--armor
--export-secret-key
$GPG_ID
)
if
[[
"
$gpgprivkey
"
==
*
"
$gpgerrstr
"
*
]]
;
then
echo
$'Problem exporting private gpg key'
echo
"
$gpgprivkey
"
gpgprivkey
=
exit
629362
fi
# Dummy password to get around not being able to create a key without passphrase
BACKUP_DUMMY_PASSWORD
=
'backup'
backupgpgkey
=
$(
gpg
--homedir
=
/home/
$MY_USERNAME
/.gnupg
--armor
--export
$GPG_BACKUP_ID
)
if
[[
"
$backupgpgkey
"
==
*
"
$gpgerrstr
"
*
]]
;
then
echo
$'Problem exporting public gpg backup key'
echo
"
$backupgpgkey
"
exit
735282
fi
backupgpgprivkey
=
$(
echo
"
$BACKUP_DUMMY_PASSWORD
"
| gpg
--batch
--passphrase-fd
0
--homedir
=
/home/
$MY_USERNAME
/.gnupg
--armor
--export-secret-key
$GPG_BACKUP_ID
)
if
[[
"
$backupgpgprivkey
"
==
*
"
$gpgerrstr
"
*
]]
;
then
echo
$'Problem exporting private gpg backup key'
echo
"
$backupgpgprivkey
"
backupgpgprivkey
=
exit
629362
fi
echo
"
$gpgkey
"
>
$USB_MOUNT
/.mastergpgkey
echo
"
$gpgprivkey
"
>>
$USB_MOUNT
/.mastergpgkey
echo
"
$backupgpgkey
"
>
$USB_MOUNT
/.backupgpgkey
echo
"
$backupgpgprivkey
"
>>
$USB_MOUNT
/.backupgpgkey
cp
-rf
/home/
$MY_USERNAME
/.gnupg
$USB_MOUNT
if
[
-d
/etc/letsencrypt
]
;
then
cp
-rf
/etc/letsencrypt
$USB_MOUNT
echo
$"LetsEncrypt keys copied to
$USB_DRIVE
"
fi
if
[
-d
$USB_MOUNT
/.gnupg
]
;
then
echo
$"GPG Keyring copied to
$USB_DRIVE
. You may now remove the drive."
else
echo
$"Unable to copy gpg keyring to
$USB_DRIVE
"
fi
umount
-f
$USB_MOUNT
rm
-rf
$USB_MOUNT
exit
0
fi
# Don't use the USB drive if it already contains a full keyring
if
[
-d
$USB_MOUNT
/.gnupg
]
;
then
echo
$'A full GPG keyring already exists on the USB drive.'
echo
$'Either reformat the USB drive or use a different drive.'
umount
-f
$USB_MOUNT
rm
-rf
$USB_MOUNT
exit
3392
echo
$'A full GPG keyring already exists on the USB drive.'
echo
$'Either reformat the USB drive or use a different drive.'
umount
-f
$USB_MOUNT
rm
-rf
$USB_MOUNT
exit
3392
fi
# Append the username as a subdirectory.
...
...
@@ -221,14 +221,14 @@ FRAGMENTS_DIR=$FRAGMENTS_DIR/$MY_USERNAME
# make a directory to contain the fragments
if
[
!
-d
$FRAGMENTS_DIR
]
;
then
mkdir
-p
$FRAGMENTS_DIR
echo
$"Made directory
$FRAGMENTS_DIR
"
mkdir
-p
$FRAGMENTS_DIR
echo
$"Made directory
$FRAGMENTS_DIR
"
fi
if
[
!
-d
$FRAGMENTS_DIR
]
;
then
echo
$"There was a problem making the directory
$FRAGMENTS_DIR
"
umount
-f
$USB_MOUNT
rm
-rf
$USB_MOUNT
exit
6843
echo
$"There was a problem making the directory
$FRAGMENTS_DIR
"
umount
-f
$USB_MOUNT
rm
-rf
$USB_MOUNT
exit
6843
fi
cd
$FRAGMENTS_DIR
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment