-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.pre
executable file
·77 lines (70 loc) · 3.06 KB
/
install.pre
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
#!/usr/bin/env bash
# Colors
RESET=$(tput sgr0)
# shellcheck disable=SC2034
RED=$(tput setaf 1)
# shellcheck disable=SC2034
GREEN=$(tput setaf 2)
# shellcheck disable=SC2034
YELLOW=$(tput setaf 3)
# shellcheck disable=SC2034
BLUE=$(tput setaf 4)
# shellcheck disable=SC2034
MAGENTA=$(tput setaf 5)
# shellcheck disable=SC2034
CYAN=$(tput setaf 6)
# shellcheck disable=SC2034
ITALIC=$(tput sitm)
# shellcheck disable=SC2034
BOLD=$(tput bold)
# system / hardware check; currently only support ubuntu 24.04 and archlinux
if [[ ! -f "/etc/os-release" ]]; then
echo "${BOLD}${YELLOW}ERROR${RESET}: couldn't determine current os."
[[ ${DOTFILES_STRICT_CHECKING} != 0 ]] && echo "Use DOTFILES_STRICT_CHECKING=0 to bypass it" && exit 1
else
. /etc/os-release
if [[ ${NAME} != "Ubuntu" ]] && [[ ${NAME} != "Arch Linux" ]]; then
echo "${BOLD}${RED}ERROR${RESET}: distro ${NAME} is not supported"
[[ ${DOTFILES_STRICT_CHECKING} != 0 ]] && echo "Use DOTFILES_STRICT_CHECKING=0 to bypass it" && exit 1
fi
if [[ ${NAME} == "Ubuntu" ]] && [[ ${VERSION_ID} != "24.04" ]]; then
echo "${BOLD}${YELLOW}WARNING${RESET}: Ubuntu ${VERSION_ID} might not be well supported"
fi
fi
if [[ $(uname -m) != "x86_64" ]]; then
echo "${BOLD}${YELLOW}ERROR${RESET}: hardware $(uname -m) is not supported"
[[ ${DOTFILES_STRICT_CHECKING} != 0 ]] && echo "Use DOTFILES_STRICT_CHECKING=0 to bypass it" && exit 1
fi
# delete all broken symlinks in $CLEAN_DIRS
function delete_broken_symlinks() {
echo "${BLUE}Deleting broken symlinks ...${RESET}"
for CLEAN_DIR in "$@"; do
if [ -d ${CLEAN_DIR} ]; then
CLEAN_DIR_RELATIVE=$(echo "$CLEAN_DIR" | sed "s|^$HOME|~|")
find ${CLEAN_DIR} -maxdepth 1 -type l -exec sh -c 'for x; do [ -e "$x" ] || rm "$x"; done' _ {} + &&
echo "- ${BOLD}${GREEN}OK${RESET} Deleting broken symlinks in ${CYAN}${CLEAN_DIR_RELATIVE}${RESET} succeeded" ||
echo "- ${BOLD}${RED}ERROR${RESET} Deleting broken symlinks in ${CYAN}${CLEAN_DIR_RELATIVE}${RESET} failed"
fi
done
}
################################################################################
function print_separate_line() {
echo "${BLUE}----------------------------------------------------------------------${RESET}"
}
print_separate_line
# NOTE: do not place this block inside function; otherwise it won't exit
if [[ $(basename $SHELL) != 'zsh' ]]; then
echo "${BOLD}${RED}ERROR${RESET}: current shell is not zsh"
echo "- Please install zsh, run '${BOLD}${MAGENTA}chsh -s $(which zsh)${RESET}', relogin shell and run this script again."
exit 1
else
echo "${BOLD}${GREEN}OK${RESET}: current shell is zsh"
# create ~/.zshrc.local if not exists
if [ ! -f ~/.zshrc.local ]; then
touch ~/.zshrc.local && echo "- ${BOLD}${CYAN}INFO${RESET} ~/.zshrc.local created"
fi
fi
print_separate_line
delete_broken_symlinks ~ ~/bin ~/.config/nvim ~/.config/nvim/lua
################################################################################
# vim: ft=bash syntax=bash cc=120 tw=119 ts=4 sw=4 sts=4 et sr