-
Notifications
You must be signed in to change notification settings - Fork 3
/
installer
executable file
Β·148 lines (119 loc) Β· 3.9 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
#!/usr/bin/env bash
set -euo pipefail
##? Setups the environment
##?
##? Usage:
##? installer
sudo -v
DOTFILES_REPOSITORY=${DOTFILES_REPOSITORY:-fraruiz/dotfiles}
DOTFILES_BRANCH=${DOTFILES_BRANCH:-main}
DOTFILES_LOG_FILE=${DOTFILES_LOG_FILE:-$HOME/dotfiles.log}
DOTFILES_PATH="$HOME/.dotfiles"
export DOTFILES_PATH="$HOME/.dotfiles"
export DOTFILES_ENV=${DOTFILES_ENV:-PROD}
export DOTFILES_INSTALLER=true
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; }
create_dotfiles_dir() {
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"
fi
mkdir -p "$1"
}
command_exists() {
type "$1" >/dev/null 2>&1
}
_w " βββββββββββββββββββββββββββββββββββββββββ"
_w "~ β π Welcome to the ${green}dotfiles${normal} installer! β ~"
_w " βββββββββββββββββββββββββββββββββββββββββ"
_w
_w "Your dotfiles will be located in ~/.dotfiles"
create_dotfiles_dir "$DOTFILES_PATH"
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
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
_a "Cloning dotfiles"
git clone "https://github.com/$DOTFILES_REPOSITORY.git" "$DOTFILES_PATH" 2>&1 | _log "Clone dotfiles"
sudo chmod -R 755 $DOTFILES_PATH
cd $DOTFILES_PATH
"$PWD/bin/dot" self install
_a "π dotfiles installed correctly! π"
_a "Please, restart your terminal to see the changes"