2012-07-28 19:39:12 +02:00
|
|
|
|
#!/bin/sh
|
2014-11-12 16:15:39 +01:00
|
|
|
|
|
2019-01-19 18:39:26 +01:00
|
|
|
|
# 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.)
|
2019-01-22 10:04:44 +01:00
|
|
|
|
# TODO: Make functions to make it easier to re-order calls?
|
2019-01-19 18:39:26 +01:00
|
|
|
|
|
|
|
|
|
HTTPS_ROOT=https://gitlab.com/
|
|
|
|
|
SSH_ROOT=git@gitlab.com:
|
|
|
|
|
ROOT=$HTTPS_ROOT
|
2019-01-22 11:46:33 +01:00
|
|
|
|
PROFILE=/tmp/homeinit-$USER/homeinit
|
2019-01-29 10:16:00 +01:00
|
|
|
|
USER_NAME=Ambrevar
|
2020-03-31 17:37:38 +02:00
|
|
|
|
SUBSTITUTE_URLS=https://ci.guix.gnu.org
|
2019-01-19 18:39:26 +01:00
|
|
|
|
|
2019-01-18 10:42:04 +01:00
|
|
|
|
[ -z "$SOURCEDIR" ] && SOURCEDIR="$HOME/personal"
|
|
|
|
|
[ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
|
|
|
|
|
[ -z "$XDG_DATA_HOME" ] && XDG_DATA_HOME="$HOME/.local/share"
|
2020-06-11 11:49:04 +02:00
|
|
|
|
[ -z "$XDG_BIN_HOME" ] && XDG_BIN_HOME="$XDG_DATA_HOME/../bin"
|
2020-06-11 12:01:33 +02:00
|
|
|
|
## Hardcoded in .mbsyncrc:
|
|
|
|
|
MAIL_CACHE="$HOME/.cache/mail"
|
2019-01-18 10:42:04 +01:00
|
|
|
|
|
2019-05-28 18:25:35 +02:00
|
|
|
|
usage() {
|
2017-05-05 20:29:00 +02:00
|
|
|
|
cat <<EOF>&2
|
|
|
|
|
Usage: ${0##*/}
|
|
|
|
|
|
2019-01-19 18:39:26 +01:00
|
|
|
|
Initialize user profile: install packages, set up folders, etc.
|
2017-05-05 20:29:00 +02:00
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
|
2019-05-28 18:25:35 +02:00
|
|
|
|
-g DEVICE: Device where to sync ~/.gnupg.
|
|
|
|
|
-u: Skip large updates (packages, emails, etc.)
|
2020-03-31 17:37:38 +02:00
|
|
|
|
-s URLS: Extra substitute URLs for Guix (space separated).
|
|
|
|
|
Example: 'http://192.168.1.2:8080'.
|
2019-01-18 10:42:04 +01:00
|
|
|
|
|
|
|
|
|
Environment variables:
|
|
|
|
|
|
|
|
|
|
SOURCEDIR=$SOURCEDIR
|
|
|
|
|
XDG_CONFIG_HOME=$XDG_CONFIG_HOME
|
|
|
|
|
XDG_DATA_HOME=$XDG_DATA_HOME
|
2020-06-11 11:49:04 +02:00
|
|
|
|
XDG_BIN_HOME=$XDG_BIN_HOME
|
2017-05-05 20:29:00 +02:00
|
|
|
|
|
2020-06-11 12:13:21 +02:00
|
|
|
|
Tip:
|
|
|
|
|
|
2020-06-11 12:45:00 +02:00
|
|
|
|
- Run the following command to install the Guix corresponding to your substitute
|
|
|
|
|
server:
|
|
|
|
|
|
|
|
|
|
guix pull -C my-channels.scm
|
|
|
|
|
|
2020-06-11 12:13:21 +02:00
|
|
|
|
- Copy the email cache to '$MAIL_CACHE' to speed up the process.
|
2020-06-11 12:01:33 +02:00
|
|
|
|
|
2019-01-18 15:43:55 +01:00
|
|
|
|
Direct link:
|
|
|
|
|
|
2019-01-19 18:39:26 +01:00
|
|
|
|
${HTTPS_ROOT}ambrevar/dotfiles/raw/master/.local/bin/homeinit
|
2017-05-05 20:29:00 +02:00
|
|
|
|
EOF
|
|
|
|
|
exit
|
2019-05-28 18:25:35 +02:00
|
|
|
|
}
|
2017-05-05 20:29:00 +02:00
|
|
|
|
|
2018-02-11 20:00:14 +01:00
|
|
|
|
OPT_UPDATE=true
|
2019-05-28 18:25:35 +02:00
|
|
|
|
OPT_DEVICE=""
|
2020-03-31 17:37:38 +02:00
|
|
|
|
while getopts ":hg:s:u" opt; do
|
2019-05-28 18:25:35 +02:00
|
|
|
|
case $opt in
|
|
|
|
|
h)
|
|
|
|
|
usage
|
|
|
|
|
exit ;;
|
|
|
|
|
g)
|
|
|
|
|
OPT_DEVICE="$OPTARG" ;;
|
2020-03-31 17:37:38 +02:00
|
|
|
|
s)
|
|
|
|
|
SUBSTITUTE_URLS="$OPTARG $SUBSTITUTE_URLS" ;;
|
2019-05-28 18:25:35 +02:00
|
|
|
|
u)
|
2020-03-31 17:37:38 +02:00
|
|
|
|
OPT_UPDATE=false ;;
|
2019-05-28 18:25:35 +02:00
|
|
|
|
\?)
|
|
|
|
|
usage
|
|
|
|
|
exit 1 ;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
shift $(($OPTIND - 1))
|
2017-05-05 20:29:00 +02:00
|
|
|
|
|
2019-01-18 10:42:04 +01:00
|
|
|
|
RED='\033[0;31m\033[1m'
|
|
|
|
|
GREEN='\033[0;32m\033[1m'
|
|
|
|
|
YELLOW='\033[0;33m\033[1m'
|
|
|
|
|
BOLD='\033[0m\033[1m'
|
|
|
|
|
NORMAL='\033[0m'
|
|
|
|
|
|
|
|
|
|
section() {
|
|
|
|
|
echo -e "$GREEN==> $@$NORMAL"
|
|
|
|
|
}
|
|
|
|
|
message() {
|
|
|
|
|
echo -e "$YELLOW:: $@$NORMAL"
|
|
|
|
|
}
|
2019-01-22 15:33:05 +01:00
|
|
|
|
info() {
|
|
|
|
|
echo -e "$@"
|
|
|
|
|
}
|
2019-01-18 10:42:04 +01:00
|
|
|
|
warning() {
|
|
|
|
|
echo -e "${YELLOW}WARNING:: $@$NORMAL"
|
|
|
|
|
}
|
2012-07-28 20:04:21 +02:00
|
|
|
|
|
2019-01-18 10:42:04 +01:00
|
|
|
|
## "ln" wrapper.
|
|
|
|
|
## If $2 is a folder, create the link in it using the basename of $1.
|
|
|
|
|
## Existing files are no clobbered, unless they already are a symlink.
|
|
|
|
|
lnn() { # $1=TARGET $2=LINK|FOLDER
|
2018-01-11 11:19:20 +01:00
|
|
|
|
if [ -d "$2" ]; then
|
|
|
|
|
set -- "$1" "$2/$(basename "$1")"
|
|
|
|
|
fi
|
2017-07-24 18:25:31 +02:00
|
|
|
|
if [ ! -e "$2" ] || [ -h "$2" ]; then
|
|
|
|
|
ln -svnf "$1" "$2"
|
|
|
|
|
fi
|
|
|
|
|
}
|
2013-05-04 00:30:11 +02:00
|
|
|
|
|
2019-01-22 11:24:35 +01:00
|
|
|
|
inpath() {
|
|
|
|
|
for i; do
|
|
|
|
|
if ! command -v "$i" >/dev/null 2>&1; then
|
2019-01-22 15:32:44 +01:00
|
|
|
|
return 1
|
2019-01-22 11:24:35 +01:00
|
|
|
|
fi
|
|
|
|
|
done
|
2019-01-22 15:32:44 +01:00
|
|
|
|
return 0
|
2019-01-22 11:24:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 10:42:04 +01:00
|
|
|
|
################################################################################
|
2019-01-19 18:39:26 +01:00
|
|
|
|
#
|
2019-01-18 10:42:04 +01:00
|
|
|
|
|
|
|
|
|
section "Initial packages"
|
2019-01-22 11:24:35 +01:00
|
|
|
|
if inpath guix; then
|
2019-06-24 21:40:31 +02:00
|
|
|
|
mkdir -p ~/.config/guix
|
|
|
|
|
|
2019-01-22 15:09:27 +01:00
|
|
|
|
## OpenSSH is not an input of Git, upstream does not want to increase the
|
|
|
|
|
## closure size that much.
|
2019-05-28 18:25:35 +02:00
|
|
|
|
mkdir -p "$(dirname "$PROFILE")"
|
2020-03-31 17:45:14 +02:00
|
|
|
|
guix package --profile="$PROFILE" --install openssh gnupg git stow password-store pinentry-tty pinentry-gtk2 cryptsetup recutils --substitute-urls="$SUBSTITUTE_URLS"
|
2019-01-22 11:46:33 +01:00
|
|
|
|
source "$PROFILE"/etc/profile
|
2018-05-18 12:05:05 +02:00
|
|
|
|
fi
|
|
|
|
|
|
2020-03-31 17:37:38 +02:00
|
|
|
|
has_gpg_keys() {
|
|
|
|
|
[ -n "$(ls -1 ~/.gnupg/private-*)" ]
|
|
|
|
|
}
|
2019-05-28 18:25:35 +02:00
|
|
|
|
|
2020-06-11 12:39:35 +02:00
|
|
|
|
is_laptop() {
|
|
|
|
|
[ -n "$(ls -1 /sys/class/power_supply/)" ]
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 17:37:38 +02:00
|
|
|
|
if ! has_gpg_keys; then
|
2019-05-28 18:25:35 +02:00
|
|
|
|
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
|
|
|
|
|
|
2019-01-18 10:42:04 +01:00
|
|
|
|
section "GPG"
|
2020-03-31 17:37:38 +02:00
|
|
|
|
if has_gpg_keys; then
|
2019-01-19 18:39:26 +01:00
|
|
|
|
ROOT=$SSH_ROOT
|
|
|
|
|
## Set up gpg-agent to authenticate to SSH_ROOT.
|
2019-01-22 12:49:46 +01:00
|
|
|
|
chmod -R go-rwx ~/.gnupg
|
2019-01-19 18:39:26 +01:00
|
|
|
|
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
|
2020-06-11 12:07:04 +02:00
|
|
|
|
if [ "$GPG_TTY" != "not a tty" ] || [ -z "$INSIDE_EMACS" ]; then
|
|
|
|
|
## If a TTY, since our ~/.gnupg/gpg-agent.conf exists and specifies the Emacs
|
|
|
|
|
## pinentry, we must force the TTY version or else it won't work from a TTY.
|
|
|
|
|
## Same if not in Emacs (e.g. Xterm).
|
2019-01-22 12:49:46 +01:00
|
|
|
|
gpgconf --kill gpg-agent
|
|
|
|
|
cat<<EOF>"$(dirname "$PROFILE")/gpg-agent.conf"
|
|
|
|
|
## 1-day timeout
|
|
|
|
|
default-cache-ttl 86400
|
|
|
|
|
max-cache-ttl 86400
|
|
|
|
|
## SSH
|
|
|
|
|
enable-ssh-support
|
|
|
|
|
default-cache-ttl-ssh 86400
|
|
|
|
|
max-cache-ttl-ssh 86400
|
|
|
|
|
## Force pinentry (should be pinentry-tty)
|
|
|
|
|
pinentry-program $(readlink -f $(which pinentry))
|
|
|
|
|
EOF
|
2019-01-22 17:20:12 +01:00
|
|
|
|
gpg-agent --homedir ~/.gnupg --daemon --options "$(dirname "$PROFILE")/gpg-agent.conf"
|
2019-01-22 12:49:46 +01:00
|
|
|
|
fi
|
|
|
|
|
## Start gpg-agent manually since SSH requests do not do it automatically.
|
2019-01-19 18:39:26 +01:00
|
|
|
|
gpg-connect-agent updatestartuptty /bye
|
|
|
|
|
|
2018-05-18 12:32:48 +02:00
|
|
|
|
if [ -e "$SOURCEDIR" ]; then
|
|
|
|
|
git -C "$SOURCEDIR" pull
|
|
|
|
|
else
|
2019-01-29 10:16:00 +01:00
|
|
|
|
git clone ${SSH_ROOT}$USER_NAME/personal ~/personal
|
2018-05-18 12:32:48 +02:00
|
|
|
|
fi
|
|
|
|
|
if [ -e ~/.password-store ]; then
|
|
|
|
|
git -C ~/.password-store pull
|
|
|
|
|
else
|
2019-01-29 10:16:00 +01:00
|
|
|
|
git clone ${SSH_ROOT}$USER_NAME/password-store ~/.password-store
|
2018-07-12 12:02:07 +02:00
|
|
|
|
## The following is necessary to make sure the 'diff' GPG filter is properly set up.
|
|
|
|
|
pass git init
|
2018-05-18 12:32:48 +02:00
|
|
|
|
fi
|
2018-05-18 12:05:05 +02:00
|
|
|
|
else
|
2019-01-18 10:42:04 +01:00
|
|
|
|
warning "~/.gnupg not found."
|
2018-05-18 12:05:05 +02:00
|
|
|
|
fi
|
|
|
|
|
|
2019-01-18 10:42:04 +01:00
|
|
|
|
section "Persistent folders"
|
2020-06-11 12:01:33 +02:00
|
|
|
|
for i in "$MAIL_CACHE" .config .config/guix .config/transmission-daemon .emacs.d "$XDG_DATA_HOME" .mpv projects; do
|
2018-05-18 12:05:05 +02:00
|
|
|
|
mkdir -pv "$HOME/$i"
|
|
|
|
|
done
|
|
|
|
|
|
2019-01-18 10:42:04 +01:00
|
|
|
|
section "dotfiles"
|
2018-05-18 12:05:05 +02:00
|
|
|
|
if [ -e ~/dotfiles ]; then
|
2019-01-29 10:16:00 +01:00
|
|
|
|
git -C ~/dotfiles remote set-url origin ${ROOT}$USER_NAME/dotfiles
|
2018-05-18 12:32:48 +02:00
|
|
|
|
git -C ~/dotfiles pull
|
2018-05-18 12:05:05 +02:00
|
|
|
|
else
|
2019-01-29 10:16:00 +01:00
|
|
|
|
git clone ${ROOT}$USER_NAME/dotfiles ~/dotfiles || exit 1
|
2018-05-18 12:05:05 +02:00
|
|
|
|
fi
|
|
|
|
|
pushd ~/dotfiles
|
2019-01-22 12:49:46 +01:00
|
|
|
|
## .bash_profile may prevent .profile from being parsed, so we move it.
|
2020-06-11 13:45:57 +02:00
|
|
|
|
for i in ~/.bash_profile ~/.bashrc; do
|
|
|
|
|
[ -e "$i" ] && mv -v "$i" "$i".old
|
|
|
|
|
done
|
2019-01-19 18:39:26 +01:00
|
|
|
|
stow -v . || exit 1
|
2018-05-18 12:05:05 +02:00
|
|
|
|
popd
|
2017-07-29 10:31:30 +02:00
|
|
|
|
|
2020-06-11 12:39:35 +02:00
|
|
|
|
guix_install_profile() {
|
|
|
|
|
local profile
|
|
|
|
|
local manifest
|
|
|
|
|
manifest=$HOME/.package-lists/guix-$i-manifest.scm
|
2020-06-11 13:45:57 +02:00
|
|
|
|
if [ -f "$manifest" ]; then
|
2020-06-11 12:39:35 +02:00
|
|
|
|
warning "Manifest $manifest not found."
|
|
|
|
|
else
|
2020-06-11 13:45:57 +02:00
|
|
|
|
if [ "$i" = "default" ]; then
|
2020-06-11 12:45:21 +02:00
|
|
|
|
~/.config/guix/current/bin/guix package --manifest="$manifest" --keep-failed --substitute-urls="$SUBSTITUTE_URLS"
|
|
|
|
|
. ~/.guix-profile/etc/profile
|
|
|
|
|
else
|
|
|
|
|
profile=$HOME/.guix-extra-profiles/$i/$i
|
|
|
|
|
mkdir -p $(dirname "$profile")
|
|
|
|
|
~/.config/guix/current/bin/guix package --manifest="$manifest" --keep-failed --profile="$profile" --substitute-urls="$SUBSTITUTE_URLS"
|
|
|
|
|
if [ -f "$profile"/etc/profile ]; then
|
|
|
|
|
. "$profile"/etc/profile
|
|
|
|
|
fi
|
2020-06-11 12:39:35 +02:00
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 10:42:04 +01:00
|
|
|
|
section "System packages"
|
2019-01-22 11:24:35 +01:00
|
|
|
|
if inpath guix; then
|
2020-03-31 17:37:38 +02:00
|
|
|
|
if [ ! -e ~/.cache/guix ]; then
|
2020-06-11 12:39:35 +02:00
|
|
|
|
message "First 'guix pull'"
|
2020-06-11 12:13:21 +02:00
|
|
|
|
guix pull --substitute-urls="$SUBSTITUTE_URLS"
|
2019-05-28 18:25:35 +02:00
|
|
|
|
hash guix
|
2019-01-22 13:39:04 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2020-06-11 12:45:21 +02:00
|
|
|
|
for i in default main emacs next texlive; do
|
2020-06-11 12:39:35 +02:00
|
|
|
|
guix_install_profile "$i"
|
2020-01-12 22:12:59 +01:00
|
|
|
|
done
|
2020-06-11 12:39:35 +02:00
|
|
|
|
if $is_laptop; then
|
|
|
|
|
guix_install_profile laptop laptop-gaming
|
|
|
|
|
else
|
|
|
|
|
guix_install_profile gaming
|
|
|
|
|
fi
|
|
|
|
|
if $OPT_UPDATE; then
|
|
|
|
|
for i in blender chromium electrum racket; do
|
|
|
|
|
guix_install_profile "$i"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
warning "Package manager not supported. Install Guix."
|
2018-01-11 11:06:43 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2019-01-22 11:24:35 +01:00
|
|
|
|
if inpath emacs; then
|
2019-01-18 10:42:04 +01:00
|
|
|
|
message "Emacs cache folder"
|
2018-02-16 14:18:28 +01:00
|
|
|
|
mkdir -pv "$HOME/.cache/emacs/"
|
2019-01-18 10:42:04 +01:00
|
|
|
|
message "Emacs local packages"
|
2020-06-11 11:47:16 +02:00
|
|
|
|
if [ -e "$XDG_DATA_HOME"/emacs/site-lisp ]; then
|
|
|
|
|
for i in "$XDG_DATA_HOME"/emacs/site-lisp/*; do
|
2019-01-19 18:39:26 +01:00
|
|
|
|
echo "$i"
|
|
|
|
|
git -C "$i" pull
|
|
|
|
|
done
|
|
|
|
|
else
|
2020-06-11 11:47:16 +02:00
|
|
|
|
mkdir -pv "$XDG_DATA_HOME"/emacs/site-lisp
|
2019-01-19 18:39:26 +01:00
|
|
|
|
fi
|
2016-05-06 09:24:40 +02:00
|
|
|
|
fi
|
2016-06-09 21:32:07 +02:00
|
|
|
|
|
2019-01-22 11:46:33 +01:00
|
|
|
|
if inpath guix; then
|
|
|
|
|
section "Cleanup initial packages"
|
|
|
|
|
rm -rv "$(dirname "$PROFILE")"
|
|
|
|
|
fi
|
|
|
|
|
|
2020-06-11 11:49:04 +02:00
|
|
|
|
if [ -x "$XDG_BIN_HOME"/updatedb-local ]; then
|
2019-01-29 10:16:00 +01:00
|
|
|
|
section "locate db"
|
2020-06-11 11:49:04 +02:00
|
|
|
|
"$XDG_BIN_HOME"/updatedb-local
|
2019-01-22 10:04:44 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2019-01-18 10:42:04 +01:00
|
|
|
|
section "Mail"
|
2020-03-31 17:37:38 +02:00
|
|
|
|
# lnn "$SOURCEDIR/mail/authinfo.gpg" "$HOME/.authinfo.gpg" ## Only if not using password-store.
|
2020-06-11 12:01:33 +02:00
|
|
|
|
mkdir -pv "$MAIL_CACHE"
|
2018-05-18 12:05:05 +02:00
|
|
|
|
while IFS= read -r i; do
|
2019-01-19 18:39:26 +01:00
|
|
|
|
## Warning: We need to eval here to expand the "~".
|
|
|
|
|
mkdir -pv $(eval echo $i)
|
2018-05-18 12:05:05 +02:00
|
|
|
|
done <<EOF
|
2019-01-18 10:42:04 +01:00
|
|
|
|
$(awk '/^Path/ {print $2}' ~/.mbsyncrc)
|
2017-07-24 18:25:31 +02:00
|
|
|
|
EOF
|
2017-07-29 10:31:30 +02:00
|
|
|
|
|
2018-01-11 11:06:43 +01:00
|
|
|
|
if $OPT_UPDATE; then
|
|
|
|
|
mbsync -aV
|
2020-06-11 12:01:33 +02:00
|
|
|
|
# mu index --maildir="$MAIL_CACHE"
|
2019-03-17 20:14:04 +01:00
|
|
|
|
notmuch new
|
2018-01-11 11:06:43 +01:00
|
|
|
|
fi
|