forked from CodelyTV/dotly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller
executable file
·101 lines (78 loc) · 2.53 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
#!/usr/bin/env bash
set -euo pipefail
##? Setups the environment
##?
##? Usage:
##? install
DOTLY_REPOSITORY=${DOTLY_REPOSITORY:-CodelyTV/dotly}
DOTLY_BRANCH=${DOTLY_BRANCH:-master}
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"; }
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 >/dev/null 2>&1
elif command_exists dnf; then
_a "Installing using dnf"
sudo dnf -y install git >/dev/null 2>&1
elif command_exists yum; then
_a "Installing using yum"
yes | sudo yum install git >/dev/null 2>&1
elif command_exists brew; then
_a "Installing using brew"
yes | brew install git >/dev/null 2>&1
else
_e "Could not install git, no package provider found"
exit 1
fi
fi
_a "Initializing your dotfiles git repository"
git init >/dev/null
_a "Cloning dotly"
git submodule add -b "$DOTLY_BRANCH" "https://github.com/$DOTLY_REPOSITORY.git" "$dotly_inner_path" >/dev/null 2>&1
_a "Installing dotly dependencies"
git submodule update --init --recursive >/dev/null 2>&1
curl https://sh.rustup.rs -sSf | sh -s -- -y
cargo install docpars
cd "$DOTLY_PATH"
"$PWD/bin/dot" self install
git init >/dev/null
_a "🎉 dotly installed correctly! 🎉"