Refactored to use .ONESHELL

This makes it a hell of a lot simpler but will lose support for BSD
make. All effected machines are running gnu-make, so the cost benefit
ratio ways heavily in favor of doing this.
This commit is contained in:
James Patrick 2020-03-09 13:30:45 -04:00
parent cc819a19ef
commit 6c3787ef1b
19 changed files with 204 additions and 193 deletions

View File

@ -11,37 +11,39 @@ include ../lib/shared.mk
install: | init update
init:
$(report) header "emacs init"
ifneq "$(call cmd_exist,emacs)" "true"
$(report) quite "emacs not installed. Skipping install."
else ifeq "$(IS_SSH)" "true"
$(report) quite "This is a ssh connection. Skipping install."
else
$(mk_link) $(SRC_DIR)/doom.d $(DOOMD)
$(MAKE) -C $(SRC_DIR) doom_init
endif
if (( ! $$+commands[emacs] )) ; then
$(report) debug "Emacs not installed. Skipping install."
elif [[ -v $$SSH_TTY ]] ; then
$(report) debug "This is a SSH connection. Skipping."
else
$(report) header "emacs init"
$(mk_link) $(SRC_DIR)/doom.d $(DOOMD)
$(MAKE) -C $(SRC_DIR) doom_init
fi
doom_init:
if [ ! -e $(EMACSD) ] ; then \
git clone $(DOOM_URL) $(EMACSD) ;\
~/.emacs.d/bin/doom --yes install ;\
$(report) "doom install" ;\
~/.emacs.d/bin/doom --yes compile ':core' ;\
$(report) "doom core compile" ;\
else ;\
$(report) debug "emacsd already exists" ;\
$(report) info hi
if [ ! -e $(EMACSD) ] ; then
git clone $(DOOM_URL) $(EMACSD)
~/.emacs.d/bin/doom --yes install \
; $(report) "doom install"
~/.emacs.d/bin/doom --yes compile ':core' \
; $(report) "doom core compile"
else
$(report) debug "emacsd already exists. Skipping"
fi
update:
if [ -e $(EMACSD)/bin/doom ] ; then \
~/.emacs.d/bin/doom --yes purge ;\
$(report) info "doom purge" ;\
~/.emacs.d/bin/doom --yes refresh ;\
$(report) info "doom refresh" ;\
else \
$(report) debug "doom not setup, so not updating." ;\
if [ -e $(EMACSD)/bin/doom ] ; then
~/.emacs.d/bin/doom --yes purge \
; $(report) "doom purge"
~/.emacs.d/bin/doom --yes refresh \
; $(report) "doom refresh"
else
$(report) debug "doom not setup, so not updating."
fi
remove:
$(info => Removing Emacs config)
$(rm_link) $(EMACSD)
$(report) header "Removing Emacs configuration"
rm -rf $(EMACSD) ; $(report) "deleted $(EMACSD)"
$(rm_link) $(DOOMD)

View File

@ -7,11 +7,11 @@ include ../lib/shared.mk
install: | init update
init:
$(info => Setting up gitconfig)
$(report) header "Setting up gitconfig"
$(mk_link) $(SOURCE) $(TARGET)
update:
remove:
$(info => Remvoing gitconfig)
$(report) header "Removing gitconfig"
$(rm_link) $(TARGET)

View File

@ -7,13 +7,14 @@ CONFIG_DIR := $(XDG_DIR)/jrnl
install: | init update
init:
ifeq ($(call cmd_exist,jrnl), true)
$(info => Setting up jrnl)
mkdir $(CONFIG_DIR)
$(mk_link) $(SRC)/jrnl.yml $(CONFIG_DIR)/jrnl.yml
if (( $$+commands[jrnl] )) ; then
$(report) header "Setting up jrnl"
mkdir $(CONFIG_DIR)
$(mk_link) $(SRC)/jrnl.yml $(CONFIG_DIR)/jrnl.yml
else
$(report) debug "jrnl not installed. Skipping."
fi
else
$(report) info "jrnl not installed. Skipping."
endif
remove:

View File

@ -11,10 +11,10 @@ fi
if [[ -h $2 ]] ; then
link_location=$(readlink $2)
if [[ "$1" == "$link_location" ]] ; then
"$REPORT" info "symlink already installed $1"
"$REPORT" pass "Symlink already installed $1"
exit 0
else
"$REPORT" warn "symlink already exist, buut doesn't point to the src"
"$REPORT" warn "Symlink already exist, buut doesn't point to the src"
exit 1
fi
fi
@ -30,5 +30,4 @@ if [[ ! -e $parent ]] ; then
mkdir -p $parent
fi
"$REPORT" info "Symlinked `ln -svf $1 $2`"
"$REPORT" pass "Symlinked `ln -svf $1 $2`"

