mirror of
https://github.com/Xevion/dotfiles.git
synced 2026-01-31 06:24:13 -06:00
Standardize hooks, add better key.txt bootstrapper, add update hook to detect --init
This commit is contained in:
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# note: CHEZMOI_UPDATE will be set if this was invoked indirectly by 'chezmoi update --init'
|
||||
set -eu
|
||||
|
||||
# While key.txt is managed by Chezmoi, it's required for encrypted operations and needed to bootstrap other operations.
|
||||
if [ ! -f ~/key.txt ]; then
|
||||
rbw get "key.txt (age)" --field notes >>~/key.txt
|
||||
rbw get "key.txt (age)" --field password >>~/key.txt
|
||||
echo "key.txt bootstrapped"
|
||||
fi
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
apt_update() {
|
||||
# Only run apt update once
|
||||
if [ -f /tmp/.apt-updated ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
sudo apt update >/dev/null
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to update apt"
|
||||
exit 1
|
||||
else
|
||||
touch /tmp/.apt-updated
|
||||
fi
|
||||
}
|
||||
|
||||
install_age() {
|
||||
# Test if age is installed
|
||||
command -v age >/dev/null 2>&1 && return
|
||||
|
||||
# Install age
|
||||
apt_update
|
||||
sudo apt install age
|
||||
}
|
||||
|
||||
install_cargo_binstall() {
|
||||
# Test if cargo binstall is installed
|
||||
cargo binstall --help >/dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
return
|
||||
fi
|
||||
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
|
||||
|
||||
# Test again
|
||||
cargo binstall --help
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to install cargo binstall"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
install_rbw() {
|
||||
# Test if rbw is installed
|
||||
command -v rbw >/dev/null 2>&1 && return
|
||||
cargo binstall rbw --no-confirm
|
||||
|
||||
# Test again
|
||||
command -v rbw >/dev/null 2>&1 && return
|
||||
echo "Failed to install rbw"
|
||||
exit 1
|
||||
}
|
||||
|
||||
install_inotify() {
|
||||
if ! dpkg -l inotify-tools >/dev/null 2>&1; then
|
||||
echo "Installing inotify-tools"
|
||||
apt_update
|
||||
sudo apt install inotify-tools
|
||||
fi
|
||||
}
|
||||
|
||||
install_inotify
|
||||
install_age
|
||||
install_cargo_binstall
|
||||
install_rbw
|
||||
rbw login
|
||||
rbw sync
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# chezmoi update --init does not invoke the 'hooks.init.pre' hook, so we do it ourselves
|
||||
if grep -q 'init' <<<$CHEZMOI_ARGS; then
|
||||
# CHEZMOI_UPDATE is just a hint in case we need to know if we're updating
|
||||
CHEZMOI_UPDATE=1 $(dirname $0)/.init_pre.sh
|
||||
fi
|
||||
Reference in New Issue
Block a user