|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -xeuo pipefail |
| 4 | + |
| 5 | +state_dir=${XDG_STATE_HOME:-$HOME/.local/state}/winblues/chezmoi |
| 6 | + |
| 7 | +# NOTE: assume that /usr/share/winblues/chezmoi/dot_local/share/xfconf-profile |
| 8 | +# is a link to /usr/share/xfconf-profile |
| 9 | +# |
| 10 | +#winblues_chezmoi_source=/usr/share/winblues/chezmoi} |
| 11 | +winblues_chezmoi_source=$(pwd)/chezmoi |
| 12 | + |
| 13 | +winblues_chezmoi_home="${state_dir}/home" |
| 14 | + |
| 15 | +export XDG_CONFIG_HOME="${winblues_chezmoi_home}/.config" |
| 16 | +export XDG_DATA_HOME="${winblues_chezmoi_home}/.local/share" |
| 17 | +export XDG_STATE_HOME="${winblues_chezmoi_home}/.local/state" |
| 18 | +export XDG_CACHE_HOME="${winblues_chezmoi_home}/.cache" |
| 19 | + |
| 20 | +winblues_chezmoi_data_home="${XDG_STATE_HOME}/chezmoi" |
| 21 | + |
| 22 | +if [ ! -d "$state_dir" ]; then |
| 23 | + echo "First run of $0" |
| 24 | + mkdir -p "$winblues_chezmoi_home" |
| 25 | + chezmoi init |
| 26 | +fi |
| 27 | + |
| 28 | +cd $winblues_chezmoi_data_home |
| 29 | + |
| 30 | +git config --local user.name "Winblues User" |
| 31 | +git config --local user.email "user@blues.win" |
| 32 | + |
| 33 | +cd $winblues_chezmoi_data_home/.. |
| 34 | +rsync -aP $winblues_chezmoi_source . |
| 35 | + |
| 36 | +cd $winblues_chezmoi_data_home |
| 37 | + |
| 38 | +if [[ -z "$(git status --porcelain)" ]]; then |
| 39 | + echo "No changes needed" |
| 40 | + exit 0 |
| 41 | +fi |
| 42 | + |
| 43 | +# At this point, we know that we need to run chezmoi |
| 44 | + |
| 45 | +git add . |
| 46 | + |
| 47 | +booted_image_version=$(rpm-ostree status --json | jq '.deployments[] | select(.booted == true) | .version' | tr -d '"') |
| 48 | +booted_image=$(rpm-ostree status --json | jq '.deployments[] | select(.booted == true) | ."container-image-reference"' | tr -d '"') |
| 49 | + |
| 50 | +git commit -m "bump: $booted_image_version-$booted_image" |
| 51 | + |
| 52 | +# Check if user has some changes to files we're managing. Save them in a branch and rollback |
| 53 | +# to a known-good state. |
| 54 | +git checkout HEAD~ |
| 55 | + |
| 56 | +if [[ -z "$(chezmoi diff --porcelain)" ]]; then |
| 57 | + echo "Dirty state of managed files. Creating a branch to preserve user's changes." |
| 58 | + if git rev-parse "rollback" >/dev/null 2>&1; then |
| 59 | + git tag -d rollback |
| 60 | + fi |
| 61 | + |
| 62 | + git checkout -b "rollback-$(date +%Y%m%d-%H%M%S)" |
| 63 | + git add . |
| 64 | + git commit -m "user-changes" |
| 65 | + git tag rollback |
| 66 | +fi |
| 67 | + |
| 68 | +git checkout master |
| 69 | + |
| 70 | +# Allow users to ignore updates to certain files |
| 71 | +if [[ -f ~/.config/winblues/chezmoi_ignore ]]; then |
| 72 | + cp ~/.config/winblues/chezmoi_ignore $winblues_chezmoi_data_home/.chezmoiignore |
| 73 | +fi |
| 74 | + |
| 75 | +chezmoi apply |
| 76 | +rm $winblues_chezmoi_data_home/.chezmoiignore |
0 commit comments