#!/bin/sh

set -e

test -n "$DEBUG" && set -x

if test -z "$1"; then
	printf "Usage: %s machine\n" "$0" 1>&2
	exit 64 # sysexits.h(3) EX_USAGE
fi

case "$1" in
	"carnation")
		MACHINE="noire-carnation"
		;;
	"rose")
		MACHINE="noire-rose"
		;;
esac

for item in "$MACHINE"/config/*
do
	name="$(printf "%s\n" "$item" | sed "s;$MACHINE/config/;;g")"
	echo $name

	printf "Creating symlink from %s to %s\n" \
		"$PWD/$item" "$XDG_CONFIG_HOME/$name" 1>&2

	if test -n "$DEBUG"; then continue; fi

	rm "$XDG_CONFIG_HOME/$name" || true
	ln -s "$PWD/$item" "$XDG_CONFIG_HOME/$name"
done

ln -sf "$PWD/$MACHINE/functions" "$HOME/.functions"
ln -sf "$PWD/$MACHINE/profile" "$HOME/.profile"
ln -sf "$PWD/$MACHINE/zprofile" "$HOME/.zprofile"
ln -sf "$PWD/$MACHINE/zshrc" "$HOME/.zshrc"
