Introducing .init.me.sh for multi-machine-architecture support
This commit is contained in:
parent
53c62408d8
commit
5e26df3f9b
|
@ -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 }}"
|
|
@ -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/**
|
|
@ -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'
|
|
@ -0,0 +1,3 @@
|
|||
# .chezmoiroot is generated by .chezmoiscripts/run_onchage_init.sh.tmpl
|
||||
# during chezmoi init --apply
|
||||
.chezmoiroot
|
|
@ -0,0 +1,6 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
rm -fR ~/.config/chezmoi ~/.local/share/chezmoi/.chezmoiroot
|
||||
chezmoi init --apply
|
|
@ -0,0 +1,3 @@
|
|||
[Data]
|
||||
one="One"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
printf '_home.macos init\n'
|
|
@ -0,0 +1 @@
|
|||
../_home/dot_zshrc
|
|
@ -0,0 +1 @@
|
|||
../../_home/private_dot_config/sz.env
|
|
@ -0,0 +1,3 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
printf '_home init\s'
|
|
@ -0,0 +1 @@
|
|||
base.chezmoiroot.posix
|
|
@ -0,0 +1 @@
|
|||
_home.macos
|
|
@ -0,0 +1 @@
|
|||
base.chezmoiroot.macos
|
Loading…
Reference in New Issue