2023-01-13 14:31:54 -08:00
|
|
|
{{- if eq .host.distro.family "linux" -}}
|
2023-01-05 01:09:21 -08:00
|
|
|
#!/usr/bin/env zx
|
|
|
|
|
2023-01-09 12:47:23 -08:00
|
|
|
// gnome config hash: {{ include (joinPath .host.home ".config" "desktop" "gnome.yml") | sha256sum }}
|
|
|
|
// settings config hash: {{ include (joinPath .host.home ".config" "desktop" "settings.yml") | sha256sum }}
|
2023-01-05 01:09:21 -08:00
|
|
|
|
|
|
|
{{ includeTemplate "universal/zx" }}
|
|
|
|
|
2023-01-09 04:49:43 -08:00
|
|
|
// Already included by the universal/zx template
|
|
|
|
// const execSync = require('child_process').execSync
|
|
|
|
|
2023-01-05 01:09:21 -08:00
|
|
|
async function loadThemeSettings() {
|
|
|
|
try {
|
|
|
|
const themeSettingsFile = `${process.env.HOME}/.config/desktop/settings.yml`
|
2023-01-08 17:15:55 -08:00
|
|
|
if (fileExists(themeSettingsFile)) {
|
2023-01-05 01:09:21 -08:00
|
|
|
const text = fs.readFileSync(themeSettingsFile).toString()
|
|
|
|
return YAML.parse(text)
|
|
|
|
} else {
|
|
|
|
log('warn', 'File Missing', 'Could not find ~/.config/desktop/settings.yml')
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
log('error', 'File Load Error', 'Failed to read the ~/.config/desktop/settings.yml file')
|
|
|
|
console.error(e)
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loadGnomeSettings() {
|
|
|
|
try {
|
|
|
|
const gnomeSettingsFile = `${process.env.HOME}/.config/desktop/gnome.yml`
|
2023-01-08 17:15:55 -08:00
|
|
|
if (fileExists(gnomeSettingsFile)) {
|
2023-01-05 01:09:21 -08:00
|
|
|
const text = fs.readFileSync(gnomeSettingsFile).toString()
|
|
|
|
return YAML.parse(text)
|
|
|
|
} else {
|
|
|
|
log('warn', 'File Missing', 'Could not find ~/.config/desktop/gnome.yml')
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
log('error', 'File Load Error', 'Failed to read the ~/.config/desktop/gnome.yml file')
|
|
|
|
console.error(e)
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function applyGsettings(settings) {
|
2023-01-08 18:35:05 -08:00
|
|
|
const gsettings = which.sync('gsettings', { nothrow: true })
|
|
|
|
if (gsettings) {
|
|
|
|
for (const setting of settings) {
|
|
|
|
try {
|
|
|
|
const gsetting = setting.setting
|
|
|
|
const gsettingVal = setting.value
|
2023-01-09 03:21:22 -08:00
|
|
|
const gsettingCmd = 'gsettings set ' + gsetting + ' ' + gsettingVal
|
2023-01-09 04:48:35 -08:00
|
|
|
execSync(gsettingCmd)
|
2023-01-09 04:53:00 -08:00
|
|
|
log('success', 'Gsettings', 'Changed ' + gsetting + ' to ' + gsettingVal)
|
2023-01-08 18:35:05 -08:00
|
|
|
} catch (e) {
|
2023-01-09 04:53:00 -08:00
|
|
|
log('error', 'Gsettings', 'Failed to apply gsetting')
|
2023-01-08 18:35:05 -08:00
|
|
|
console.error(e)
|
|
|
|
}
|
2023-01-05 01:09:21 -08:00
|
|
|
}
|
2023-01-08 18:35:05 -08:00
|
|
|
} else {
|
2023-01-09 04:53:00 -08:00
|
|
|
log('info', 'Gsettings', 'gsettings does not appear to be available')
|
2023-01-05 01:09:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function applyXconfSettings(settings) {
|
2023-01-08 18:35:05 -08:00
|
|
|
const xfconfQuery = which.sync('xfconf-query', { nothrow: true })
|
|
|
|
if (xfconfQuery) {
|
|
|
|
for (const setting of settings) {
|
|
|
|
try {
|
|
|
|
const xfconfType = setting.value_type ? setting.value_type : 'string'
|
2023-01-09 05:07:48 -08:00
|
|
|
const xfCmd = 'xfconf-query --channel \'' + setting.channel + '\' --property \'' + setting.property + '\' --type ' + xfconfType + ' --set ' + setting.value
|
|
|
|
execSync(xfCmd)
|
2023-01-08 18:35:05 -08:00
|
|
|
} catch (e) {
|
2023-01-09 04:53:00 -08:00
|
|
|
log('error', 'Xfconf', 'Failed to apply gsetting')
|
2023-01-08 18:35:05 -08:00
|
|
|
console.error(e)
|
|
|
|
}
|
2023-01-05 01:09:21 -08:00
|
|
|
}
|
2023-01-08 18:35:05 -08:00
|
|
|
} else {
|
2023-01-09 04:53:00 -08:00
|
|
|
log('info', 'Xfconf', 'xfconf-query does not appear to be available')
|
2023-01-05 01:09:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function applyDconfSettings(settings) {
|
2023-01-08 18:35:05 -08:00
|
|
|
const dconf = which.sync('dconf', { nothrow: true })
|
|
|
|
if (dconf) {
|
|
|
|
for (const setting of settings) {
|
|
|
|
try {
|
2023-01-09 05:38:35 -08:00
|
|
|
const dconfCmd = 'dconf write ' + setting.key + ' "' + setting.value + '"'
|
2023-01-09 05:07:48 -08:00
|
|
|
execSync(dconfCmd)
|
2023-01-09 04:53:00 -08:00
|
|
|
log('success', 'Dconf', 'Changed ' + setting.key + ' to ' + setting.value)
|
2023-01-08 18:35:05 -08:00
|
|
|
} catch (e) {
|
2023-01-09 04:53:00 -08:00
|
|
|
log('error', 'Dconf', 'Failed to apply dconf setting')
|
2023-01-08 18:35:05 -08:00
|
|
|
console.error(e)
|
|
|
|
}
|
2023-01-05 01:09:21 -08:00
|
|
|
}
|
2023-01-08 18:35:05 -08:00
|
|
|
} else {
|
2023-01-09 04:53:00 -08:00
|
|
|
log('info', 'Dconf', 'dconf does not appear to be available')
|
2023-01-05 01:09:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const promises = [loadThemeSettings(), loadGnomeSettings()]
|
|
|
|
const results = await Promise.all(promises)
|
|
|
|
const themeSettings = results[0]
|
|
|
|
const gnomeSettings = results[1]
|
2023-01-05 16:17:34 -08:00
|
|
|
const settingsPromises = []
|
2023-01-05 01:09:21 -08:00
|
|
|
if (themeSettings && themeSettings.gsetting_configs) {
|
|
|
|
settingsPromises.push(applyGsettings(themeSettings.gsetting_configs))
|
|
|
|
}
|
|
|
|
if (themeSettings && themeSettings.xconf_settings) {
|
|
|
|
settingsPromises.push(applyXconfSettings(themeSettings.xconf_settings))
|
|
|
|
}
|
|
|
|
if (gnomeSettings && gnomeSettings.default_dconf_settings) {
|
|
|
|
settingsPromises.push(applyDconfSettings(gnomeSettings.default_dconf_settings))
|
|
|
|
}
|
|
|
|
await Promise.all(settingsPromises)
|
|
|
|
log('success', 'Settings', 'Successfully applied all valid gsettings / xconf / dconf settings')
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
2023-01-13 14:31:54 -08:00
|
|
|
|
|
|
|
{{ end -}}
|