Introducing .init.me.sh for multi-machine-architecture support

This commit is contained in:
GSz (@VAST) 2025-02-20 22:24:38 -05:00
parent 53c62408d8
commit 5e26df3f9b
15 changed files with 76 additions and 0 deletions

24
.chezmoi.toml.tmpl Normal file
View File

@ -0,0 +1,24 @@
# This .chezmoi.toml file is used once only
# It collects information about the system in order to determine
# which of the _home.* dirs will be set as the .chezmoiroot
#
{{- $chassisType := "desktop" }}
{{- $sysType := "posix" }}
{{- if eq .chezmoi.os "darwin" }}
{{- $sysType = "macos" }}
{{- if contains "BatteryData" (output "ioreg" "-c" "AppleSmartBattery") }}
{{- $chassisType = "laptop" }}
{{- else }}
{{- $chassisType = "desktop" }}
{{- end }}
{{- else if eq .chezmoi.os "linux" }}
{{- $chassisType = (output "hostnamectl" "--json=short" | mustFromJson).Chassis }}
{{- else if eq .chezmoi.os "windows" }}
{{- $sysType = "windows" }}
{{- $chassisType = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "if ((Get-CimInstance -Class Win32_Battery | Measure-Object).Count -gt 0) { Write-Output 'laptop' } else { Write-Output 'desktop' }") | trim }}
{{- end }}
[scriptEnv]
CZ_CHASSIS="{{- $chassisType }}"
CZ_SYS="{{- $sysType }}"
CZ_OS="{{- .chezmoi.os }}"

7
.chezmoiignore Normal file
View File

@ -0,0 +1,7 @@
# The content at the root of the repo is for initial detection only.
# Thus, only .chezmoitscripts is required, because it will setup the
# correct .chezmoiroot, where the rest of the content resides.
#
*
! .chezmoiscripts/
! .chezmoiscripts/**

View File

@ -0,0 +1,22 @@
#! /usr/bin/env bash
set -e
#env | grep -E 'chezmoi|^CZ'
cd "$CHEZMOI_SOURCE_DIR"
CZ_MODEL="$(ioreg -l | grep "product-name" | sed -Ee 's/^.*\<"(.*)\"\>.*$/\1/')"
set | grep '^CZ_'
printf 'System detected as %s/%s, setting up .chezmoiroot and initializing...\n' "$CZ_SYS" "$CZ_CHASSIS"
if [ -r "base.chezmoiroot.$CZ_SYS.$CZ_CHASSIS" ]; then
ln -s "base.chezmoiroot.$CZ_SYS.$CZ_CHASSIS" .chezmoiroot
elif [ -r "base.chezmoiroot.$CZ_SYS" ]; then
ln -s "base.chezmoiroot.$CZ_SYS" .chezmoiroot
elif [ -r "base.chezmoiroot.$CZ_CHASSIS" ]; then
ln -s "base.chezmoiroot.$CZ_CHASSIS" .chezmoiroot
else
printf 'Failed to find a matching .chezmoiroot. Aborting!\n'
false
fi
# Brute force remove chezmoistate lock and restart init --apply
exec sh -c 'rm ~/.config/chezmoi/chezmoistate.boltdb && chezmoi init --apply'

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# .chezmoiroot is generated by .chezmoiscripts/run_onchage_init.sh.tmpl
# during chezmoi init --apply
.chezmoiroot

6
.init.me.sh Executable file
View File

@ -0,0 +1,6 @@
#! /usr/bin/env bash
set -ex
rm -fR ~/.config/chezmoi ~/.local/share/chezmoi/.chezmoiroot
chezmoi init --apply

View File

@ -0,0 +1,3 @@
[Data]
one="One"

View File

@ -0,0 +1,3 @@
#! /usr/bin/env bash
printf '_home.macos init\n'

1
_home.macos/dot_zshrc Symbolic link
View File

@ -0,0 +1 @@
../_home/dot_zshrc

View File

@ -0,0 +1 @@
../../_home/private_dot_config/sz.env

View File

@ -0,0 +1,3 @@
#! /usr/bin/env bash
printf '_home init\s'

1
base.chezmoiroot.linux Symbolic link
View File

@ -0,0 +1 @@
base.chezmoiroot.posix

1
base.chezmoiroot.macos Normal file
View File

@ -0,0 +1 @@
_home.macos

View File

@ -0,0 +1 @@
base.chezmoiroot.macos