View File

@ -10,9 +10,9 @@ format(){
case $1 in
"error") echo -e "$R ✘ $2$NC";;
"warn") echo -e "$Y ⚠ $2$NC";;
"info") echo -e "$G ✔ $2$NC";;
"quite") echo -e "$MUTED כֿ $2$NC";;
"debug") [ -v verbose ] && echo -e "$MUTED כֿ $2$NC" || true ;;
"pass") echo -e "$G ✔ $2$NC";;
"info") echo -e "$MUTED כֿ $2$NC";;
"debug") [ -v debug ] && $0 info $2 ; true ;;
"header") echo -e "=> $2";;
*) echo -e "$1: $2";;
esac
@ -20,7 +20,7 @@ format(){
if [[ -z $2 ]] ; then
case "$LAST_RETURN" in
0) format info $1;;
0) format pass $1;;
*) format error "FAILURE DURING: \"$1\"";;
esac
else

View File

@ -17,6 +17,6 @@ if [[ ! -L $1 ]] ; then
exit
fi
$REPORT info "Deleting $1"
$REPORT pass "Deleting $1"
rm $1

View File

@ -8,11 +8,11 @@ include ../lib/shared.mk
install: | init update
init:
$(info => Setting up githook)
$(report) info "Symlinked `ln -svf $(GIT_HOOK_SRC) $(GIT_HOOK_TARGET)`"
$(report) header "Setting up githook"
$(report) pass "Symlinked `ln -svf $(GIT_HOOK_SRC) $(GIT_HOOK_TARGET)`"
update:
remove:
$(info => Removing Githook)
$(report) header "Removing githook"
$(rm_link) $(GIT_HOOK_TARGET)

View File

@ -1,10 +1,10 @@
# This will make heavy use of the "$+commands[cmd]" function in bash. Make sure its installed.
_SHELL := $(shell which zsh )
ifndef _SHELL
$(error ZSH is not installed on this machine. This makefile requires ZSH features)
endif
SHELL := $(_SHELL)
.ONESHELL:
# Helper scripts for setting up and taking down links.
LIB_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
@ -12,23 +12,9 @@ mk_link := $(LIB_DIR)/helper/mk_link
rm_link := $(LIB_DIR)/helper/rm_link
report := LAST_RETURN=$$? $(LIB_DIR)/helper/report
return_val_truthy := && echo true || echo false
cmd_exist = $(shell (($$+commands[$1])) $(return_val_truthy) )
# Shortcut for the XDG dir if it exist. default to ~/.confg
XDG_DIR := $${XDG_CONFIG_HOME:-~/.config}
# Some things will OS specific.
# With this you can use `$(IS_MAC) && echo "I'm a Mac" || echo "I'm not a Mac"`
ifeq ($(shell uname), Darwin)
IS_MAC=true
else
IS_LINUX=true
endif
IS_MAC?=false
IS_LINUX?=false
IS_SSH=$(shell [ ! -z $$SSH_TTY ] $(return_val_truthy) )
# TURN THIS OFF FOR DEBUGGING
MAKEFLAGS += --silent

View File

@ -3,10 +3,10 @@ SRC_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
include lib/shared.mk
define recursive_make
for i in */makefile; do; \
echo "`dirname $$i` " ; \
$(MAKE) -C $(SRC_DIR)/`dirname $$i` $1 ; \
echo "" ; \
for i in */makefile; do
echo "`dirname $$i` "
$(MAKE) -C $(SRC_DIR)/`dirname $$i` $1
echo ""
done
endef

View File

@ -6,20 +6,24 @@ TARGET := $(XDG_DIR)/mako
install: | init update
init:
ifeq ($(call cmd_exist,mako), true)
$(info => Setting up mako)
$(mk_link) $(SRC) $(TARGET)
else
$(report) warn "mako not installed. Skipping."
endif
if (( $$+commands[mako] )) ; then
$(report) header "Setting up mako"
$(mk_link) $(SRC) $(TARGET)
else
$(report) warn "mako not installed. Skipping."
fi
update:
ifeq ($(call cmd_exist,makoctl), true)
$(info => Reloading mako)
[[ -n `pgrep mako` ]] \
&& ( makoctl reload ; $(report) "mako reload") ; true
endif
if (( $$+commands[makoctl] )) ; then
$(report) header "Updating mako"
if [[ -n `pgrep mako` ]] ; then
makoctl reload ; $(report) "mako reload"
fi
else
$(report) debug "mako not installed"
fi
remove:
$(info => Remvoing sway)
$(report) header "Removing mako"
$(rm_link) $(TARGET)

