forked from CodelyTV/dotly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer
executable file
·132 lines (105 loc) · 3.62 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
#!/usr/bin/env bash
set -euo pipefail
##? Setups the environment
##?
##? Usage:
##? install
DOTLY_REPOSITORY=${DOTLY_REPOSITORY:-CodelyTV/dotly}
DOTLY_BRANCH=${DOTLY_BRANCH:-master}
DOTLY_LOG_FILE=${DOTLY_LOG_FILE:-$HOME/dotly.log}
export DOTLY_ENV=${DOTLY_ENV:-PROD}
export DOTLY_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 "$DOTLY_LOG_FILE"
echo "----- $current_date - $log_name -----" >>"$DOTLY_LOG_FILE"
while IFS= read -r log_message; do
echo "$log_message" >>"$DOTLY_LOG_FILE"
done
echo "" >>"$DOTLY_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"
else
_a "Ok! dotfiles will be located in: ${purple}$DOTFILES_PATH${normal}"
fi
mkdir -p "$1"
}
command_exists() {
type "$1" >/dev/null 2>&1
}
_w " ┌────────────────────────────────────┐"
_w "~ │ 🚀 Welcome to the ${green}dotly${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"
dotly_inner_path="modules/dotly"
export DOTLY_PATH="$DOTFILES_PATH/$dotly_inner_path"
create_dotfiles_dir "$DOTFILES_PATH"
cd "$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
_a "Initializing your dotfiles git repository"
git init 2>&1 | _log "Initializing repository"
_a "Cloning dotly"
git submodule add -b "$DOTLY_BRANCH" "https://github.com/$DOTLY_REPOSITORY.git" "$dotly_inner_path" 2>&1 | _log "Adding dotly submodule"
_a "Installing dotly dependencies"
git submodule update --init --recursive 2>&1 | _log "Installing dotly dependencies"
cd "$DOTLY_PATH"
"$PWD/bin/dot" self install
_a "🎉 dotly installed correctly! 🎉"
_a "Please, restart your terminal to see the changes"