Reorders install script, and includes system preference configuration too

This commit is contained in:
Alicia Sykes 2022-09-23 19:54:18 +01:00
parent 3ae274d91a
commit cee0a5a163

View File

@ -35,6 +35,9 @@ PURPLE='\033[0;35m'
# Other params
PROMPT_TIMEOUT=15 # When user is prompted for input, skip after x seconds
# Clear the screen
clear
# Start timer
start_time=`date +%s`
@ -54,6 +57,23 @@ make_banner () {
echo -e "\n${banner}\n${RESET}"
}
# Explain to the user what changes will be made
make_intro () {
C2="\033[0;35m"
C3="\x1b[2m"
echo -e "${CYAN_B}The seup script will do the following:${RESET}"
echo -e "${C2}(1) Pre-Setup Tasls"
echo -e " ${C3}- Check that all requirements are met, and system is compatible"
echo -e "${C2}(2) Setup Dotfiles"
echo -e " ${C3}- Clone or update dotfiles from git, and apply symlinks"
echo -e "${C2}(3) Install packages"
echo -e " ${C3}- Update packeges, and prompt to install apps"
echo -e "${C2}(4) Configure sytstem"
echo -e " ${C3}- Setup Vim, Tmux and ZSH plugins"
echo -e " ${C3}- Configure OS and apply app user preferences"
echo -e "\n${PURPLE}You will be prompted at each stage, before any changes are made.${RESET}"
}
# Checks if a given package is installed
command_exists () {
hash "$1" 2> /dev/null
@ -83,6 +103,18 @@ function pre_setup_tasks () {
# Show starting banner
make_banner "${TITLE}" "${CYAN_B}" 1
# Print list of what will be applied
make_intro
# Confirm user would like to proceed
echo -e "\n${CYAN_B}Are you happy to continue? (y/N)${RESET}"
read -t $PROMPT_TIMEOUT -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "\n${PURPLE}No worries, feel free to come back another time.\nTerminating...${RESET}"
exit 0
fi
echo
# Verify required packages are installed
system_verify "git" true
system_verify "zsh" false
@ -145,10 +177,21 @@ function apply_preferences () {
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"
# Apply general system, app and OS security preferences (prompt user first)
read -t $PROMPT_TIMEOUT -p "$(echo -e $CYAN_B)Would you like to apply system preferences? (y/N)" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ "$system_type" = "Darwin" ]; then
echo -e "\n${PURPLE}Applying MacOS system preferences, ensure you've understood before proceeding${RESET}\n"
macos_settings_dir="$DOTFILES_DIR/system-specific/macos/system-settings"
for macScript in "macos-security.sh" "macos-preferences.sh" "macos-apps.sh"; do
chmod +x $macos_settings_dir/$macScript && $macos_settings_dir/$macScript --quick-exit
done
fi
fi
}
# Setup Brew, install / update packages, organize launchpad and checks for macOS updates
@ -164,9 +207,9 @@ function intall_macos_packages () {
fi
fi
# Update / Install the Homebrew packages in ~/.Brewfile
if command_exists brew && [ -f "$HOME/.Brewfile" ]
if command_exists brew && [ -f "$DOTFILES_DIR/installs/Brewfile" ]
then
echo -e "${PURPLE}Updating homebrew and packages...${RESET}"
echo -e "\n${PURPLE}Updating homebrew and packages...${RESET}"
brew update
brew upgrade
brew bundle --global --file $HOME/.Brewfile
@ -175,17 +218,20 @@ function intall_macos_packages () {
echo -e "${PURPLE}Skipping Homebrew as requirements not met${RESET}"
fi
# Restore launchpad structure with lporg
if ! command_exists lporg && [ -f "$DOTFILES_DIR/configs/macos/launchpad.yml" ]; then
launchpad_layout="${DOTFILES_DIR}/system-specific/macos/app-configs/launchpad.yml"
if command_exists lporg && [ -f $launchpad_layout ]; then
echo -e "${PURPLE}Restoring Launchpad Layout...${RESET}"
lporg load "$DOTFILES_DIR/configs/macos/launchpad.yml"
lporg load $launchpad_layout
fi
# Check for MacOS software updates, and ask user if they'd like to install
echo -e "${PURPLE}Checking for software updates...${RESET}"
pending_updates=$(softwareupdate -l 2>&1)
if [[ ! $pending_updates == *"No new software available."* ]]; then
read -t $PROMPT_TIMEOUT -p "$(echo -e $CYAN_B)A new macOS software update is available.\
Would you like to install it now?$(echo -e $RESET) (y/N)" -n 1 -r
echo -e "${PURPLE}A new version of Mac OS is availbile${RESET}"
read -t $PROMPT_TIMEOUT -p "$(echo -e $CYAN_B)Would you like to update to the latest version of MacOS? (y/N)" -n 1 -r
echo -e "${RESET}"
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "${PURPLE}Updating MacOS${RESET}"
softwareupdate -i -a
fi
else
@ -196,16 +242,11 @@ function intall_macos_packages () {
# Based on system type, uses appropriate package manager to install / updates apps
function install_packages () {
read -t $PROMPT_TIMEOUT -p "$(echo -e $CYAN_B)Would you like to install / update system packages? (y/N) " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "\n${PURPLE}Skipping package installs${RESET}"
return
fi
# Ask for users password
echo -e "\n${PURPLE}Some install steps may require elevated permissions.${CYAN_B}\n\
You can enter your password now, to avoid typing it for each stage, or Ctrl+C to skip.${RESET}"
sudo -v
# Mac OS
if [ "$system_type" = "Darwin" ]; then
intall_macos_packages
@ -220,15 +261,25 @@ function finishing_up () {
# Print success message, and time taken
total_time=$((`date +%s`-start_time))
make_banner "✨ Dotfiles configured succesfully in $total_time seconds" ${GREEN_B} 1
echo -e "\033[0;92m .--.\n |o_o |\n |:_/ |\n // \
\ \\ \n (| | ) \n /'\_ _/\`\\ \n \\___)=(___/\n"
# Exit script with success code
echo -e "${CYAN_B}Press any key to exit.${RESET}\n"
read -t $PROMPT_TIMEOUT -n 1 -s
exit 0
}
# If --help flag passed in, just show the help menu
if [[ $* == "--help" ]]; then
make_intro
exit 0
fi
# Let's Begin!
pre_setup_tasks # Print start message, and check requirements are met
setup_dot_files # Clone / updatae dotfiles, and create the symlinks
apply_preferences # Apply settings for individual applications
install_packages # Prompt to install / update OS-specific packages
apply_preferences # Apply settings for individual applications
finishing_up # Refresh current session, print summary and exit
# All done :)