-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·155 lines (128 loc) · 5.31 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
# This script is intended to be pseudo-idempotent.
set -euo pipefail
GREEN='\033[1;32m'
BLUE='\033[1m\033[34m'
YELLOW="\033[1;33m"
RED='\033[1;31m'
NOCOLOR='\033[0m'
echo -e "${BLUE}==> Deploying dotfiles${NOCOLOR}"
# Setup XDG directories
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state"
# Deploy config files as symlinks based on the mappings file
while read -r map; do
# The $(eval echo ...) expression is needed to expand environmental
# variables inside mappings file
src=$(cut -d " " -f 1 <<< "$(eval echo "$map")")
dest=$(cut -d " " -f 2 <<< "$(eval echo "$map")")
# This will not overwrite files unless they are symlinks
if [ -e "${dest}" ] && [ ! -h "${dest}" ]; then
echo -e "${YELLOW}Config file: $dest will be skipped because it already exists, remove it and rerun this script to install new config${NOCOLOR}"
continue
fi
mkdir -p "$(dirname "$dest")"
echo "Linking $src to $dest"
ln -f -s "$(realpath "$src")" "$dest"
done < mappings
# Map all scripts inside scripts dir to local binaries dir
SCRIPTS_PATH="$HOME/.local/bin/"
mkdir -p "$SCRIPTS_PATH"
for script in ./scripts/*; do
echo "Linking $script to $SCRIPTS_PATH"
ln -f -s "$(realpath "$script")" "$SCRIPTS_PATH"
done
# System-specific actions
case ${OSTYPE} in
# For MacOS
darwin*)
echo -e "${GREEN}MacOS detected${NOCOLOR}"
# Install homebrew
echo -e "${BLUE}==> Installing brew${NOCOLOR}"
if ! [ -x "$(command -v brew)" ]; then
BREW_INSTALL_URL="https://raw.githubusercontent.com/Homebrew/install/master/install.sh"
if ! /bin/bash -c "$(curl -fsSL "${BREW_INSTALL_URL}")"; then
echo -e "${RED}Failed to install homebrew, config install abandoned${NOCOLOR}"
exit 1
fi
else
echo -e "${GREEN}Homebrew already installed, skipping${NOCOLOR}"
fi
# Install homebrew programs from brewfile
echo -e "${BLUE}==> Installing brew formulas${NOCOLOR}"
brew bundle --quiet --file=packages/macos/brewfile
# Silence lastlogin... message
touch "${HOME}"/.hushlogin
;;
# For Linux distributions
linux-gnu)
echo -e "${GREEN}Linux detected${NOCOLOR}"
# Arch-based with pacman
if [ -x "$(command -v pacman)" ]; then
echo -e "${BLUE}Installing pacman packages${NOCOLOR}"
# Falls into "Exceptions" from shellckeck wiki
#shellcheck disable=SC2024
sudo pacman --sync --refresh --needed --noconfirm - < packages/arch/pkg-list.txt
if ! [ -x "$(command -v yay)" ]; then
echo -e "${BLUE}Installing yay${NOCOLOR}"
git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si --noconfirm && cd - && rm -rf yay
fi
echo -e "${BLUE}Installing aur packages with yay${NOCOLOR}"
yay --sync --refresh --sysupgrade --needed --noconfirm --removemake - < packages/arch/pkg-list-aur.txt
# Debian based with apt
elif [ -x "$(command -v apt)" ]; then
echo -e "${BLUE}Installing apt packages${NOCOLOR}"
# Falls into "Exceptions" from shellckeck wiki
#shellcheck disable=SC2024
sudo xargs apt install -y < packages/debian/pkglist
else
echo -e "${RED}Did not detect supported Linux package manager, config install abandoned${NOCOLOR}"
exit 1
fi
;;
# Other systems not supported
*)
echo -e "${RED}Did not detect compatible OS, config install abandoned${NOCOLOR}"
exit 1
;;
esac
# Install zsh prompt
echo -e "${BLUE}==> Installing pure prompt${NOCOLOR}"
mkdir -p "${XDG_DATA_HOME}/zsh"
if [ -d "${XDG_DATA_HOME}/zsh/pure" ]; then
echo -e "${GREEN}Pure prompt already installed, skipping${NOCOLOR}"
elif ! git clone --quiet https://github.com/sindresorhus/pure.git "${XDG_DATA_HOME}/zsh/pure"; then
echo -e "${RED}Failed to install pure prompt, config will proceed${NOCOLOR}"
fi
# XDG-compliant zsh history file has to be created manually
mkdir -p "${XDG_STATE_HOME}/zsh"
echo -e "${BLUE}==> Setting up neovim plugins${NOCOLOR}"
LAZYPATH="${XDG_DATA_HOME}/nvim/lazy/lazy.nvim"
if ! [ -e "${LAZYPATH}" ]; then
echo -e "${BLUE}Installing Lazy package manager${NOCOLOR}"
git clone --filter=blob:none https://github.com/folke/lazy.nvim.git --branch=stable "$LAZYPATH"
echo -e "${GREEN}Installed Lazy package manager${NOCOLOR}"
fi
echo -e "${BLUE}Installing neovim plugins${NOCOLOR}"
nvim --headless +Lazy install +q
# Install tmux plugin manager
echo -e "${BLUE}==> Installing tmux-themepack${NOCOLOR}"
TMUX_CONF_DIR="${XDG_CONFIG_HOME}/tmux"
if ! [ -d "${TMUX_CONF_DIR}/plugins/tpm" ]; then
TPM_GIT_REPO_URL="https://github.com/tmux-plugins/tpm"
if ! git clone --quiet "${TPM_GIT_REPO_URL}" "${TMUX_CONF_DIR}/plugins/tpm"; then
echo -e "${RED}Failed to install tmux plugin manager, config will proceed${NOCOLOR}"
fi
if ! tmux new-session -d "${TMUX_CONF_DIR}/plugins/tpm/scripts/install_plugins.sh"; then
echo -e "${RED}Failed to install tmux plugins, config will proceed${NOCOLOR}"
fi
echo -e "${GREEN}Tmux plugin manager installed successfully${NOCOLOR}"
else
echo -e "${GREEN}Tmux plugin manager already installed, skipping${NOCOLOR}"
fi
echo -e "${BLUE}==> You use pyenv to install Python and obtain packages from packages/common/requirements.txt with pip${NOCOLOR}"
echo -e "${BLUE}==> You can use extra Linux dotfiles from gui_extras/linux for GUI setup with suckless user space tools${NOCOLOR}"
echo -e "${BLUE}==> You can use extra MacOS config files from gui_extras/mac for GUI setup${NOCOLOR}"
echo -e "${GREEN}Config finished${NOCOLOR}"