local/bin/homeinit: Fix gpg init, factor ROOT variables

master
Pierre Neidhardt 2019-01-19 18:39:26 +01:00
parent 3f7e903ac7
commit 9d760d3013
1 changed files with 43 additions and 19 deletions

View File

@ -1,5 +1,17 @@
#!/bin/sh
# TODO: Make "command -v " wrapper with support for multiple arguments.
# TODO: Create a separate profile in /tmp to install gnupg, git, etc. then delete it when it's over.
# TODO: Run guix pull if OPT_UPDATE and if guix chekout is more than some days old, as specified by an environment variable.
# TODO: Guix pull on commit specified in package-lists/guix-version?
# TODO: On foreign distro, use local package manager to install Guix. (Start with pacman.)
# TODO: Test if TTY and set pinentry appropriately without clobbering
# ~/.gnupg/gpg-agent.conf
HTTPS_ROOT=https://gitlab.com/
SSH_ROOT=git@gitlab.com:
ROOT=$HTTPS_ROOT
[ -z "$SOURCEDIR" ] && SOURCEDIR="$HOME/personal"
[ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
[ -z "$XDG_DATA_HOME" ] && XDG_DATA_HOME="$HOME/.local/share"
@ -9,7 +21,7 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
cat <<EOF>&2
Usage: ${0##*/}
Initialize home folder.
Initialize user profile: install packages, set up folders, etc.
Options:
@ -24,7 +36,7 @@ Environment variables:
Direct link:
https://gitlab.com/ambrevar/dotfiles/raw/master/.local/bin/homeinit
${HTTPS_ROOT}ambrevar/dotfiles/raw/master/.local/bin/homeinit
EOF
exit
fi
@ -64,28 +76,34 @@ lnn() { # $1=TARGET $2=LINK|FOLDER
}
################################################################################
#
section "Initial packages"
if command -v guix >/dev/null 2>&1; then
guix package --install gnupg git stow password-store
## TODO: Should openssh be an input of Git?
guix package --install openssh gnupg git stow password-store
elif command -v pacman >/dev/null 2>&1; then
sudo pacman --noconfirm -S --needed gnupg git stow password-store
sudo pacman --noconfirm -S --needed openssh gnupg git stow password-store
fi
section "GPG"
if [ -d ~/.gnupg ]; then
ROOT=$SSH_ROOT
## Set up gpg-agent to authenticate to SSH_ROOT.
chmod go-rwx ~/.gnupg ~/.gnupg/*
## TODO: Got to start gpg-agent first?
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
guix package -i pinentry-tty
gpg-connect-agent updatestartuptty /bye
if [ -e "$SOURCEDIR" ]; then
git -C "$SOURCEDIR" pull
else
git clone git@gitlab.com:Ambrevar/personal
git clone ${SSH_ROOT}Ambrevar/personal
fi
if [ -e ~/.password-store ]; then
git -C ~/.password-store pull
else
git clone git@gitlab.com:Ambrevar/password-store ~/.password-store
git clone ${SSH_ROOT}Ambrevar/password-store ~/.password-store
## The following is necessary to make sure the 'diff' GPG filter is properly set up.
pass git init
fi
@ -100,21 +118,23 @@ done
section "dotfiles"
if [ -e ~/dotfiles ]; then
git -C ~/dotfiles remote set-url origin git@gitlab.com:Ambrevar/dotfiles
git -C ~/dotfiles remote set-url origin ${ROOT}Ambrevar/dotfiles
git -C ~/dotfiles pull
else
git clone git@gitlab.com:Ambrevar/dotfiles
git clone ${ROOT}Ambrevar/dotfiles
fi
pushd ~/dotfiles
stow -v .
## .bash_profile may prevent .profile from being parsed, so we remove it.
[ -e ~/.bash_profile ] && mv -v ~/.bash_profile ~/.bash_profile.old
stow -v . || exit 1
popd
section "System packages"
if command -v guix >/dev/null 2>&1; then
## TODO: The manifest will uninstall other unspecified packages. Is this
## really what we want?
guix package --manifest=~/.package-lists/guix
## TODO: Delete setup generation (gnupg, git, stow)?
export GUIX_PACKAGE_PATH=$HOME/.guix-packages
guix package --manifest=$HOME/.package-lists/guix --keep-failed
elif command -v pacman >/dev/null 2>&1; then
pacman_list=""
if [ -f ~/.package-lists/arch-official ]; then
@ -193,11 +213,14 @@ if command -v emacs >/dev/null 2>&1; then
fi
fi
message "Emacs local packages"
mkdir -pv ~/.local/share/emacs/site-lisp
for i in ~/.local/share/emacs/site-lisp/*; do
echo "$i"
git -C "$i" pull
done
if [ -e ~/.local/share/emacs/site-lisp ]; then
for i in ~/.local/share/emacs/site-lisp/*; do
echo "$i"
git -C "$i" pull
done
else
mkdir -pv ~/.local/share/emacs/site-lisp
fi
fi
section "Mail"
@ -205,7 +228,8 @@ lnn "$SOURCEDIR/mail/mbsyncrc" "$HOME/.mbsyncrc"
lnn "$SOURCEDIR/mail/authinfo.gpg" "$HOME/.authinfo.gpg"
mkdir -pv "$HOME/.cache/mail/"
while IFS= read -r i; do
mkdir -pv $i
## Warning: We need to eval here to expand the "~".
mkdir -pv $(eval echo $i)
done <<EOF
$(awk '/^Path/ {print $2}' ~/.mbsyncrc)
EOF