Skip to content

Instantly share code, notes, and snippets.

@Larusso
Last active January 4, 2021 19:54
Show Gist options
  • Save Larusso/6c2efb47c69846252613d54f30d9cdb2 to your computer and use it in GitHub Desktop.
Save Larusso/6c2efb47c69846252613d54f30d9cdb2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
#
# Bootstrap program for the system.
#
# Enable the default zsh options
emulate zsh
setopt errexit # exit the script if any statement returns a non-true valu
setopt pipefail # unveil hidden pipeline command errors
setopt extendedglob # enable '#', '~', '^' operators and flags in patterns
# Detect the platform (similar to $OSTYPE)
os="$(uname)"
distro="unknown"
case $os in
'Linux')
os='Linux'
if [ -f /etc/os-release ]; then
. /etc/os-release
distro=$ID
fi
;;
'WindowsNT')
os='Windows'
;;
'Darwin')
os='macOS'
;;
*) ;;
esac
print -P "%F{green}::%f detected OS $os and distro $distro"
# install yay if missing
function install_yay {
if ! command -v yay >/dev/null 2>&1; then
print -P "%F{blue}::%f installing yay dependencies ..."
sudo pacman -S --needed git base-devel
print -P "%F{blue}::%f installing yay ..."
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
fi
}
# install homebrew if missing
function init_homebrew {
print -P "%F{blue}::%f init homebrew ..."
if ! command -v brew >/dev/null 2>&1; then
print -P "%F{blue}::%f installing homebrew ..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
}
# bootstrap yadm
function init_yadm {
print -P "%F{blue}::%f init yadm dotfile manager ..."
yadm_tmp=$(mktemp -d -t yadm-XXXXXXX)
yadm="$yadm_tmp/yadm"
PATH=$yadm_tmp:$PATH
curl -fLo $yadm https://github.com/TheLocehiliosan/yadm/raw/master/yadm
chmod a+x $yadm
$yadm clone -f https://github.com/Larusso/dotfiles.git
rm -fr $yadm_tmp
}
if [ "$os" = "macOS" ]; then
init_homebrew
elif [ "$os" = "Linux" ] && [ "$distro" = "arch"]; then
install_yay
fi
init_yadm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment