diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index a40b0af..ae04004 --- a/install.sh +++ b/install.sh @@ -1,39 +1,13 @@ #!/usr/bin/env bash +source "./public.bash" + # Current User user=$(id -un) -# Script's color palette -reset="\033[0m" -highlight="\033[42m\033[97m" -dot="\033[33m▸ $reset" -dim="\033[2m" -bold="\033[1m" - # Keep-alive: update existing `sudo` time stamp until script has finished while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & -headline() { - printf "${highlight} %s ${reset}\n" "$@" -} - -chapter() { - echo "${highlight} $((count++)).) $@ ${reset}\n" -} - -# Prints out a step, if last parameter is true then without an ending newline -step() { - if [ $# -eq 1 ] - then echo "${dot}$@" - else echo "${dot}$@" - fi -} - -run() { - echo "${dim}▹ $@ $reset" - eval $@ -} - echo "" headline " Let's secure your Mac and install basic applications." echo "" @@ -257,6 +231,26 @@ else echo "${dim}▹ Facebook domains already blocked. $reset" fi +# Download Packaged Software +# Some software comes packaged directly from the vendor +# Eventually we'll automate the installs of each of these +# But the biggest challenege is just remembering +# Which apps you need to download, so let's do that for now + +download_file "https://download.mozilla.org/?product=firefox-latest-ssl&os=osx&lang=en-US" "firefox-latest.dmg" + +download_file "https://app-updates.agilebits.com/download/OPM7" "1password-latest.pkg" + +download_file "https://iterm2.com/downloads/stable/iTerm2-3_2_9.zip" "iTerm2-3_2_9.zip" + +download_file "https://discordapp.com/api/download?platform=osx" "discord-latest.dmg" + +download_file "https://dl.iina.io/IINA.v1.0.4.dmg" "IINA.v1.0.4.dmg" + +download_file "https://cdn-fastly.obsproject.com/downloads/obs-mac-23.2.1-installer.pkg" "obs-mac-23.2.1-installer.pkg" + +download_file "https://www.kaleidoscopeapp.com/download" "kaleidoscope-latest.zip" + # Install Applications # Note: Before installing Homebrew, set the following settings in your .bash_profile for increased privacy. @@ -281,6 +275,9 @@ run defaults write com.apple.iTunes DeviceBackupsDisabled -bool true echo "Install jq." run brew install jq +echo "Install tldr." +run brew install tldr + echo "Install Habitat." run brew tap habitat-sh/habitat run brew install hab @@ -313,9 +310,6 @@ run brew install shellcheck echo "Install pre-commit" run brew install pre-commit -echo "Install spectacle." -run brew cask install spectacle - echo "Install docker." run brew cask install docker @@ -328,7 +322,6 @@ run brew cask install licecap echo "Install Visual Studio Code." run brew cask install visual-studio-code -testing code commit echo "Install Visual Studio Code Extensions." vscode_install_ext(){ run code --install-extension $@ diff --git a/public.bash b/public.bash new file mode 100644 index 0000000..5f631f9 --- /dev/null +++ b/public.bash @@ -0,0 +1,103 @@ +# These functions are the public API used by install.sh + +# Script's color palette +reset="\033[0m" +highlight="\033[42m\033[97m" +dot="\033[33m▸ $reset" +dim="\033[2m" +bold="\033[1m" + +headline() { + printf "${highlight} %s ${reset}\n" "$@" +} + +chapter() { + echo "${highlight} $((count++)).) $@ ${reset}\n" +} + +# Prints out a step, if last parameter is true then without an ending newline +step() { + if [ $# -eq 1 ] + then echo "${dot}$@" + else echo "${dot}$@" + fi +} + +run() { + echo "${dim}▹ $@ $reset" + eval $@ +} + +# Downloads a file from a source URL to a local file. +# uses an optional shasum to determine if an existing file can be used. +# +# If an existing file is present and the third argument is set with a shasum +# digest, the file will be checked to see if it's valid. If so, the function +# ends early and returns 0. Otherwise, the shasums do not match so the +# file-on-disk is removed and a normal download proceeds as though no previous +# file existed. This is designed to restart an interrupted download. +# +# Any valid `curl` URL will work. +# +# ```sh +# download_file http://example.com/file.tar.gz file.tar.gz +# # Downloads every time, even if the file exists locally +# download_file http://example.com/file.tar.gz file.tar.gz abc123... +# # Downloads if no local file is found +# download_file http://example.com/file.tar.gz file.tar.gz abc123... +# # File matches checksum: download is skipped, local file is used +# download_file http://example.com/file.tar.gz file.tar.gz oh noes... +# # File doesn't match checksum: local file removed, download attempted +# ``` +# +# Will return 0 if a file was downloaded or if a valid cached file was found. +download_file() { + local url="$1" + local dst="$HOME/Downloads/$2" + local sha="$3" + _curl_cmd=$(command -v curl) + pushd "$HOME/Downloads" > /dev/null + if [[ -f $dst && -n "$sha" ]]; then + echo "Found previous file '$dst', attempting to re-use" + if verify_file "$dst" "$sha"; then + echo "Using cached and verified '$dst'" + return 0 + else + echo "Clearing previous '$dst' file and re-attempting download" + rm -fv "$dst" + fi + fi + + echo "Downloading '$url' to '$dst'" + # shellcheck disable=2154 + $_curl_cmd -L "$url" -o "$dst" + echo "Downloaded '$dst'"; + popd > /dev/null +} + +# Verifies that a file on disk matches the given shasum. If the given shasum +# doesn't match the file's shasum then a warning is printed with the expected +# and computed shasum values. +# +# ```sh +# verify_file file.tar.gz abc123... +# ``` +# +# Will return 0 if the shasums match, and 1 if they do not match. A message +# will be printed to stderr with the expected and computed shasum values. +verify_file() { + echo "Verifying $1" + local checksum + _openssl_cmd=$(command -v openssl) + # shellcheck disable=2154 + read -r checksum _ < <($_openssl_cmd dgst -sha256 "$1" | cut -d'=' -f2) + if [[ $2 = "$checksum" ]]; then + echo "Checksum verified for $1" + else + echo "Checksum invalid for $1:" + echo " Expected: $2" + echo " Computed: ${checksum}" + return 1 + fi + return 0 +} \ No newline at end of file