2022-11-03 21:57:30 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-12-24 19:25:22 +01:00
|
|
|
########################################################################
|
|
|
|
# Sets app preferences on Linux via dconf #
|
2022-11-03 21:57:30 +01:00
|
|
|
########################################################################
|
|
|
|
# Uses dconf to apply application preferences on Linux GNOME desktops #
|
2022-12-24 19:25:22 +01:00
|
|
|
# Reads source files from ./config/gnome/*.dconf ($DCONF_SOURCE_DIR) #
|
|
|
|
# Creates a backup of current settings, then loads + saves new config #
|
2023-03-16 18:26:44 +01:00
|
|
|
# IMPORTANT: Be sure to read files thoroughly before executing! #
|
2022-11-03 21:57:30 +01:00
|
|
|
########################################################################
|
|
|
|
# Licensed under MIT (C) Alicia Sykes 2022 <https://aliciasykes.com> #
|
|
|
|
########################################################################
|
|
|
|
|
|
|
|
# Color variables
|
2022-12-24 19:25:22 +01:00
|
|
|
PRIMARY_COLOR='\033[1;34m'
|
|
|
|
ACCENT_COLOR='\033[0;96m'
|
2022-11-03 21:57:30 +01:00
|
|
|
ERROR_COLOR='\033[1;31m'
|
2022-12-24 19:25:22 +01:00
|
|
|
WARN_COLOR='\033[0;33m'
|
|
|
|
SUCCESS_COLOR='\033[0;32m'
|
2022-11-03 21:57:30 +01:00
|
|
|
RESET='\033[0m'
|
|
|
|
ITAL='\e[3m'
|
2022-11-06 15:55:38 +01:00
|
|
|
PALE='\e[2m'
|
2022-12-24 19:25:22 +01:00
|
|
|
UNDAL='\e[4m'
|
2022-11-03 21:57:30 +01:00
|
|
|
|
2022-12-24 19:25:22 +01:00
|
|
|
# Set config variables
|
2022-11-03 21:57:30 +01:00
|
|
|
PARAMS=$*
|
2022-12-24 19:25:22 +01:00
|
|
|
FILE_EXT='dconf'
|
2022-11-03 21:57:30 +01:00
|
|
|
|
|
|
|
show_help () {
|
|
|
|
echo -e "${PRIMARY_COLOR}🐧 Linux Desktop Preferences${RESET_COLOR}\n"\
|
2022-11-18 21:11:19 +01:00
|
|
|
"${ACCENT_COLOR}This script will apply preferences to the GNOME shell and"\
|
|
|
|
"related applications using dconf\n Config files are read from"\
|
|
|
|
"./config/gnome and applied to the dconf database in ~/.config/dconf/[user]\n"\
|
2022-11-03 21:57:30 +01:00
|
|
|
"Before any changes are made, existing settings are backed up to ~/.cache/dconf-backups/\n"\
|
2022-11-18 21:11:19 +01:00
|
|
|
"\n The following applications will be configured:\n"\
|
2022-12-24 19:25:22 +01:00
|
|
|
" - Terminal\n"\
|
2022-11-03 21:57:30 +01:00
|
|
|
" - Calculator\n"\
|
|
|
|
" - Evolution\n"\
|
|
|
|
" - Geddit\n"\
|
|
|
|
" - gThumb\n"\
|
|
|
|
" - Todo App\n"\
|
2022-12-24 19:25:22 +01:00
|
|
|
"\n${WARN_COLOR}⚠ Be sure that you've read and unserstood which"\
|
|
|
|
"changes will be applied before proceeding${RESET}\n"
|
2022-11-03 21:57:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# If --help flag passed in, just show the help menu
|
|
|
|
if [[ $PARAMS == *"--help"* ]]; then
|
|
|
|
show_help
|
|
|
|
exit 0
|
|
|
|
elif [[ ! $PARAMS == *"--skip-intro"* ]]; then
|
|
|
|
show_help
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ask for user confirmation before proceeding (if skip flag isn't passed)
|
|
|
|
if [[ ! $PARAMS == *"--yes-to-all"* ]]; then
|
2022-11-06 15:55:38 +01:00
|
|
|
echo -e "\n${PRIMARY_COLOR}Would you like to proceed? (y/N)${RESET}"
|
2022-11-03 21:57:30 +01:00
|
|
|
read -t 15 -n 1 -r
|
|
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
2022-12-24 19:25:22 +01:00
|
|
|
echo -e "${ACCENT_COLOR}\nNo worries, nothing will be applied"\
|
|
|
|
"- feel free to come back another time."
|
2022-11-06 15:55:38 +01:00
|
|
|
echo -e "${PRIMARY_COLOR}Exiting...${RESET}"
|
2022-11-03 21:57:30 +01:00
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo -e "\n"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check dconf is installed, exit with error if not
|
|
|
|
if ! hash dconf 2> /dev/null; then
|
|
|
|
echo -e "${PRIMARY_COLOR}This script requires dconf to be installed${RESET}"
|
|
|
|
echo -e "${ACCENT_COLOR}Exiting...${RESET}"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure XDG variable for cache location is set
|
|
|
|
if [ -z ${XDG_CACHE_HOME+x} ]; then
|
|
|
|
echo -e "${PRIMARY_COLOR}XDG_CACHE_HOME is not yet set. Will use ~/.cache${RESET}"
|
|
|
|
XDG_CACHE_HOME="${HOME}/.cache"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set locations for where to store backups, and where to read new configs from
|
|
|
|
DCONF_BACKUP_DIR="${DCONF_BACKUP_DIR:-${XDG_CACHE_HOME}/dconf-backups}"
|
|
|
|
DCONF_BACKUP_FILE=${DCONF_BACKUP_FILE:-"backup_"`date +"%Y-%m-%d_%H-%M-%S"`}
|
2022-12-24 19:25:22 +01:00
|
|
|
DCONF_SOURCE_DIR="${DOTFILES_DIR:-"$(cd "$(dirname "$0")" && pwd)/../.."}/config/gnome"
|
2022-11-03 21:57:30 +01:00
|
|
|
|
|
|
|
# Create directory to store backups
|
|
|
|
DCONF_BACKUP_PATH="${DCONF_BACKUP_DIR}/${DCONF_BACKUP_FILE}"
|
|
|
|
mkdir -p $DCONF_BACKUP_PATH
|
|
|
|
|
2022-11-18 21:11:19 +01:00
|
|
|
# For a given dconf key ($1), and specified file ($2), check info, make backup, apply settings
|
2022-11-03 21:57:30 +01:00
|
|
|
apply_dconf () {
|
|
|
|
dconf_key=$1
|
|
|
|
dconf_name=$2
|
|
|
|
|
2022-11-06 15:55:38 +01:00
|
|
|
# If --prompt-before-each flag is set, then ask users permission for each app
|
|
|
|
if [[ $PARAMS == *"--prompt-before-each"* ]]; then
|
|
|
|
echo -e -n "\n${PRIMARY_COLOR}Would you like to apply ${dconf_name} settings? (y/N) ${RESET}"
|
|
|
|
read -t 15 -n 1 -r
|
|
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
|
|
echo -e "\n${ACCENT_COLOR}Skipping ${dconf_name} settings${RESET}"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
|
2022-11-03 21:57:30 +01:00
|
|
|
# Check that a valid key is specified
|
|
|
|
if [[ -z "$dconf_key" ]]; then
|
|
|
|
echo -e "${ERROR_COLOR}⚠ Error, no key specified${RESET}"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check source file exists
|
2022-12-24 19:25:22 +01:00
|
|
|
if [ ! -f "$DCONF_SOURCE_DIR/$dconf_name.$FILE_EXT" ]; then
|
2022-11-18 21:11:19 +01:00
|
|
|
echo -e "${ERROR_COLOR}⚠ Error, the specified config file for"\
|
|
|
|
"'${dconf_name}' doesn't exist in ${DCONF_SOURCE_DIR}${RESET}"
|
2022-11-03 21:57:30 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Make backup of existing settings
|
|
|
|
echo -e "${PRIMARY_COLOR}Applying ${dconf_name} config${RESET}"
|
2022-12-24 19:25:22 +01:00
|
|
|
dconf dump $dconf_key > "${DCONF_BACKUP_PATH}/${dconf_name}.$FILE_EXT"
|
2022-11-03 21:57:30 +01:00
|
|
|
|
|
|
|
# Apply new settings from file
|
2022-12-24 19:25:22 +01:00
|
|
|
echo -e "${SUCCESS_COLOR}✓ ${dconf_name} settings succesfully applies to ${dconf_key}${RESET}"
|
|
|
|
dconf load $dconf_key < $DCONF_SOURCE_DIR/${dconf_name}.$FILE_EXT
|
2022-11-03 21:57:30 +01:00
|
|
|
|
|
|
|
# Print instructions on reverting changes
|
2022-12-24 19:25:22 +01:00
|
|
|
echo -e "${ACCENT_COLOR}${ITAL}${PALE}To revert, run $"\
|
|
|
|
"${UNDAL}dconf load $dconf_key < $DCONF_BACKUP_PATH/${dconf_name}.$FILE_EXT${RESET}\n"
|
2022-11-03 21:57:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# For the following dconf keys, apply settings in from the specified files
|
2022-12-24 19:25:22 +01:00
|
|
|
apply_dconf '/org/gnome/calculator/' 'calculator' # Apply calculator settings
|
|
|
|
apply_dconf '/org/gnome/evolution/' 'evolution' # Apply Evolution (mail client) settings
|
|
|
|
apply_dconf '/org/gnome/gedit/preferences/' 'gedit' # Apply Gedit (text editor) settings
|
|
|
|
apply_dconf '/org/gnome/gthumb/' 'gthumb' # Apply gthumb (image editor) settings
|
|
|
|
apply_dconf '/org/gnome/todo/' 'todo' # Apply todo list app settings
|
2022-11-22 23:40:34 +01:00
|
|
|
apply_dconf '/org/gnome/shell/extensions/' 'gnome-extensions'
|
2022-11-18 21:11:19 +01:00
|
|
|
|
2022-11-22 23:40:34 +01:00
|
|
|
# Run update command
|
|
|
|
echo -e "\n${PRIMARY_COLOR}Reloading dconf database${RESET}"
|
|
|
|
sudo dconf update
|