View File

@ -9,37 +9,39 @@ DESKTOP_TARGET := ~/.local/share/applications
install: | init update
init:
ifeq ($(call cmd_exist,rofi), true)
$(info => Setting up rofi)
$(mk_link) $(SRC) $(TARGET)
$(MAKE) -C $(SRC) desktop_init
else
$(report) warn "rofi not installed. Skipping."
endif
if (( $$+commands[rofi] )) ; then
$(report) header "Setting up rofi"
$(mk_link) $(SRC) $(TARGET)
$(MAKE) -C $(SRC) desktop_init
else
$(report) debug "rofi not installed. Skipping."
fi
update:
remove:
$(info => Remvoing rofi)
$(report) header "Removing rofi"
$(rm_link) $(TARGET)
$(MAKE) -C $(SRC) desktop_remove
desktop_init:
ifeq ($(shell [ -e $(DESKTOP_TARGET) ] $(return_val_truthy) ), true)
$(info ==> Setting up desktop shortcuts.)
cd $(DESKTOP_SRC) ; \
for i in *.desktop; do ; \
$(mk_link) $(DESKTOP_SRC)/$$i $(DESKTOP_TARGET)/$$i ; \
done
else
$(report) warn "$(DESKTOP_TARGET) does not exist. Skipping."
endif
if [[ ! -e $(DESKTOP_TARGET) ]] ; then
$(report) warn "$(DESKTOP_TARGET) does not exist. Skipping."
else
$(report) header "Adding .desktop files"
cd $(DESKTOP_SRC)
for i in *.desktop ; do
$(mk_link) $(DESKTOP_SRC)/$$i $(DESKTOP_TARGET)/$$i
done
fi
desktop_remove:
ifeq ($(shell [ -e $(DESKTOP_TARGET) ] $(return_val_truthy) ), true)
$(info ==> removing rofi desktop entries.)
cd $(DESKTOP_SRC) ; \
for i in *.desktop; do ; \
$(rm_link) $(DESKTOP_TARGET)/$$i ; \
done
endif
if [[ ! -e $(DESKTOP_TARGET) ]] ; then
$(report) warn "$(DESKTOP_TARGET) does not exist. Skipping."
else
$(report) header "Removing .desktop files"
cd $(DESKTOP_SRC)
for i in *.desktop ; do
$(rm_link) $(DESKTOP_TARGET)/$$i
done
fi

View File

@ -1,35 +1,37 @@
SRC_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CONFIG_SRC := $(SRC_DIR)/config
CONFIG_TRGT := ~/.ssh/config
JPATRICK_KEY := ~/.ssh/git.jpatrick.io
GIT_KEY := ~/.ssh/git.jpatrick.io
include ../lib/shared.mk
install: | init update
init:
$(info => Setting up ssh)
$(report) header "Setting up ssh"
$(mk_link) $(CONFIG_SRC) $(CONFIG_TRGT)
$(mk_link) $(SRC_DIR)/public_keys ~/.ssh/public_keys
$(MAKE) -C $(SRC_DIR) init_jpatrick_key
$(MAKE) -C $(SRC_DIR) init_git_key
update:
cd ~/.ssh \
&& mkdir -p public_keys/`hostname` \
&& for i in *.pub ; do ; \
cp $$i public_keys/`hostname`/$$i ; \
mkdir -p public_keys/`hostname`
cd ~/.ssh
$(report) header "Copying public keys"
for i in *.pub ; do
cp $$i public_keys/`hostname`/$$i
$(report) pass "Copied $$i"
done
remove:
$(info => Remvoing ssh)
$(rm_link) $(TARGET)
$(report) warn "NOTE: All prior keys still remain."
$(report) header "Removing ssh sym-links"
$(rm_link) $(CONFIG_TRGT)
$(report) warn "NOTE: All keys still remain."
init_jpatrick_key:
ifeq ($(shell [ ! -e $(JPATRICK_KEY) ] $(return_val_truthy) ), true)
$(report) info "Setting up key for jpatrick.io"
ssh-keygen -t ed25519 -C "`hostname`: `date`" -f $(JPATRICK_KEY) -N "" \
; $(report) info "jpatrick.io key created"
else
$(report) warn "Key for jpatrick.io already created"
endif
init_git_key:
if [[ -e $(GIT_KEY) ]] ; then
$(report) debug "$(GIT_KEY) already installed."
else
$(report) info "Setting up key for git.jpatrick.io"
ssh-keygen -t ed25519 -C "`hostname`: `date`" -f $(GIT_KEY) -N "" \
; $(report) info "git.jpatrick.io key created"
fi

