Skip to content

Instantly share code, notes, and snippets.

@letrome
Created April 22, 2024 12:06
Show Gist options
  • Save letrome/528efe6f11525017bdfdb8127dddb368 to your computer and use it in GitHub Desktop.
Save letrome/528efe6f11525017bdfdb8127dddb368 to your computer and use it in GitHub Desktop.
#! /bin/zsh
default_browser="arc"
install_list="wget git fortune cowthink vim shpotify newman docker docker-compose duti defaultbrowser"
install_cask_list="arc google-chrome notion 1password 1password-cli viscosity postman github iterm2 slack deepl visual-studio-code linear-linear spotify whatsapp sublime-text jetbrains-toolbox the-unarchiver vnc-viewer vlc"
plugins_ohmyzsh="git 1password aliases chucknorris codeclimate colored-man-pages colorize command-not-found docker docker-compose encode64 extract jsontools sublime themes vscode web-search"
encrypted_spotify_creds="#encrypted-spotify-creds"
vlc_association="mp3 avi asf wmv wma mp4 mov 3gp ogg ogm wav flac midi"
fleet_association="txt json xml java py sh log scala sc php gitignore md"
failed_install=""
success_install="homebrew"
printf "STEP 1. Software installation\n"
printf " install homebrew ...\n"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
return_code=$?
if [ ${return_code} -ne 0 ] ; then
printf " install homebrew ... \e[31mFAILURE\e[0m\n"
exit ${return_code}
else
printf " install homebrew ... \e[32mSUCCESS\e[0m\n"
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> "${HOME}"/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
fi
for package in $(echo $install_list) ; do
printf " install %s ...\n" "${package}"
brew install "${package}"
return_code=$?
if [ $return_code -ne 0 ] ; then
printf " install %s ... \e[31mFAILURE\e[0m\n" "${package}"
if [ ${#failed_install} -le 0 ] ; then delim="" ; else delim=" " ; fi
failed_install=$failed_install$delim$package
else
if [ "${package}" = "vim" ] ; then
printf " create .vimrc and set default configuration values ... "
printf "syntax on\n" > ~/.vimrc
printf "\e[32mDONE\e[0m\n"
elif [ "${package}" = "shpotify" ] ; then
printf " create .shpotify.cfg and set CLIENT_ID and CLIENT_SECRET ...\n"
echo "${encrypted_spotify_creds}" | openssl enc -d -aes-256-cbc -a -pbkdf2 > "${HOME}"/.shpotify.cfg
printf " create .shpotify.cfg and set CLIENT_ID and CLIENT_SECRET ... \e[32mDONE\e[0m\n"
fi
printf " install %s ... \e[32mSUCCESS\e[0m\n" "${package}"
success_install=$success_install" "$package
fi
done
for package in $(echo $install_cask_list) ; do
printf " install %s ...\n" "${package}"
brew install --cask "${package}"
return_code=$?
if [ $return_code -ne 0 ] ; then
printf " install %s ... \e[31mFAILURE\e[0m\n" "${package}"
if [ ${#failed_install} -le 0 ] ; then delim="" ; else delim=" " ; fi
failed_install=$failed_install$delim$package
else
if [ "${package}" = "1password" ] ; then
printf " create .ssh/config and add 1password binding configuration ... "
mkdir "${HOME}"/.ssh &> /dev/null
printf "Host *\n AddKeysToAgent yes\n IdentityAgent \"~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock\"\n" > ~/.ssh/config
printf "\e[32mDONE\e[0m\n"
elif [ "${package}" = "google-chrome" -a "${default_browser}" = "chrome" ] ; then
printf " setup chrome as the default browser ... "
defaultbrowser chrome
printf "\e[32mDONE\e[0m\n"
elif [ "${package}" = "arc" -a "${default_browser}" = "arc" ] ; then
printf " setup arc as the default browser ... "
defaultbrowser browser
printf "\e[32mDONE\e[0m\n"
fi
printf " install %s ... \e[32mSUCCESS\e[0m\n" "${package}"
success_install=$success_install" "$package
fi
done
printf "\n ✅ Successfully installed:\n %s\n" "${success_install}"
if [ ${#failed_install} -gt 0 ] ; then
printf " ❌ Error during installation:\n %s\n" "${failed_install}"
fi
printf "\nSTEP 2. Terminal configuration\n"
printf " STEP 2.1. Install oh my zsh ... "
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" &> /dev/null
printf "\e[32mSUCCESS\e[0m\n\n"
printf " STEP 2.2. Setup and install plugins\n"
printf " enable plugins ...\n"
printf " the following list of plugin will be enabled:\n"
printf " %s\n" "${plugins_ohmyzsh}"
sed -i '' "s/plugins=(git)/plugins=(${plugins_ohmyzsh})/g" ~/.zshrc
failed_plugins=$(source ~/.zshrc 2>&1)
if [ ${#failed_plugins} -gt 0 ] ; then
printf " enable plugins ... \e[33mWARNING\e[0m\n"
printf " error for the following plugins:\n"
printf " - %s" "$(echo "${failed_plugins}" | cut -d ' ' -f3 | cut -d "'" -f2)"
else
printf " enable plugins ... \e[32mSUCCESS\e[0m\n\n"
fi
printf " STEP 2.3. Update theme\n"
printf " enable theme 'gozilla' ... "
sed -i '' "s/ZSH_THEME=\"robbyrussell\"/ZSH_THEME=\"gozilla\"/g" ~/.zshrc
source ~/.zshrc &> /dev/null
printf "\e[32mSUCCESS\e[0m\n\n"
printf " STEP 2.4. Creating aliases\n"
printf " add alias 'brewette' ... "
printf "function brewette() {
brew update
brew upgrade
brew upgrade —cask
brew cleanup
}\n\n" >> ~/.zshrc
printf "\e[32mSUCCESS\e[0m\n"
printf " add alias 'decrypt' ... "
printf "function decrypt(){
to_decrypt=\"\"
output_file=\"\"
for param in \"\$@\" ; do
key=\$(echo \"\$param\" | cut -d\"=\" -f1)
value=\$(echo \"\$param\" | cut -d\"=\" -f2)
if [ \"\${key}\" = \"input\" ] ; then
to_decrypt=\$(cat \"\${value}\")
elif [ \"\${key}\" = \"output\" ] ; then
output_file=\$value
fi
done
if [ \${#to_decrypt} -eq 0 ] ; then
read -r to_decrypt;
fi
decrypted_value=\$(echo \"\${to_decrypt}\" | openssl enc -d -aes-256-cbc -a -pbkdf2)
if [ \${#output_file} -ne 0 ] ; then
echo \"\${decrypted_value}\" > \"\${output_file}\"
else
echo \"\${decrypted_value}\"
fi
}\n\n" >> ~/.zshrc
printf "\e[32mSUCCESS\e[0m\n"
source ~/.zshrc &> /dev/null
printf "\nSTEP 3. Files association\n"
while [ ! -d ~/Applications/Fleet.app -a ! -d ~/Applications/Fleet.app ] ; do
printf "Please install Fleet from Toolbox then press ENTER to continue ..."
open -a /Applications/JetBrains\ Toolbox.app
read
done
for file_extension in $(echo $fleet_association) ; do
printf " Set Fleet as default application for extention .%s ... " ${file_extension}
duti -s Fleet.app ".${file_extension}" all
printf "\e[32mDONE\e[0m\n"
done
while [ ! -d ~/Applications/VLC.app -a ! -d ~/Applications/VLC.app ] ; do
printf "Please install VLC then press ENTER to continue ..."
read
done
for file_extension in $(echo $vlc_association) ; do
printf " Set VLC as default application for extention .%s ... " ${file_extension}
duti -s org.videolan.vlc ".${file_extension}" all
printf "\e[32mDONE\e[0m\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment