Skip to content

Commit

Permalink
Begin adding a functional MacOS variant.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oracle authored and Oracle committed Jun 1, 2024
1 parent 1a4e2cf commit f4345d5
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ git-tmp/*
TODO.md
*.log
runcoms/bashrc
install_homebrew.sh
keep
13 changes: 8 additions & 5 deletions lib/pkg-helpers.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/bash

#
# Apt
#
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
# Ensure Package ✦
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦

ensure_package_installed() {


local -r pkg_name="${*}"

if dpkg -l | grep --quiet "${pkg_name}"; then
Expand Down Expand Up @@ -52,10 +54,11 @@ sync_git_repo() {
local name="${2}"
local path="${3:-.}"

if quiet_pushd "${path}/${name}"; then
if [ -d "${path}/${name}" ]; then
pushd "${path}/${name}"
>&3 git fetch
if repo_is_out_of_date; then
2>&3 git pull origin master
2>&3 git pull
fi
log "${name} up to date"
quiet_popd
Expand Down
16 changes: 14 additions & 2 deletions lib/system-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
wait_for_user() {
local -r msg="${*}"

notify-send "$0" "${msg}"
2>&3 >&3 paplay --volume=41000 '/usr/share/sounds/freedesktop/stereo/complete.oga'
case "$(uname)" in
Darwin)
terminal-notifier -sound default <<< "${msg}"
;;
Linux)
notify-send "$0" "${msg}"
2>&3 >&3 paplay --volume=41000 '/usr/share/sounds/freedesktop/stereo/complete.oga'
;;
esac


read -n 1 -s -r -p "Press any key to continue"
printf "\r"
Expand Down Expand Up @@ -40,3 +48,7 @@ safe_copy() {
exit 2
fi
}

os-name() {
tr '[:upper:]' '[:lower:]' <<< "$(uname)"
}
99 changes: 99 additions & 0 deletions lib_darwin/pkg-helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash -e

# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
# Prerequisite Packages ✦
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦

install_missing_package_manager() {
if which -s brew; then
log_info "Homebrew already installed."
else
# May 2024
local -r url="https://raw.githubusercontent.com/Homebrew/install/e65f88c8b7a49ce741a7092ab22774d2fdd798c0/install.sh"
local -r checksum="67b0989bd0a404cdd32c1df20e3fb724b7c278c83a068fd5a16dac6f8d317a79"
local -r script_name="install_homebrew.sh"

curl -o "${script_name}" "${url}"
shasum -c - <<< "${checksum} ${script_name}"

NONINTERACTIVE=1 bash "${script_name}"
fi

brew cleanup
brew update --force --quiet
brew doctor
}

ensure_package_installed() {
local -r package_name="${1}"
log_info "checking for ${package_name}"
if brew list | grep --quiet "${package_name}"; then
log_info "${package_name} already installed"
else
brew install "${package_name}"
log_info "${package_name} installed"
fi
}


# ✦✦✦✦✦
# Git ✦
# ✦✦✦✦✦

clone_github_repo() {
local -r clone_destination="${1:-.}"
local -r repo_author="${2}"
local -r repo_name="${3}"
local -r url="https://github.com/${repo_author}/${repo_name}.git"

local git_option='--'
if [ "${VERBOSITY:-normal}" = 'low' ]; then
git_option='--quiet'
elif [ "${VERBOSITY:-normal}" = 'high' ]; then
git_option='--verbose'
fi

2>&3 >&3 git clone "${git_option}" "${url}" "${clone_destination}"
}

# See http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git
repo_is_out_of_date() {
local -r local="$( git rev-parse @ )"
local -r remote="$( git rev-parse "@{u}" )"
local -r base="$( git merge-base @ "@{u}" )"

if [ "$local" = "$remote" ]; then
return 1
elif [ "$local" = "$base" ]; then
return 0
else
log_warn "Warning: Git repo has diverged. Skipping..."
fi
}

sync_git_repo() {
local author="${1}"
local name="${2}"
local path="${3:-.}"

if [ -d "${path}/${name}" ]; then
quiet_pushd "${path}/${name}"
>&3 git fetch
if repo_is_out_of_date; then
2>&3 git pull origin master
fi
log "${name} up to date"
quiet_popd
else
clone_github_repo "${path}/${name}" "${author}" "${name}"
log_info "${name} installed"
fi
}

# ✦✦✦✦✦
# Pip ✦
# ✦✦✦✦✦

pip_install() {
2>&3 >&3 python3 -m pip install "${*}"
}
8 changes: 8 additions & 0 deletions lib_darwin/term-helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
# Terminal Goods ✦
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦

install_dircolors() {
sync_git_repo "joshjon" "bliss-dircolors" "${REPO_ROOT}/keep"
}

120 changes: 69 additions & 51 deletions main.sh
Original file line number Diff line number Diff line change
@@ -1,93 +1,111 @@
#!/bin/bash
REPO_ROOT=/Users/mila_fa/dev/terminal-suite
#!/bin/bash -e
REPO_ROOT=$HOME/dev/terminal-suite

# ------------
# Prequisites
# ------------

# 1. Iterm set on solarized
# 2. Xcode utils
# 3. Run this script from the root of the git repo located in `~/dev`

# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
# 0. Environment setup ✦
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦

case "$(uname)" in
Darwin)
declare -r LIB_DIR="${REPO_ROOT}/lib_mac"
source "${REPO_ROOT}/lib/setup.sh"
source "${REPO_ROOT}/lib/exit-handling.sh"
source "${REPO_ROOT}/lib/logging-helpers.sh"
source "${REPO_ROOT}/lib_darwin/pkg-helpers.sh"
source "${REPO_ROOT}/lib/system-helpers.sh"
source "${REPO_ROOT}/lib_darwin/term-helpers.sh"
;;
Linux)
declare -r LIB_DIR="${REPO_ROOT}/lib"
;;
esac

declare -r MANIFEST_DIR="${REPO_ROOT}/manifests"
declare -r PYTHON_DIR="${REPO_ROOT}/setup_python"
declare -r RUNCOMS_DIR="${REPO_ROOT}/runcoms"
declare -r SOLARIZED_DIR="${REPO_ROOT}/setup_solarized"
declare -r SHELL_DIR="${REPO_ROOT}/setup_shell"
declare -r VIM_DIR="${REPO_ROOT}/setup_vim"

declare -r CLONE_DIR="${REPO_ROOT}/git-tmp"
ensure_directory_exists "${CLONE_DIR}"

#
# 0. Environment setup
#
declare -r LIB_DIR='./lib'
declare -r MANIFEST_DIR='./manifests'
declare -r PYTHON_DIR='./setup_python'
declare -r RUNCOMS_DIR='./runcoms'
declare -r SOLARIZED_DIR='./setup_solarized'
declare -r SHELL_DIR='./setup_shell'
declare -r VIM_DIR='./setup_vim'

declare -r CLONE_DIR='./git-tmp'

source "${LIB_DIR}/setup.sh"
source "${LIB_DIR}/exit-handling.sh"
source "${LIB_DIR}/logging-helpers.sh"
source "${LIB_DIR}/pkg-helpers.sh"
source "${LIB_DIR}/system-helpers.sh"
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
# 1. Install Packages ✦
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦

ensure_directory_exists "${CLONE_DIR}"
log_info 'Installing and configuring a package manager'
install_missing_package_manager

#
# 1. Install dependencies
#
log_info 'Installing various software packages'
while read -r package_name; do
ensure_package_installed "${package_name}"
done < "${MANIFEST_DIR}/$(os-name)-pkg-manifest.txt"

# log_info 'Installing various software packages'
# while read -r package_name; do
# log "checking for ${package_name}"
# ensure_package_installed "${package_name}"
# log "${package_name} installed"
# done < "${MANIFEST_DIR}/pkg-manifest.txt"
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
# 2. Solarized terminal setup ✦
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦

#
# 2. Solarized terminal setup
#
log_info 'Setting up terminal colors'
ensure_directory_exists "${REPO_ROOT}/keep"
install_dircolors

#
# 3. Vim setup
#
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦
# 3. Vim Setup ✦
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦

log_info 'Loading vim installation module'
source "${VIM_DIR}/functions.sh"

log_info 'Outfit local machine with vimrc'
install_vimrc

log_info 'Installing package vim'
ensure_directory_exists "${VIM_CONFIG_DIR}/autoload"
ensure_directory_exists "${VIM_CONFIG_DIR}/bundle"

log_info 'Installing pathogen'
ensure_pathogen_installed


log_info 'Installing vim plugins'
vim_plugin_install 'vim-plugin-manifest.txt'

log_info 'Copying Powerline fonts for terminal'
install_powerline_fonts

#
# 3a. Vim Python setup
#

log_info 'Installing flake8 for syntastic'
pip_install 'flake8'
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
# 3a. Vim Python ✦
# ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦

log_info 'Copying Python vim plugins.'
vim_plugin_install 'python-plugin-manifest.txt'

wait_for_user 'User intervention needed:'\
'Jedi requires "git submodule update --init --recursive"'
'Jedi requires "git submodule update --init --recursive"'

log_info 'Copying python virtual env autocomplete script.'
ensure_directory_exists "${VIM_CONFIG_DIR}/python"
cp -f "${PYTHON_DIR}/enable_virtual_env_autocomplete.py" "${VIM_CONFIG_DIR}/python"

#
# 3b. Vim C++ setup
#
# ✦✦✦✦✦✦✦✦✦✦✦✦✦
# 3b. Vim C++
# ✦✦✦✦✦✦✦✦✦✦✦✦✦

#TODO
#https://stackoverflow.com/questions/4237817/configuring-vim-for-c

#
# 4. Readline setup
#

log_info 'Sychronizing .inputrc'
safe_copy 'inputrc' "${SHELL_DIR}"
# log_info 'Sychronizing .inputrc'
# safe_copy 'inputrc' "${SHELL_DIR}"

#
# 5. Bashrc setup
Expand Down
18 changes: 18 additions & 0 deletions manifests/darwin-pkg-manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
bash
cmake
coreutils
curl
flake8
fzf
gcc
git
nmap
node
pyenv
terminal-notifier
the_silver_searcher
tree
vim
watch
wget
yq
1 change: 1 addition & 0 deletions manifests/python-plugin-manifest.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
davidhalter jedi-vim
nvie vim-flake8
2 changes: 2 additions & 0 deletions runcoms/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ function! SetupForPython()
" python autocomplete with virtualenv support
python3 'python/enable_virtual_env_autocomplete.py'

let g:syntastic_python_flake8_exec = 'flake8'

call ActivateSyntastic()

" vim commentary
Expand Down
3 changes: 3 additions & 0 deletions runcoms/zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
eval `gdircolors ~/dev/terminal-suite/keep/bliss-dircolors/bliss.dircolors`
export CLICOLOR=1
Loading

0 comments on commit f4345d5

Please sign in to comment.