-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller
166 lines (137 loc) Β· 4.52 KB
/
installer
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
#!/usr/bin/env bash
set -euo pipefail
##? Setups the environment
##?
##? Usage:
##? install
REPOSITORY="https://github.com/borjapazr/dotfiles.git"
DOTFILES_LOG_FILE=${DOTFILES_LOG_FILE:-$HOME/dotfiles.log}
case "${1:-}" in
-h | --help | --version)
grep "^##?" "$0" | cut -c 5-
exit 0
;;
esac
# Colors, print and prompt
red='\033[0;31m'
green='\033[0;32m'
purple='\033[0;35m'
normal='\033[0m'
_w() {
local -r text="${1:-}"
echo -e "$text"
}
_a() { _w "β $1"; }
_e() { _a "${red}$1${normal}"; }
_s() { _a "${green}$1${normal}"; }
_q() { read -rp "π€ $1: " "$2"; }
_log() {
log_name="$1"
current_date=$(date "+%Y-%m-%d %H:%M:%S")
touch "$DOTFILES_LOG_FILE"
echo "----- $current_date - $log_name -----" >>"$DOTFILES_LOG_FILE"
while IFS= read -r log_message; do
echo "$log_message" >>"$DOTFILES_LOG_FILE"
done
echo "" >>"$DOTFILES_LOG_FILE"
}
_current_timestamp() { date +%s; }
_command_exists() {
type "$1" >/dev/null 2>&1
}
clone_repository() {
if [ -d "$1" ]; then
local -r backup_path="$1.$(_current_timestamp).back"
_e "The path '$1' already exist"
_s "Creating a backup in '$backup_path'"
mv "$1" "$backup_path"
else
_a "π Ok! dotfiles will be located in: ${purple}$DOTFILES_PATH${normal}"
fi
git clone "$REPOSITORY" "$DOTFILES_PATH" --depth 1 2>&1 | _log "π Cloning repository"
}
install_git() {
if ! _command_exists git; then
_e "β git not installed, trying to install"
if _command_exists apt; then
_a "π₯ Installing using apt"
sudo apt -y install git 2>&1 | _log "π₯ Installing git"
elif _command_exists dnf; then
_a "π₯ Installing using dnf"
sudo dnf -y install git 2>&1 | _log "π₯ Installing git"
elif _command_exists yum; then
_a "π₯ Installing using yum"
yes | sudo yum install git 2>&1 | _log "π₯ Installing git"
elif _command_exists brew; then
_a "π₯ Installing using brew"
yes | brew install git 2>&1 | _log "π₯ Installing git"
elif _command_exists pacman; then
_a "π₯ Installing using pacman"
sudo pacman -S --noconfirm git 2>&1 | _log "π₯ Installing git"
else
case "$OSTYPE" in
darwin*)
_a "π Checking if Command Line Tools are installed π΅οΈββοΈ"
xcode-select --install 2>&1 | grep installed >/dev/null
if [[ $? ]]; then
_a "π₯ Installing Command Line Tools πΊ"
xcode-select --install
_q "πΉ Press a key after command line tools has finished to continue...π" "CLT_INSTALLED"
fi
;;
*)
_e "β Could not install git, no package provider found"
exit 1
;;
esac
fi
fi
}
install_curl() {
if ! _command_exists curl; then
_e "β curl not installed, trying to install"
if _command_exists apt; then
_a "π₯ Installing using apt"
sudo apt -y install curl 2>&1 | _log "π₯ Installing curl"
elif _command_exists dnf; then
_a "π₯ Installing using dnf"
sudo dnf -y install curl 2>&1 | _log "π₯ Installing curl"
elif _command_exists yum; then
_a "π₯ Installing using yum"
yes | sudo yum install curl 2>&1 | _log "π₯ Installing curl"
elif _command_exists brew; then
_a "π₯ Installing using brew"
yes | brew install curl 2>&1 | _log "π₯ Installing curl"
elif _command_exists pacman; then
_a "π₯ Installing using pacman"
sudo pacman -S --noconfirm curl 2>&1 | _log "π₯ Installing curl"
else
_e "β Could not install curl, no package provider found"
exit 1
fi
fi
}
main() {
_w
_w "βββββββββββββββββββββββββββββββ"
_w "β π₯ ${green}.dotfiles${normal} installer! β"
_w "βββββββββββββββββββββββββββββββ"
_w
_q "β Where do you want your dotfiles to be located? (default ~/.dotfiles)" "DOTFILES_PATH"
DOTFILES_PATH="${DOTFILES_PATH:-$HOME/.dotfiles}"
DOTFILES_PATH="$(eval echo "$DOTFILES_PATH")"
export DOTFILES_PATH="$DOTFILES_PATH"
install_curl
install_git
_a "π Cloning .dotfiles"
clone_repository "$DOTFILES_PATH"
_a "π₯ Installing dependencies"
cd $DOTFILES_PATH
git submodule update --init --recursive 2>&1 | _log "Installing .dotfiles dependencies"
"$DOTFILES_PATH/bin/dot" self install
_s "π .dotfiles installed correctly! π"
_s "π Please, restart your terminal to see the changes"
_a "π Check the installation logs"
cat "$DOTFILES_LOG_FILE"
}
main "$@"