chore(install): update install.sh and Makefile

This commit is contained in:
2021-05-15 22:49:20 +01:00
parent dc2fe52be5
commit 5b0551bad8
2 changed files with 78 additions and 68 deletions

View File

@@ -1,62 +1,19 @@
.SILENT:
links:
./install.sh links
#
# Default tasks
#
terminfo:
./install.sh terminfo
install:
make $(DEP_PATHS)
update:
make $(foreach path,$(DEP_PATHS),$(shell echo "update_$(path)"))
clean:
make $(foreach path,$(DEP_PATHS),$(shell echo "remove_$(path)"))
launch-agents:
./install.sh launch-agents
#
# Backups
#
.PHONY: backup
backup: backup-tmux-plugins backup-zplug
.PHONY: backup-tmux-plugins
backup-tmux-plugins: \
tmux/tmux-plugins-$(shell date "+%Y-%m-%d").tar.bz2
.PHONY: backup-zplug
backup-zplug: \
zsh/zplug-$(shell date "+%Y-%m-%d").tar.bz2
tmux/tmux-plugins-%.tar.bz2: tmux/plugins
cd tmux && tar -cjf "$(shell basename "$@")" plugins
zsh/zplug-%.tar.bz2: zsh/zplug
cd zsh && tar -cjf "$(shell basename "$@")" zplug
#
# Internals
#
DEP_PATHS =
define dep-file
DEP_PATHS += $(1)
$(1):
echo "fetching $(1)..."
mkdir -p "$(shell dirname "$(1)")" && \
curl -s -L -o "$(1)" "$(2)"
.PHONY: remove_$(1)
remove_$(1):
( test -f "$(1)" && rm "$(1)" && echo "removed $(1)" ) || exit 0
.PHONY: update_$(1)
update_$(1): remove_$(1) $(1)
endef
#
# Specify Dependencies
#
$(eval $(call dep-file,zsh/completion/_docker-compose,https://github.com/docker/compose/raw/master/contrib/completion/zsh/_docker-compose))

View File

@@ -59,7 +59,7 @@ install_symlinks() {
# Setup private dotfiles
if [ -f "$ROOT_PATH/$PRIVATE_PATH/install.sh" ]; then
"$ROOT_PATH/$PRIVATE_PATH/install.sh" links
"$ROOT_PATH/$PRIVATE_PATH/install.sh" symlinks
fi
# Symlink each path
@@ -81,10 +81,17 @@ install_launch_agents() {
# Setup private launch_agents
if [ -f "$ROOT_PATH/$PRIVATE_PATH/install.sh" ]; then
"$ROOT_PATH/$PRIVATE_PATH/install.sh" launch_agents
"$ROOT_PATH/$PRIVATE_PATH/install.sh" launch-agents
fi
}
install_terminfo() {
for file in $ROOT_PATH/terminfo/*.terminfo; do
log ok "tic -x" "$file"
tic -x "$file"
done
}
install_homebrew() {
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
}
@@ -104,23 +111,69 @@ install_emacs_config() {
# Helper functions
#
ok() {
printf "OK:\t%s\n" "$1"
}
# Colors
C_RED="$(tput setaf 1)"
C_GREEN="$(tput setaf 2)"
C_YELLOW="$(tput setaf 3)"
C_BLUE="$(tput setaf 4)"
C_MAGENTA="$(tput setaf 5)"
C_CYAN="$(tput setaf 6)"
C_GREY="$(tput setaf 7)"
C_RESET="$(tput sgr0)"
info() {
printf "INFO:\t%s\n" "$1"
# Symbols
S_RARROW="${C_CYAN}-->${C_RESET}"
log() {
local type="$1"
local prefix="$2"
shift 2
local message="$@"
type="$(echo "$type" | tr '[:lower:]' '[:upper:]')"
case "$type" in
OK)
type="${C_GREEN}${type}:${C_RESET}"
;;
WARN | ERROR)
type="${C_RED}${type}:${C_RESET}"
;;
*)
type="${C_YELLOW}${type}:${C_RESET}"
;;
esac
if [ -n "$prefix" ]; then
prefix="${C_GREY}${prefix}: ${C_RESET}"
fi
printf "${type}\t${prefix}${message}\n"
}
symlink() {
local source="$1"
local target="$2"
local linksource
if [ ! -e "$target" ]; then
ok "symlink: $target --> $source"
if [ "$target" == "$source" ]; then
log ok symlink "$target"
elif [ ! -e "$target" ] && [ ! -L "$target" ]; then
log link symlink "$target ${S_RARROW} $source"
ln -s "$source" "$target"
elif [ -L "$target" ]; then
linksource="$(readlink "$target")"
if [ "$linksource" == "$source" ]; then
log ok symlink "$target ${S_RARROW} $source"
else
info "symlink: $target exists"
log warn symlink "$target ${S_RARROW} $linksource" \
"${C_CYAN}(should be ${C_RESET}$source${C_CYAN})${C_RESET}"
fi
elif [ -f "$target" ]; then
log warn symlink "$target exists and is a file"
elif [ -d "$target" ]; then
log warn symlink "$target exists and is a directory"
else
log warn symlink "$target exists"
fi
}
@@ -130,18 +183,15 @@ dot_symlink() {
local target="$3/.${name}"
local cur_name
if [ ! -e "$target" ]; then
if [ "$(dirname "$name")" != "." ] && [ "$(dirname "$name")" != "/" ]; then
cur_name="$(dirname "$name")"
while [ "$cur_name" != "." ] && [ "$cur_name" != "/" ]; do
source="../${source}"
cur_name="$(dirname "$cur_name")"
done
mkdir -p "$(dirname "$target")"
ok "symlink: $target --> $source"
ln -s "$source" "$target"
else
info "symlink: $target exists"
fi
symlink "$source" "$target"
}
git_clone() {
@@ -150,9 +200,9 @@ git_clone() {
if [ ! -e "$target" ]; then
git clone "$clone_url" "$target"
ok "git clone: $clone_url --> $target"
log ok git-clone "$clone_url ${S_RARROW} $target"
else
info "git clone: $target already exists"
log info git-clone "$target already exists"
fi
}
@@ -176,9 +226,12 @@ case "$1" in
rbenv)
install_rbenv
;;
launch_agents | agents)
launch-agents | launch_agents | agents)
install_launch_agents
;;
terminfo)
install_terminfo
;;
info)
echo "Target directory: $TARGET"
echo "Detected dotfiles root: $ROOT_PATH"