View File

@ -6,21 +6,21 @@ TARGET := $(XDG_DIR)/sway
install: | init update
init:
ifeq ($(call cmd_exist,sway), true)
$(info => Setting up sway)
$(mk_link) $(SRC) $(TARGET)
else
$(report) warn "Sway not installed. Skipping."
endif
if (( ! $$+commands[sway] )) ; then
$(report) debug "Sway not installed. Skipping."
else
$(report) header "Setting up sway"
$(mk_link) $(SRC) $(TARGET)
fi
update:
ifeq ($(call cmd_exist,swaymsg), true)
$(info => Reloading sway)
swaymsg reload ; $(report) "sway reload"
else
$(report) warn "swaymsg not installed. Skipping."
endif
if (( ! $$+commands[swaymsg] )) ; then
$(report) debug "swaymsg not installed. Skipping."
else
$(report) header "Reloading sway"
swaymsg reload ; $(report) "sway reload"
fi
remove:
$(info => Remvoing sway)
$(report) header "Removing sway"
$(rm_link) $(TARGET)

View File

@ -7,16 +7,15 @@ include ../lib/shared.mk
install: | init update
init:
$(info => tmux init)
ifeq ($(call cmd_exist,tmux), true)
$(info => Setting up tmux)
$(mk_link) $(SOURCE) $(TARGET)
else
$(report) warn "tmux not installed."
endif
if (( ! $$+commands[tmux] )) ; then
$(report) header "tmux not installed"
else
$(report) header "tmux init"
$(mk_link) $(SOURCE) $(TARGET)
fi
update:
remove:
$(info => Remvoing tmux config)
$(report) header "Removing tmux config"
$(rm_link) $(TARGET)

View File

@ -7,22 +7,22 @@ SCRIPTS_TARGET := ~/.local/share/tridactyl/scripts
install: | init update
init:
$(info => setting up Tridaycl)
ifeq "$(IS_MAC)" "true"
$(MAKE) -C $(SRC_DIR) setup
else ifeq "$(call cmd_exist,firefox)" "true"
$(MAKE) -C $(SRC_DIR) setup
else
$(report) warn "This doesn't seem to be an env for Tridactyl. Skipping."
endif
if [[ $OSTYPE = darwin* ]] ; then
$(MAKE) -C $(SRC_DIR) setup
elif (( $$+commands[firefox] )) ; then
$(MAKE) -C $(SRC_DIR) setup
else
$(report) debug "This doesn't seem to be an env for Tridactyl. Skipping."
fi
setup:
$(report) header "Setting up Tridaycl"
$(mk_link) $(SRC_DIR) $(RC_TARGET)
$(mk_link) $(SRC_DIR)/scripts $(SCRIPTS_TARGET)
update:
remove:
$(info => Remvoing tridactyl )
$(report) header "Removing Tridaycl"
$(rm_link) $(RC_TARGET)
$(rm_link) $(SCRIPTS_TARGET)

View File

@ -8,22 +8,27 @@ include ../lib/shared.mk
install: | init update
init:
ifneq ($(call cmd_exist,vim), true)
$(error Vim not installed)
endif
$(info => Setting up vim)
$(mk_link) $(SRC_DIR) $(TARGET_DIR)
$(mk_link) $(SRC_DIR)/vimrc ~/.vimrc
if (( $$+commands[vim] )) ; then
$(report) header "Setting up vim"
$(mk_link) $(SRC_DIR) $(TARGET_DIR)
$(mk_link) $(SRC_DIR)/vimrc ~/.vimrc
else
$(report) warn "cannot find vim?"
fi
update:
ifneq ($(call cmd_exist,vim), true)
$(error Vim not installed)
endif
$(info => Updating vim)
curl -fsLo $(PLUG_PATH) $(PLUG_URL) ; $(report) "vim plug setup"
vim +PlugInstall +PlugUpdate +qall ; $(report) "downloading/updating plugins"
if (( $$+commands[vim] )) ; then
$(report) header "Upgrading vim"
curl -fsLo $(PLUG_PATH) $(PLUG_URL) \
; $(report) "vim plug setup"
vim +PlugInstall +PlugUpdate +qall \
; $(report) "downloading/updating plugins"
else
$(report) warn "cannot find vim?"
fi
remove:
$(info => Removing vim config)
$(report) header "Removing vim config"
$(rm_link) ~/.vimrc
$(rm_link) $(TARGET_DIR)

