#!/bin/sh
#####################################################################
CHECK_ZSH() {
	CHECK_EXISTS() { command -v $@ >/dev/null 2>&1; }
	CHECK_EXISTS zsh && return 0

	echo "'zsh' not installed; attempting auto-installation" >&2
	CHECK_EXISTS yay  && yay -Syu zsh             && return 0
	CHECK_EXISTS apt  && sudo apt-get install zsh && return 0
	CHECK_EXISTS brew && brew install zsh         && return 0

	echo "unable to install 'zsh'; please install 'zsh' and try again" >&2
	return 1
}
CHECK_ZSH || exit 1
#####################################################################
DOTWRYN="$HOME/.wryn"

[ ! -d "$DOTWRYN" ] && {
	git clone https://yage.io/wrynegade/dotwryn "$DOTWRYN"
}

cd "$DOTWRYN"
git pull

[ ! -f "$DOTWRYN/setup/run" ] && {
	echo "unable to find '$DOTWRYN/setup/run'; did git clone fail above?" >&2
	exit 1
}

"$DOTWRYN/setup/run" $@ && {
	echo 'settings will be available at next login!'
}
