-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall
executable file
·171 lines (122 loc) · 4.24 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env bash
set -e
##### Variables ###############################################################
export PATH=${HOME}/.local/bin:${HOME}/bin:${HOME}/.local/share/mise/shims:/usr/local/bin:${PATH}
# For Ubuntu
export DEBIAN_FRONTEND=noninteractive
# Defind Colors
BANNER="\033[38;2;101;178;255m" # BLUE
DEBUG="\033[38;2;144;108;255m" # MAGENTA
INFO="\033[38;2;98;209;150m" # GREEN
WARN="\033[38;2;255;179;120m" # YELLOW
ERROR="\033[38;2;255;84;88m" # RED
OTHER="\033[38;2;99;242;241m" # CYAN
CLEAR_COLOR="\033[0m"
# Define path
DOTPATH="$HOME/.dotfiles"
##### Functions ###############################################################
COL=120
function _banner() {
sep=$(for ((i = 1; i < COL; i++)); do echo -n =; done)
printf "\n${BANNER}%s %s${CLEAR_COLOR}\n\n" "${1}" "${sep:${#1}}"
}
function _logger() {
LOG_LEVEL="${1}"
printf "${!LOG_LEVEL}%s${CLEAR_COLOR}\n" "${1}: ${2}"
}
##### Check DONT_SUDO Environment Variable ####################################
_banner "Check DONT_SUDO Environment Variable..."
if [[ -n "${DONT_SUDO}" ]]; then
_logger INFO "DONT_SUDO is set. Skip sudo command."
USE_SUDO="false"
else
USE_SUDO="true"
fi
##### Detect OS Distribution ##################################################
_banner "Detect OS Distribution..."
if [[ -f /etc/os-release ]]; then
. /etc/os-release
case "${NAME}" in
Ubuntu*)
# Ubuntu
;;
*)
_logger ERROR "Unknown OS is detected."
exit 1
;;
esac
else
_logger ERROR "No such file. /etc/os-release"
exit 1
fi
_logger INFO "${PRETTY_NAME} is detected."
##### Setup repositories ######################################################
function setup_repository_deb() {
_banner "Setup repositories..."
_logger INFO "Install apt common package."
sudo -E apt-get update
sudo -E apt-get install -y gnupg software-properties-common ca-certificates
sudo install -dm 755 /etc/apt/keyrings
}
if "${USE_SUDO}" && ! dpkg --list | grep -q -w gnupg; then
setup_repository_deb
else
_banner "Skip repositories set up."
fi
##### Install packages ########################################################
function install_packages_deb() {
_banner "Install packages..."
_logger INFO "Update package info."
sudo -E apt-get update
# Prevent interruptions due to time zone selection.
sudo -E apt-get install -y tzdata
_logger INFO "Install basic packages."
sudo -E apt-get install -y \
build-essential \
git
}
if "${USE_SUDO}" && ! dpkg --list | grep -q -w build-essential; then
install_packages_deb
else
_banner "Skip package installation."
fi
##### Install starship ########################################################
_banner "Install Starship..."
mkdir -p "${HOME}/.local/bin"
sh -c "$(curl -fsSL https://starship.rs/install.sh)" dollar_zero --yes --bin-dir "${HOME}/.local/bin"
##### Clone Dotfiles ##########################################################
_banner "Clone Dotfiles..."
if [[ ! -d "${DOTPATH}" ]]; then
_logger INFO "Clone dotfiles repository"
git clone --recursive https://github.com/IMOKURI/dotfiles.git "${DOTPATH}"
fi
##### Install dotfiles ########################################################
_banner "Deploy dotfiles..."
pushd "$(pwd)"
cd "${DOTPATH}"
make install
if ! grep -q '.config/bashrc' "${HOME}/.bashrc"; then
echo -e "\nif [[ -f ~/.config/bashrc ]]; then\n . ~/.config/bashrc\nfi" >>"${HOME}/.bashrc"
fi
if ! grep -q '.config/profile.d/local.sh' "${HOME}/.profile"; then
echo -e "\nif [[ -f ~/.config/profile.d/local.sh ]]; then\n . ~/.config/profile.d/local.sh\nfi" >>"${HOME}/.profile"
fi
popd
##### Install Mise ############################################################
_banner "Install Mise..."
pushd "$(pwd)"
cd "${DOTPATH}"
make mise
popd
##### Install bashmarks #######################################################
_banner "Install Bashmarks..."
pushd "$(pwd)"
cd "${DOTPATH}"
make bashmarks
popd
##### Instruct next steps #####################################################
_banner "Please restart your shell session."
_banner "Please run following commands to install development tools."
_logger INFO " mise install"
_banner "Please restart your shell session."
_banner "Well done!"