View File

@ -6,23 +6,21 @@ TARGET := $(XDG_DIR)/waybar
install: | init update
init:
ifeq ($(call cmd_exist,waybar), true)
$(info => Setting up waybar)
$(mk_link) $(SRC) $(TARGET)
else
$(report) warn "waybar not installed. Skipping."
endif
if (( $$+commands[waybar] )) ; then
$(report) header "Setting up waybar"
$(mk_link) $(SRC) $(TARGET)
else
$(report) debug "waybar not installed. Skipping."
fi
update:
ifeq ($(call cmd_exist,swaymsg), true)
$(info => Reloading sway)
swaymsg reload ; $(report) "sway reload"
else
$(report) warn "swaymsg not installed. Skipping."
endif
if (( $$+commands[swaymsg] )) ; then
$(report) header "Reloading waybar"
swaymsg reload ; $(report) "sway reload"
else
$(report) debug "swaymsg not installed. Skipping."
fi
remove:
$(info => Removing waybar)
$(report) header "Removing waybar"
$(rm_link) $(TARGET)
.PHONY: install update init remove

View File

@ -8,35 +8,47 @@ install: | init update
init:
$(info => Setting up zsh)
ifeq ($(shell [ ! -e $(ZPLUG_DIR) ] $(return_val_truthy) ), true)
export ZPLUG_HOME=$(ZPLUG_DIR) \
; git clone https://github.com/zplug/zplug $(ZPLUG_DIR) \
; source ~/.zplug/init.zsh && zplug update --self \
; $(report) "zplug installed"
endif
$(MAKE) -C $(SRC) init_zplug
$(mk_link) $(SRC) ~/.zsh
$(mk_link) $(ZSH_DIR)/zshrc ~/.zshrc
$(mk_link) $(ZSH_DIR)/zlogin ~/.zlogin
$(mk_link) $(ZSH_DIR)/zprofile ~/.zprofile
$(mk_link) $(ZSH_DIR)/zshenv ~/.zshenv
$(mk_link) $(ZSH_DIR)/zlogout ~/.zlogout
chmod 700 $(ZSH_DIR)/transient
chmod 700 $(ZSH_DIR)/transient \
; $(report) "updating transient permissions"
init_zplug:
if [ ! -e $(ZPLUG_DIR) ] ; then
export ZPLUG_HOME=$(ZPLUG_DIR)
git clone https://github.com/zplug/zplug $(ZPLUG_DIR) \
; $(report) "zplug installed"
else
$(report) debug "zplug already installed. Skipping"
fi
update:
[ -e $(ZPLUG_DIR) ] \
&& ( echo "=> Updating zplug" \
source $(ZPLUG_DIR)/init.zsh ; source $(ZSH_DIR)/zplug ; zplug install ; zplug update ) \
|| $(report) warn "No zplug install detected. Skipping."
if [ -e $(ZPLUG_DIR) ] ; then
$(report) header "Updating zplug"
source $(ZPLUG_DIR)/init.zsh
source $(ZSH_DIR)/zplug
export zplugs
zplug install \
; $(report) "zplug install"
zplug update \
; $(report) "zplug upate"
zplug clean \
; $(report) "zplug cleaned"
else
$(report) error "$(ZPLUG_DIR) doesn't exist... maybe run init first?"
fi
remove:
ifeq ($(shell [ -e $(ZPLUG_DIR) ] $(return_val_truthy) ), true)
$(report) warn "Leaving $(ZPLUG_DIR) directory."
endif
$(info => Removing zsh)
rm -rf $(ZPLUG_DIR) ; $(report) "deleting zplug dir"
$(rm_link) ~/.zprofile
$(rm_link) ~/.zlogin
$(rm_link) ~/.zshrc
$(rm_link) ~/.zsh
$(rm_link) ~/.zshenv
$(mk_link) $(ZSH_DIR)/zlogout ~/.zlogout
$(rm_link) ~/.zlogout

View File

@ -27,4 +27,5 @@ else
fi
env_loader zplug
zplug load