2022-11-07 00:57:18 +01:00
|
|
|
#!/usr/bin/env bash
|
2022-08-11 11:22:22 +02:00
|
|
|
|
2022-09-13 14:29:13 +02:00
|
|
|
######################################################################
|
|
|
|
# 🧰 Lissy93/Dotfiles - All-in-One Install and Setup Script for Unix #
|
|
|
|
######################################################################
|
|
|
|
# Fetches latest changes, symlinks files, and installs dependencies #
|
|
|
|
# Then sets up ZSH, TMUX, Vim as well as OS-specific tools and apps #
|
2022-11-12 13:37:13 +01:00
|
|
|
# Checks all dependencies are met, and prompts to install if missing #
|
2022-09-13 14:29:13 +02:00
|
|
|
# For docs and more info, see: https://github.com/lissy93/dotfiles #
|
|
|
|
# #
|
2023-10-29 17:42:33 +01:00
|
|
|
# OPTIONS: #
|
|
|
|
# --auto-yes: Skip all prompts, and auto-accept all changes #
|
|
|
|
# --no-clear: Don't clear the screen before running #
|
|
|
|
# #
|
|
|
|
# ENVIRONMENTAL VARIABLES: #
|
|
|
|
# DOTFILES_DIR: Where to save dotfiles to (default: ~/.dotfiles) #
|
|
|
|
# DOTFILES_REPO: Git repo to USE (default: Lissy93/Dotfiles) #
|
|
|
|
# #
|
2022-09-13 14:29:13 +02:00
|
|
|
# IMPORTANT: Before running, read through everything very carefully! #
|
|
|
|
# #
|
|
|
|
# Licensed under MIT (C) Alicia Sykes 2022 <https://aliciasykes.com> #
|
|
|
|
######################################################################
|
2022-08-11 11:22:22 +02:00
|
|
|
|
2022-10-31 17:32:01 +01:00
|
|
|
# Set variables for reference
|
|
|
|
PARAMS=$* # User-specified parameters
|
|
|
|
CURRENT_DIR=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd)
|
|
|
|
SYSTEM_TYPE=$(uname -s) # Get system type - Linux / MacOS (Darwin)
|
|
|
|
PROMPT_TIMEOUT=15 # When user is prompted for input, skip after x seconds
|
|
|
|
START_TIME=`date +%s` # Start timer
|
|
|
|
SRC_DIR=$(dirname ${0})
|
|
|
|
|
2022-10-11 19:27:33 +02:00
|
|
|
# Dotfiles Source Repo and Destination Directory
|
2022-09-13 14:29:13 +02:00
|
|
|
REPO_NAME="${REPO_NAME:-Lissy93/Dotfiles}"
|
2022-10-31 17:32:01 +01:00
|
|
|
DOTFILES_DIR="${DOTFILES_DIR:-${SRC_DIR:-$HOME/.dotfiles}}"
|
2022-10-11 19:27:33 +02:00
|
|
|
DOTFILES_REPO="${DOTFILES_REPO:-https://github.com/${REPO_NAME}.git}"
|
|
|
|
|
|
|
|
# Config Names and Locations
|
|
|
|
TITLE="🧰 ${REPO_NAME} Setup"
|
2022-09-13 14:29:13 +02:00
|
|
|
SYMLINK_FILE="${SYMLINK_FILE:-symlinks.yaml}"
|
2022-10-27 00:13:53 +02:00
|
|
|
DOTBOT_DIR="lib/dotbot"
|
2022-03-12 20:27:04 +01:00
|
|
|
DOTBOT_BIN="bin/dotbot"
|
2022-10-11 19:27:33 +02:00
|
|
|
|
2022-03-09 23:10:48 +01:00
|
|
|
# Color Variables
|
|
|
|
CYAN_B='\033[1;96m'
|
|
|
|
YELLOW_B='\033[1;93m'
|
|
|
|
RED_B='\033[1;31m'
|
|
|
|
GREEN_B='\033[1;32m'
|
|
|
|
PLAIN_B='\033[1;37m'
|
|
|
|
RESET='\033[0m'
|
2022-08-30 18:39:35 +02:00
|
|
|
GREEN='\033[0;32m'
|
2022-08-07 17:58:57 +02:00
|
|
|
PURPLE='\033[0;35m'
|
2022-03-09 23:10:48 +01:00
|
|
|
|
2022-09-26 20:40:27 +02:00
|
|
|
# Clear the screen
|
2022-10-22 17:47:52 +02:00
|
|
|
if [[ ! $PARAMS == *"--no-clear"* ]] && [[ ! $PARAMS == *"--help"* ]] ; then
|
2022-09-26 20:40:27 +02:00
|
|
|
clear
|
|
|
|
fi
|
|
|
|
|
2022-09-28 19:17:56 +02:00
|
|
|
# If set to auto-yes - then don't wait for user reply
|
2022-10-11 19:27:33 +02:00
|
|
|
if [[ $PARAMS == *"--auto-yes"* ]]; then
|
2022-09-28 19:17:56 +02:00
|
|
|
PROMPT_TIMEOUT=1
|
2022-10-27 00:13:53 +02:00
|
|
|
AUTO_YES=true
|
2022-09-28 19:17:56 +02:00
|
|
|
fi
|
|
|
|
|
2022-03-09 23:10:48 +01:00
|
|
|
# Function that prints important text in a banner with colored border
|
|
|
|
# First param is the text to output, then optional color and padding
|
2022-08-06 12:39:28 +02:00
|
|
|
make_banner () {
|
2022-03-09 23:10:48 +01:00
|
|
|
bannerText=$1
|
|
|
|
lineColor="${2:-$CYAN_B}"
|
|
|
|
padding="${3:-0}"
|
|
|
|
titleLen=$(expr ${#bannerText} + 2 + $padding);
|
|
|
|
lineChar="─"; line=""
|
|
|
|
for (( i = 0; i < "$titleLen"; ++i )); do line="${line}${lineChar}"; done
|
|
|
|
banner="${lineColor}╭${line}╮\n│ ${PLAIN_B}${bannerText}${lineColor} │\n╰${line}╯"
|
|
|
|
echo -e "\n${banner}\n${RESET}"
|
|
|
|
}
|
2021-01-31 21:45:12 +01:00
|
|
|
|
2022-09-23 20:54:18 +02:00
|
|
|
# Explain to the user what changes will be made
|
|
|
|
make_intro () {
|
|
|
|
C2="\033[0;35m"
|
|
|
|
C3="\x1b[2m"
|
2022-11-10 06:46:14 +01:00
|
|
|
echo -e "${CYAN_B}The seup script will do the following:${RESET}\n"\
|
|
|
|
"${C2}(1) Pre-Setup Tasls\n"\
|
|
|
|
" ${C3}- Check that all requirements are met, and system is compatible\n"\
|
|
|
|
" ${C3}- Sets environmental variables from params, or uses sensible defaults\n"\
|
2022-11-17 13:52:03 +01:00
|
|
|
" ${C3}- Output welcome message and summary of changes\n"\
|
2022-11-10 06:46:14 +01:00
|
|
|
"${C2}(2) Setup Dotfiles\n"\
|
|
|
|
" ${C3}- Clone or update dotfiles from git\n"\
|
|
|
|
" ${C3}- Symlinks dotfiles to correct locations\n"\
|
|
|
|
"${C2}(3) Install packages\n"\
|
|
|
|
" ${C3}- On MacOS, prompt to install Homebrew if not present\n"\
|
|
|
|
" ${C3}- On MacOS, updates and installs apps liseted in Brewfile\n"\
|
|
|
|
" ${C3}- On Arch Linux, updates and installs packages via Pacman\n"\
|
|
|
|
" ${C3}- On Debian Linux, updates and installs packages via apt get\n"\
|
|
|
|
" ${C3}- On Linux desktop systems, prompt to install desktop apps via Flatpak\n"\
|
2023-06-13 23:30:33 +02:00
|
|
|
" ${C3}- Checks that OS is up-to-date and critical patches are installed\n"\
|
|
|
|
"${C2}(4) Configure system\n"\
|
2022-11-17 13:52:03 +01:00
|
|
|
" ${C3}- Setup Vim, and install / update Vim plugins via Plug\n"\
|
|
|
|
" ${C3}- Setup Tmux, and install / update Tmux plugins via TPM\n"\
|
|
|
|
" ${C3}- Setup ZSH, and install / update ZSH plugins via Antigen\n"\
|
|
|
|
" ${C3}- Apply system settings (via NSDefaults on Mac, dconf on Linux)\n"\
|
|
|
|
" ${C3}- Apply assets, wallpaper, fonts, screensaver, etc\n"\
|
2022-11-10 06:46:14 +01:00
|
|
|
"${C2}(5) Finishing Up\n"\
|
|
|
|
" ${C3}- Refresh current terminal session\n"\
|
|
|
|
" ${C3}- Print summary of applied changes and time taken\n"\
|
|
|
|
" ${C3}- Exit with appropriate status code\n\n"\
|
|
|
|
"${PURPLE}You will be prompted at each stage, before any changes are made.${RESET}\n"\
|
|
|
|
"${PURPLE}For more info, see GitHub: \033[4;35mhttps://github.com/${REPO_NAME}${RESET}"
|
2022-09-23 20:54:18 +02:00
|
|
|
}
|
|
|
|
|
2022-11-08 21:22:55 +01:00
|
|
|
# Cleanup tasks, run when the script exits
|
|
|
|
cleanup () {
|
|
|
|
# Reset tab color and title (iTerm2 only)
|
|
|
|
echo -e "\033];\007\033]6;1;bg;*;default\a"
|
2022-11-17 15:41:12 +01:00
|
|
|
|
2022-11-08 21:22:55 +01:00
|
|
|
# Unset re-used variables
|
|
|
|
unset PROMPT_TIMEOUT
|
|
|
|
unset AUTO_YES
|
|
|
|
|
2022-11-12 13:37:13 +01:00
|
|
|
# dinosaurs are awesome
|
2022-11-08 21:22:55 +01:00
|
|
|
echo "🦖"
|
2022-09-23 20:54:18 +02:00
|
|
|
}
|
|
|
|
|
2021-02-08 16:26:59 +01:00
|
|
|
# Checks if a given package is installed
|
|
|
|
command_exists () {
|
|
|
|
hash "$1" 2> /dev/null
|
|
|
|
}
|
|
|
|
|
2022-08-11 11:22:22 +02:00
|
|
|
# On error, displays death banner, and terminates app with exit code 1
|
2022-03-09 23:10:48 +01:00
|
|
|
terminate () {
|
|
|
|
make_banner "Installation failed. Terminating..." ${RED_B}
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Checks if command / package (in $1) exists and then shows
|
2022-08-30 18:39:35 +02:00
|
|
|
# either shows a warning or error, depending if package required ($2)
|
2021-02-08 16:26:59 +01:00
|
|
|
system_verify () {
|
|
|
|
if ! command_exists $1; then
|
2022-03-09 23:10:48 +01:00
|
|
|
if $2; then
|
2022-03-12 20:27:04 +01:00
|
|
|
echo -e "🚫 ${RED_B}Error:${PLAIN_B} $1 is not installed${RESET}"
|
2022-03-09 23:10:48 +01:00
|
|
|
terminate
|
|
|
|
else
|
2022-03-12 20:27:04 +01:00
|
|
|
echo -e "⚠️ ${YELLOW_B}Warning:${PLAIN_B} $1 is not installed${RESET}"
|
2022-03-09 23:10:48 +01:00
|
|
|
fi
|
2021-02-08 16:26:59 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-11-12 13:37:13 +01:00
|
|
|
# Shows a desktop notification, on compatible systems ($1 = message)
|
|
|
|
show_notification () {
|
|
|
|
if [[ $PARAMS == *"--no-notifications"* ]]; then return; fi
|
|
|
|
notif_title=$TITLE
|
|
|
|
notif_logo="${DOTFILES_DIR}/.github/logo.png"
|
|
|
|
if command_exists terminal-notifier; then
|
|
|
|
terminal-notifier -group 'dotfiles' -title $notif_title -subtitle $1 \
|
|
|
|
-message $2 -appIcon $notif_logo -contentImage $notif_logo \
|
|
|
|
-remove 'ALL' -sound 'Sosumi' &> /dev/null
|
|
|
|
elif command_exists notify-send; then
|
|
|
|
notify-send -u normal -t 15000 -i "${notif_logo}" "${notif_title}" "${1}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-08-11 11:22:22 +02:00
|
|
|
# Prints welcome banner, verifies that requirements are met
|
2022-08-10 13:07:57 +02:00
|
|
|
function pre_setup_tasks () {
|
2022-10-11 19:27:33 +02:00
|
|
|
# Show pretty starting banner
|
2022-08-10 13:07:57 +02:00
|
|
|
make_banner "${TITLE}" "${CYAN_B}" 1
|
|
|
|
|
2022-11-08 21:22:55 +01:00
|
|
|
# Set term title
|
|
|
|
echo -e "\033];${TITLE}\007\033]6;1;bg;red;brightness;30\a" \
|
|
|
|
"\033]6;1;bg;green;brightness;235\a\033]6;1;bg;blue;brightness;215\a"
|
|
|
|
|
2022-10-11 19:27:33 +02:00
|
|
|
# Print intro, listing what changes will be applied
|
2022-09-23 20:54:18 +02:00
|
|
|
make_intro
|
|
|
|
|
2022-10-11 19:27:33 +02:00
|
|
|
# Confirm that the user would like to proceed
|
2022-09-23 20:54:18 +02:00
|
|
|
echo -e "\n${CYAN_B}Are you happy to continue? (y/N)${RESET}"
|
2022-10-27 00:13:53 +02:00
|
|
|
read -t $PROMPT_TIMEOUT -n 1 -r ans_start
|
|
|
|
if [[ ! $ans_start =~ ^[Yy]$ ]] && [[ $AUTO_YES != true ]] ; then
|
2022-11-12 13:37:13 +01:00
|
|
|
echo -e "\n${PURPLE}No worries, feel free to come back another time."\
|
|
|
|
"\nTerminating...${RESET}"
|
2022-10-11 19:27:33 +02:00
|
|
|
make_banner "🚧 Installation Aborted" ${YELLOW_B} 1
|
2022-09-23 20:54:18 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
|
2022-11-17 13:52:03 +01:00
|
|
|
# If pre-requsite packages not found, prompt to install
|
|
|
|
if ! command_exists git; then
|
|
|
|
bash <(curl -s -L 'https://alicia.url.lol/prerequisite-installs') $PARAMS
|
|
|
|
fi
|
|
|
|
|
2022-08-10 13:07:57 +02:00
|
|
|
# Verify required packages are installed
|
|
|
|
system_verify "git" true
|
|
|
|
system_verify "zsh" false
|
|
|
|
system_verify "vim" false
|
|
|
|
system_verify "nvim" false
|
|
|
|
system_verify "tmux" false
|
2022-11-01 14:23:24 +01:00
|
|
|
|
|
|
|
# If XDG variables arn't yet set, then configure defaults
|
|
|
|
if [ -z ${XDG_CONFIG_HOME+x} ]; then
|
|
|
|
echo -e "${YELLOW_B}XDG_CONFIG_HOME is not yet set. Will use ~/.config${RESET}"
|
2022-11-07 00:57:18 +01:00
|
|
|
export XDG_CONFIG_HOME="${HOME}/.config"
|
2022-11-01 14:23:24 +01:00
|
|
|
fi
|
|
|
|
if [ -z ${XDG_DATA_HOME+x} ]; then
|
|
|
|
echo -e "${YELLOW_B}XDG_DATA_HOME is not yet set. Will use ~/.local/share${RESET}"
|
2022-11-07 00:57:18 +01:00
|
|
|
export XDG_DATA_HOME="${HOME}/.local/share"
|
2022-11-01 14:23:24 +01:00
|
|
|
fi
|
2022-11-18 01:08:45 +01:00
|
|
|
|
|
|
|
# Ensure dotfiles source directory is set and valid
|
|
|
|
if [[ ! -d "$SRC_DIR" ]] && [[ ! -d "$DOTFILES_DIR" ]]; then
|
|
|
|
echo -e "${YELLOW_B}Destination direcory not set,"\
|
|
|
|
"defaulting to $HOME/.dotfiles\n"\
|
|
|
|
"${CYAN_B}To specify where you'd like dotfiles to be downloaded to,"\
|
|
|
|
"set the DOTFILES_DIR environmental variable, and re-run.${RESET}"
|
|
|
|
DOTFILES_DIR="${HOME}/.dotfiles"
|
2022-11-01 14:23:24 +01:00
|
|
|
fi
|
2022-08-10 13:07:57 +02:00
|
|
|
}
|
|
|
|
|
2022-08-11 11:22:22 +02:00
|
|
|
# Downloads / updates dotfiles and symlinks them
|
2022-08-10 13:07:57 +02:00
|
|
|
function setup_dot_files () {
|
|
|
|
|
2022-11-18 01:08:45 +01:00
|
|
|
# If dotfiles not yet present, clone the repo
|
|
|
|
if [[ ! -d "$DOTFILES_DIR" ]]; then
|
|
|
|
echo -e "${PURPLE}Dotfiles not yet present."\
|
|
|
|
"Downloading ${REPO_NAME} into ${DOTFILES_DIR}${RESET}"
|
|
|
|
echo -e "${YELLOW_B}You can change where dotfiles will be saved to,"\
|
|
|
|
"by setting the DOTFILES_DIR env var${RESET}"
|
|
|
|
mkdir -p "${DOTFILES_DIR}" && \
|
|
|
|
git clone --recursive ${DOTFILES_REPO} ${DOTFILES_DIR} && \
|
|
|
|
cd "${DOTFILES_DIR}"
|
|
|
|
else # Dotfiles already downloaded, just fetch latest changes
|
2022-08-29 00:15:42 +02:00
|
|
|
echo -e "${PURPLE}Pulling changes from ${REPO_NAME} into ${DOTFILES_DIR}${RESET}"
|
2022-11-01 14:23:24 +01:00
|
|
|
cd "${DOTFILES_DIR}" && \
|
|
|
|
git pull origin master && \
|
2022-11-18 01:08:45 +01:00
|
|
|
echo -e "${PURPLE}Updating submodules${RESET}" && \
|
2022-11-01 14:23:24 +01:00
|
|
|
git submodule update --recursive --remote --init
|
2022-08-10 13:07:57 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If git clone / pull failed, then exit with error
|
2022-11-18 01:08:45 +01:00
|
|
|
if ! test "$?" -eq 0; then
|
2023-06-13 23:30:33 +02:00
|
|
|
echo -e >&2 "${RED_B}Failed to fetch dotfiles from git${RESET}"
|
2022-08-11 11:22:22 +02:00
|
|
|
terminate
|
2022-08-10 13:07:57 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Set up symlinks with dotbot
|
2022-08-29 00:15:42 +02:00
|
|
|
echo -e "${PURPLE}Setting up Symlinks${RESET}"
|
2022-08-10 13:07:57 +02:00
|
|
|
cd "${DOTFILES_DIR}"
|
|
|
|
git -C "${DOTBOT_DIR}" submodule sync --quiet --recursive
|
|
|
|
git submodule update --init --recursive "${DOTBOT_DIR}"
|
2022-11-04 21:15:14 +01:00
|
|
|
chmod +x lib/dotbot/bin/dotbot
|
2022-09-13 14:29:13 +02:00
|
|
|
"${DOTFILES_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${DOTFILES_DIR}" -c "${SYMLINK_FILE}" "${@}"
|
2022-08-10 13:07:57 +02:00
|
|
|
}
|
|
|
|
|
2022-08-28 23:10:28 +02:00
|
|
|
# Applies application-specific preferences, and runs some setup tasks
|
|
|
|
function apply_preferences () {
|
|
|
|
|
|
|
|
# If ZSH not the default shell, ask user if they'd like to set it
|
|
|
|
if [[ $SHELL != *"zsh"* ]] && command_exists zsh; then
|
2022-11-04 21:15:14 +01:00
|
|
|
echo -e "\n${CYAN_B}Would you like to set ZSH as your default shell? (y/N)${RESET}"
|
2022-10-27 00:13:53 +02:00
|
|
|
read -t $PROMPT_TIMEOUT -n 1 -r ans_zsh
|
2022-10-28 14:05:43 +02:00
|
|
|
if [[ $ans_zsh =~ ^[Yy]$ ]] || [[ $AUTO_YES = true ]] ; then
|
2022-08-29 00:15:42 +02:00
|
|
|
echo -e "${PURPLE}Setting ZSH as default shell${RESET}"
|
2022-08-28 23:10:28 +02:00
|
|
|
chsh -s $(which zsh) $USER
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-11-04 21:15:14 +01:00
|
|
|
# Prompt user to update ZSH, Tmux and Vim plugins, then reload each
|
|
|
|
echo -e "\n${CYAN_B}Would you like to install / update ZSH, Tmux and Vim plugins? (y/N)${RESET}"
|
|
|
|
read -t $PROMPT_TIMEOUT -n 1 -r ans_cliplugins
|
|
|
|
if [[ $ans_cliplugins =~ ^[Yy]$ ]] || [[ $AUTO_YES = true ]] ; then
|
|
|
|
# Install / update vim plugins with Plug
|
|
|
|
echo -e "\n${PURPLE}Installing Vim Plugins${RESET}"
|
|
|
|
vim +PlugInstall +qall
|
|
|
|
|
|
|
|
# Install / update Tmux plugins with TPM
|
|
|
|
echo -e "${PURPLE}Installing TMUX Plugins${RESET}"
|
|
|
|
chmod ug+x "${XDG_DATA_HOME}/tmux/tpm"
|
|
|
|
sh "${TMUX_PLUGIN_MANAGER_PATH}/tpm/bin/install_plugins"
|
|
|
|
sh "${XDG_DATA_HOME}/tmux/plugins/tpm/bin/install_plugins"
|
|
|
|
|
|
|
|
# Install / update ZSH plugins with Antigen
|
|
|
|
echo -e "${PURPLE}Installing ZSH Plugins${RESET}"
|
|
|
|
/bin/zsh -i -c "antigen update && antigen-apply"
|
|
|
|
fi
|
2022-09-23 20:54:18 +02:00
|
|
|
|
|
|
|
# Apply general system, app and OS security preferences (prompt user first)
|
2022-11-10 06:46:14 +01:00
|
|
|
echo -e "\n${CYAN_B}Would you like to apply system preferences? (y/N)${RESET}"
|
2022-10-27 00:13:53 +02:00
|
|
|
read -t $PROMPT_TIMEOUT -n 1 -r ans_syspref
|
2022-10-28 14:05:43 +02:00
|
|
|
if [[ $ans_syspref =~ ^[Yy]$ ]] || [[ $AUTO_YES = true ]]; then
|
2022-10-11 19:27:33 +02:00
|
|
|
if [ "$SYSTEM_TYPE" = "Darwin" ]; then
|
2022-11-10 06:46:14 +01:00
|
|
|
echo -e "\n${PURPLE}Applying MacOS system preferences,\
|
|
|
|
ensure you've understood before proceeding${RESET}\n"
|
2022-10-27 00:13:53 +02:00
|
|
|
macos_settings_dir="$DOTFILES_DIR/scripts/macos-setup"
|
2022-09-23 20:54:18 +02:00
|
|
|
for macScript in "macos-security.sh" "macos-preferences.sh" "macos-apps.sh"; do
|
2022-11-10 06:46:14 +01:00
|
|
|
chmod +x $macos_settings_dir/$macScript && \
|
|
|
|
$macos_settings_dir/$macScript --quick-exit --yes-to-all
|
2022-09-23 20:54:18 +02:00
|
|
|
done
|
2022-11-18 21:09:36 +01:00
|
|
|
else
|
|
|
|
echo -e "\n${PURPLE}Applying preferences to GNOME apps, ensure you've understood before proceeding${RESET}\n"
|
|
|
|
dconf_script="$DOTFILES_DIR/scripts/linux/dconf-prefs.sh"
|
|
|
|
chmod +x $dconf_script && $dconf_script
|
2022-09-23 20:54:18 +02:00
|
|
|
fi
|
|
|
|
fi
|
2022-08-28 23:10:28 +02:00
|
|
|
}
|
|
|
|
|
2022-09-13 14:29:13 +02:00
|
|
|
# Setup Brew, install / update packages, organize launchpad and checks for macOS updates
|
2022-09-08 21:45:44 +02:00
|
|
|
function intall_macos_packages () {
|
|
|
|
# Homebrew not installed, ask user if they'd like to download it now
|
|
|
|
if ! command_exists brew; then
|
2022-10-27 00:13:53 +02:00
|
|
|
echo -e "\n${CYAN_B}Would you like to install Homebrew? (y/N)${RESET}"
|
|
|
|
read -t $PROMPT_TIMEOUT -n 1 -r ans_homebrewins
|
2022-10-28 14:05:43 +02:00
|
|
|
if [[ $ans_homebrewins =~ ^[Yy]$ ]] || [[ $AUTO_YES = true ]] ; then
|
2022-09-13 14:29:13 +02:00
|
|
|
echo -en "🍺 ${PURPLE}Installing Homebrew...${RESET}\n"
|
2022-11-10 06:46:14 +01:00
|
|
|
brew_url='https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh'
|
|
|
|
/bin/bash -c "$(curl -fsSL $brew_url)"
|
2022-09-08 21:45:44 +02:00
|
|
|
export PATH=/opt/homebrew/bin:$PATH
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# Update / Install the Homebrew packages in ~/.Brewfile
|
2022-10-27 00:13:53 +02:00
|
|
|
if command_exists brew && [ -f "$DOTFILES_DIR/scripts/installs/Brewfile" ]; then
|
2022-09-23 20:54:18 +02:00
|
|
|
echo -e "\n${PURPLE}Updating homebrew and packages...${RESET}"
|
2022-10-18 21:04:56 +02:00
|
|
|
brew update # Update Brew to latest version
|
|
|
|
brew upgrade # Upgrade all installed casks
|
|
|
|
brew bundle --global --file $HOME/.Brewfile # Install all listed Brew apps
|
|
|
|
brew cleanup # Remove stale lock files and outdated downloads
|
|
|
|
killall Finder # Restart finder (required for some apps)
|
2022-09-13 14:29:13 +02:00
|
|
|
else
|
|
|
|
echo -e "${PURPLE}Skipping Homebrew as requirements not met${RESET}"
|
2022-09-08 21:45:44 +02:00
|
|
|
fi
|
|
|
|
# Restore launchpad structure with lporg
|
2022-10-27 00:13:53 +02:00
|
|
|
launchpad_layout="${DOTFILES_DIR}/config/macos/launchpad.yml"
|
2022-09-23 20:54:18 +02:00
|
|
|
if command_exists lporg && [ -f $launchpad_layout ]; then
|
2022-10-28 14:05:43 +02:00
|
|
|
echo -e "\n${CYAN_B}Would you like to restore launchpad layout? (y/N)${RESET}"
|
|
|
|
read -t $PROMPT_TIMEOUT -n 1 -r ans_restorelayout
|
|
|
|
if [[ $ans_restorelayout =~ ^[Yy]$ ]] || [[ $AUTO_YES = true ]] ; then
|
|
|
|
echo -e "${PURPLE}Restoring Launchpad Layout...${RESET}"
|
|
|
|
yes "" | lporg load $launchpad_layout
|
|
|
|
fi
|
2022-09-08 21:45:44 +02:00
|
|
|
fi
|
|
|
|
# Check for MacOS software updates, and ask user if they'd like to install
|
2022-10-28 14:05:43 +02:00
|
|
|
echo -e "\n${CYAN_B}Would you like to check for OX X system updates? (y/N)${RESET}"
|
|
|
|
read -t $PROMPT_TIMEOUT -n 1 -r ans_macoscheck
|
|
|
|
if [[ $ans_macoscheck =~ ^[Yy]$ ]] || [[ $AUTO_YES = true ]] ; then
|
|
|
|
echo -e "${PURPLE}Checking for software updates...${RESET}"
|
|
|
|
pending_updates=$(softwareupdate -l 2>&1)
|
|
|
|
if [[ ! $pending_updates == *"No new software available."* ]]; then
|
|
|
|
echo -e "${PURPLE}A new version of Mac OS is availbile${RESET}"
|
|
|
|
echo -e "${CYAN_B}Would you like to update to the latest version of MacOS? (y/N)${RESET}"
|
|
|
|
read -t $PROMPT_TIMEOUT -n 1 -r ans_macosupdate
|
|
|
|
if [[ $ans_macosupdate =~ ^[Yy]$ ]] || [[ $AUTO_YES = true ]]; then
|
|
|
|
echo -e "${PURPLE}Updating MacOS${RESET}"
|
|
|
|
softwareupdate -i -a
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo -e "${GREEN}System is up-to-date."\
|
|
|
|
"Running $(sw_vers -productName) version $(sw_vers -productVersion)${RESET}"
|
2022-09-08 21:45:44 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-08-11 11:22:22 +02:00
|
|
|
# Based on system type, uses appropriate package manager to install / updates apps
|
2022-08-10 13:07:57 +02:00
|
|
|
function install_packages () {
|
2022-10-27 00:13:53 +02:00
|
|
|
echo -e "\n${CYAN_B}Would you like to install / update system packages? (y/N)${RESET}"
|
|
|
|
read -t $PROMPT_TIMEOUT -n 1 -r ans_syspackages
|
|
|
|
if [[ ! $ans_syspackages =~ ^[Yy]$ ]] && [[ $AUTO_YES != true ]] ; then
|
2022-11-07 00:57:18 +01:00
|
|
|
echo -e "\n${PURPLE}Skipping package installs${RESET}"
|
2022-08-28 23:10:28 +02:00
|
|
|
return
|
|
|
|
fi
|
2022-10-11 19:27:33 +02:00
|
|
|
if [ "$SYSTEM_TYPE" = "Darwin" ]; then
|
2022-10-09 02:14:13 +02:00
|
|
|
# Mac OS
|
2022-09-08 21:45:44 +02:00
|
|
|
intall_macos_packages
|
2022-10-09 02:14:13 +02:00
|
|
|
elif [ -f "/etc/arch-release" ]; then
|
|
|
|
# Arch Linux
|
2022-10-27 00:13:53 +02:00
|
|
|
arch_pkg_install_script="${DOTFILES_DIR}/scripts/installs/arch-pacman.sh"
|
2022-10-09 02:14:13 +02:00
|
|
|
chmod +x $arch_pkg_install_script
|
2022-11-12 13:37:13 +01:00
|
|
|
$arch_pkg_install_script $PARAMS
|
2023-04-10 15:36:26 +02:00
|
|
|
elif [ -f "/etc/debian_version" ]; then
|
|
|
|
# Debian / Ubuntu
|
|
|
|
debian_pkg_install_script="${DOTFILES_DIR}/scripts/installs/debian-apt.sh"
|
|
|
|
chmod +x $debian_pkg_install_script
|
|
|
|
$debian_pkg_install_script $PARAMS
|
2022-08-28 23:10:28 +02:00
|
|
|
fi
|
2022-09-25 15:12:51 +02:00
|
|
|
# If running in Linux desktop mode, prompt to install desktop apps via Flatpak
|
2022-10-27 00:13:53 +02:00
|
|
|
flatpak_script="${DOTFILES_DIR}/scripts/installs/flatpak.sh"
|
2022-11-12 13:37:13 +01:00
|
|
|
if [[ $SYSTEM_TYPE == "Linux" ]] && [ ! -z $XDG_CURRENT_DESKTOP ] && [ -f $flatpak_script ]; then
|
2022-09-25 15:12:51 +02:00
|
|
|
chmod +x $flatpak_script
|
2022-11-12 13:37:13 +01:00
|
|
|
$flatpak_script $PARAMS
|
2022-09-25 15:12:51 +02:00
|
|
|
fi
|
2022-08-10 13:07:57 +02:00
|
|
|
}
|
|
|
|
|
2022-08-11 11:22:22 +02:00
|
|
|
# Updates current session, and outputs summary
|
2022-08-10 13:07:57 +02:00
|
|
|
function finishing_up () {
|
|
|
|
# Update source to ZSH entry point
|
|
|
|
source "${HOME}/.zshenv"
|
|
|
|
|
2022-10-27 00:13:53 +02:00
|
|
|
# Calculate time taken
|
2022-10-11 19:27:33 +02:00
|
|
|
total_time=$((`date +%s`-START_TIME))
|
2022-10-18 21:04:56 +02:00
|
|
|
if [[ $total_time -gt 60 ]]; then
|
|
|
|
total_time="$(($total_time/60)) minutes"
|
|
|
|
else
|
|
|
|
total_time="${total_time} seconds"
|
|
|
|
fi
|
|
|
|
|
2022-10-27 00:13:53 +02:00
|
|
|
# Print success msg and pretty picture
|
2022-10-18 21:04:56 +02:00
|
|
|
make_banner "✨ Dotfiles configured succesfully in $total_time" ${GREEN_B} 1
|
2022-09-23 20:54:18 +02:00
|
|
|
echo -e "\033[0;92m .--.\n |o_o |\n |:_/ |\n // \
|
|
|
|
\ \\ \n (| | ) \n /'\_ _/\`\\ \n \\___)=(___/\n"
|
2022-10-27 00:13:53 +02:00
|
|
|
|
2022-09-23 18:37:34 +02:00
|
|
|
# Refresh ZSH sesssion
|
|
|
|
SKIP_WELCOME=true || exec zsh
|
|
|
|
|
2022-11-10 06:46:14 +01:00
|
|
|
# Show popup
|
2022-11-17 13:52:03 +01:00
|
|
|
if command_exists terminal-notifier; then
|
|
|
|
terminal-notifier -group 'dotfiles' -title $TITLE -subtitle 'All Tasks Complete' \
|
|
|
|
-message "Your dotfiles are now configured and ready to use 🥳" \
|
|
|
|
-appIcon ./.github/logo.png -contentImage ./.github/logo.png \
|
|
|
|
-remove 'ALL' -sound 'Sosumi' &> /dev/null
|
|
|
|
fi
|
2022-11-10 06:46:14 +01:00
|
|
|
|
2022-10-27 00:13:53 +02:00
|
|
|
# Show press any key to exit
|
2022-09-23 20:54:18 +02:00
|
|
|
echo -e "${CYAN_B}Press any key to exit.${RESET}\n"
|
|
|
|
read -t $PROMPT_TIMEOUT -n 1 -s
|
2022-10-27 00:13:53 +02:00
|
|
|
|
|
|
|
# Bye
|
2022-08-10 13:07:57 +02:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2022-11-08 21:22:55 +01:00
|
|
|
# Trigger cleanup on exit
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2022-09-23 20:54:18 +02:00
|
|
|
# If --help flag passed in, just show the help menu
|
2022-10-11 19:27:33 +02:00
|
|
|
if [[ $PARAMS == *"--help"* ]]; then
|
2022-09-23 20:54:18 +02:00
|
|
|
make_intro
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-09-13 14:29:13 +02:00
|
|
|
# Let's Begin!
|
2022-08-10 13:07:57 +02:00
|
|
|
pre_setup_tasks # Print start message, and check requirements are met
|
2023-06-13 23:30:33 +02:00
|
|
|
setup_dot_files # Clone / update dotfiles, and create the symlinks
|
2022-08-11 11:22:22 +02:00
|
|
|
install_packages # Prompt to install / update OS-specific packages
|
2022-09-23 20:54:18 +02:00
|
|
|
apply_preferences # Apply settings for individual applications
|
2022-09-13 14:29:13 +02:00
|
|
|
finishing_up # Refresh current session, print summary and exit
|
|
|
|
# All done :)
|