Skip to content

Commit 2286302

Browse files
authored
feat: add chezmoi service (#3)
1 parent 5065113 commit 2286302

File tree

10 files changed

+160
-12
lines changed

10 files changed

+160
-12
lines changed

files/scripts/01-main.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@
33
set -ouex pipefail
44

55
systemctl enable libvirtd.service
6-
systemctl --global enable xfconf-profile.service
6+
7+
# This profile will not actually be used by xfconf-profile. We are
8+
# only moving it to the chezmoi target state because we want to apply
9+
# chezmoi changes if this file changes
10+
mkdir -p /usr/share/winblues/chezmoi/dot_local/share/xfconf-profile
11+
cp /usr/share/xfconf-profile/default.json \
12+
/usr/share/winblues/chezmoi/dot_local/share/winblues-blue95.json
13+
14+
systemctl --global preset-all

files/scripts/90-finalize.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -ouex pipefail
3+
4+
systemctl --global preset-all
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enable flatpak-user-update.timer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enable winblues-chezmoi.service
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=Update user-level configs managed by winblues
3+
After=default.target
4+
5+
[Service]
6+
Type=oneshot
7+
ExecStart=/usr/libexec/winblues-chezmoi
8+
9+
[Install]
10+
WantedBy=default.target

files/system/usr/lib/systemd/user/xfconf-profile.service

-11
This file was deleted.
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
set -xeuo pipefail
4+
5+
state_dir=${XDG_STATE_HOME:-$HOME/.local/state}/winblues/chezmoi
6+
7+
user_chezmoi_ignore=${XDG_CONFIG_HOME:-$HOME/.config}/winblues/chezmoiignore
8+
user_env_file=$(mktemp -p /tmp winblues-chezmoi-env.XXXX)
9+
10+
# Save current user environment so we can reload it in chezmoi run_*.sh scripts
11+
echo "export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}" >"${user_env_file}"
12+
echo "export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}" >>"${user_env_file}"
13+
echo "export XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state}" >>"${user_env_file}"
14+
echo "export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}" >>"${user_env_file}"
15+
export WINBLUES_CHEZMOI_ORIGINAL_ENV_FILE="${user_env_file}"
16+
17+
# Use our own chezmoi directories so we don't interfere with the user's chezmoi
18+
export XDG_CONFIG_HOME="${state_dir}/.config"
19+
export XDG_DATA_HOME="${state_dir}/.local/share"
20+
export XDG_STATE_HOME="${state_dir}/.local/state"
21+
export XDG_CACHE_HOME="${state_dir}/.cache"
22+
23+
if [ ! -d "$state_dir" ]; then
24+
echo "First run of $0"
25+
mkdir -p "$state_dir"
26+
chezmoi init
27+
chezmoi git -- checkout -b main
28+
fi
29+
30+
# Copy the booted image's chezmoi source to the user's state
31+
winblues_chezmoi_data_home="${XDG_DATA_HOME}/chezmoi"
32+
winblues_chezmoi_source=/usr/share/winblues/chezmoi
33+
34+
cd $winblues_chezmoi_data_home/..
35+
rsync -aP $winblues_chezmoi_source .
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 apply to update
44+
# our managed files
45+
46+
git config --local user.name "Winblues User"
47+
git config --local user.email "user@blues.win"
48+
git add .
49+
50+
booted_image_version=$(rpm-ostree status --json | jq '.deployments[] | select(.booted == true) | .version' | tr -d '"')
51+
booted_image=$(rpm-ostree status --json | jq '.deployments[] | select(.booted == true) | ."container-image-reference"' | tr -d '"')
52+
53+
git commit -m "bump: $booted_image_version of $booted_image"
54+
55+
# Check if user has changes to files we're managing. Save them in a branch and rollback
56+
# to a known-good state.
57+
if [[ ! -z "$(chezmoi diff --script-contents=false)" ]]; then
58+
echo "Dirty state of managed files. Creating a branch to preserve user's changes."
59+
if git rev-parse "rollback" >/dev/null 2>&1; then
60+
git tag -d rollback
61+
fi
62+
63+
git checkout -b "rollback-$(date +%Y%m%d-%H%M%S)"
64+
chezmoi re-add
65+
git add .
66+
git commit --allow-empty -m "changes to managed files"
67+
git tag rollback
68+
else
69+
echo "No user-modified managed files"
70+
fi
71+
72+
git checkout main
73+
74+
# Allow users to ignore updates to certain files
75+
if [[ -f $user_chezmoi_ignore ]]; then
76+
cp $user_chezmoi_ignore $winblues_chezmoi_data_home/.chezmoiignore
77+
fi
78+
79+
chezmoi apply --force
80+
rm -f $winblues_chezmoi_data_home/.chezmoiignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
. "${WINBLUES_CHEZMOI_ORIGINAL_ENV_FILE}"
6+
7+
xfconf-profile sync
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* NOTE: this file is managed by Winblues using chezmoi. Any changes to this
3+
* file will be overwritten the next time you log in. To configure chezmoi to
4+
* not manage this file, run the following:
5+
* mkdir -p ~/.config/winblues
6+
* echo ".config/gtk-3.0/gtk.css" >> ~/.config/winblues/chezmoiignore
7+
*/
8+
9+
/* GTK 3.24 Theme Override for the Chicago95 theme.
10+
* REMOVE THIS FILE WHEN USING OTHER GTK THEMES! */
11+
12+
/* XFCE APP: Color Profiles
13+
* Add a background colour since the color profile app overrides the GTK theme. */
14+
.color-profiles {
15+
background-color: @bg_color; }
16+
17+
/* XFCE APP: XFCE Session logout dialogue
18+
* Add a border to the logout dialogue. */
19+
.xfsm-logout-dialog {
20+
border-left: 1px solid @border_bright;
21+
border-top: 1px solid @border_bright;
22+
border-bottom: 1px solid @border_dark;
23+
border-right: 1px solid @border_dark;
24+
box-shadow: inset -1px -1px @border_shade, inset 1px 1px @border_light; }
25+
26+
/* XFCE APP: Thunar
27+
* Add a border effect to areas where Thunar will attempt to override. */
28+
.thunar .sidebar {
29+
border-right: 2px solid @border_color; }
30+
.thunar notebook .standard-view {
31+
padding: 0px;
32+
border-left: 2px solid @border_color;
33+
border-right: 2px solid @border_color; }
34+
35+
/* GNOME APP: GNOME Disks
36+
* This is a fix for the GNOME Disks application grid style. */
37+
.gnome-disk-utility-grid {
38+
background-color: @bg_shade;
39+
color: @font_bright;
40+
border-radius: 0px;
41+
outline-color: @border_bright; }
42+
.gnome-disk-utility-grid:backdrop {
43+
background-color: @bg_shade; }
44+
45+

files/system/usr/share/xfconf-profile/default.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
},
1010
"xfwm4": {
1111
"/general/theme": "Chicago95"
12+
},
13+
"xfce4-keyboard-shortcuts": {
14+
"/commands/custom/Super_L": "/usr/bin/xfce4-popup-whiskermenu"
1215
}
1316
}

0 commit comments

Comments
 (0)