local/bin/homeinit: Support Guix channel support and syncing .gnupg from drive

master
Pierre Neidhardt 2019-05-28 18:25:35 +02:00
parent 9f3d6f501b
commit 7ed117a317
1 changed files with 50 additions and 12 deletions

View File

@ -15,7 +15,7 @@ USER_NAME=Ambrevar
[ -z "$XDG_DATA_HOME" ] && XDG_DATA_HOME="$HOME/.local/share"
[ -z "$EMACS_MIN_VERSION" ] && EMACS_MIN_VERSION=26
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage() {
cat <<EOF>&2
Usage: ${0##*/}
@ -23,7 +23,8 @@ Initialize user profile: install packages, set up folders, etc.
Options:
-u: Skip large updates (packages, emails, etc.)
-g DEVICE: Device where to sync ~/.gnupg.
-u: Skip large updates (packages, emails, etc.)
Environment variables:
@ -37,13 +38,26 @@ Direct link:
${HTTPS_ROOT}ambrevar/dotfiles/raw/master/.local/bin/homeinit
EOF
exit
fi
}
OPT_UPDATE=true
if [ "$1" = "-u" ]; then
OPT_UPDATE=false
shift
fi
OPT_DEVICE=""
while getopts ":hg:u" opt; do
case $opt in
h)
usage
exit ;;
g)
OPT_DEVICE="$OPTARG" ;;
u)
OPT_UPDATE=true ;;
\?)
usage
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
RED='\033[0;31m\033[1m'
GREEN='\033[0;32m\033[1m'
@ -92,13 +106,28 @@ section "Initial packages"
if inpath guix; then
## OpenSSH is not an input of Git, upstream does not want to increase the
## closure size that much.
mkdir "$(dirname "$PROFILE")"
guix package --profile="$PROFILE" --install openssh gnupg git stow password-store pinentry-tty
mkdir -p "$(dirname "$PROFILE")"
guix package --profile="$PROFILE" --install openssh gnupg git stow password-store pinentry-tty pinentry-gtk2 cryptsetup
source "$PROFILE"/etc/profile
elif inpath pacman; then
sudo pacman --noconfirm -S --needed openssh gnupg git stow password-store
fi
if [ ! -d ~/.gnupg ]; then
section "GPG sync"
if [ -n "$OPT_DEVICE" ]; then
section "GnuPG"
sudo cryptsetup open "$OPT_DEVICE" gpg_backup
sudo mount -o compress=zstd /dev/mapper/gpg_backup /mnt
cp -a /mnt/public/.gnupg ~/
sudo umount /mnt
sudo cryptsetup close gpg_backup
else
warning "No device specified."
fi
fi
section "GPG"
if [ -d ~/.gnupg ]; then
ROOT=$SSH_ROOT
@ -169,13 +198,21 @@ if inpath guix; then
git clone https://git.savannah.gnu.org/git/guix.git /tmp/guix
YESTERDAY_COMMIT=$(git -C /tmp/guix log --until=yesterday -n 1 --format=%H)
guix pull --commit=$YESTERDAY_COMMIT
hash guix
unset YESTERDAY_COMMIT
rm -rfv /tmp/guix
rm -rf /tmp/guix
elif $OPT_UPDATE; then
CURRENT_COMMIT=$(guix --version 2>/dev/null | awk '{print $4; exit}')
REPO=$HOME/.cache/guix/pull/"$(ls -1 ~/.cache/guix/pull)"
for i in $HOME/.cache/guix/pull/*; do
if [ "$(git -C "$i" config --get remote.origin.url)" = "https://git.savannah.gnu.org/git/guix.git" ]; then
REPO="$i"
break
fi
done
CURRENT_COMMIT_DATE=$(git -C "$REPO" log -n 1 --format=%ct $CURRENT_COMMIT)
git -C $REPO pull
hash guix
LATEST_COMMIT_DATE=$(git -C "$REPO" log -n 1 --format=%ct)
[ -z "$GUIX_DISTRO_AGE_WARNING" ] && GUIX_DISTRO_AGE_WARNING=$((7 * 24 * 60 * 60))
@ -198,8 +235,9 @@ if inpath guix; then
## TODO: The manifest will uninstall other unspecified packages. Is this
## really what we want?
export GUIX_PACKAGE_PATH=$HOME/.guix-packages
guix package --manifest=$HOME/.package-lists/guix-manifest.scm --keep-failed
~/.config/guix/current/bin/guix package --manifest=$HOME/.package-lists/guix-manifest.scm --keep-failed
. ~/.guix-profile/etc/profile
elif inpath pacman; then
pacman_list=""
if [ -f ~/.package-lists/arch-official ]; then