-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·203 lines (179 loc) · 5.98 KB
/
setup.sh
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/sh
set -e
ORIGINAL_DIR="$(pwd)"
cd "$(dirname "$0")"
# SET SOME DEFAULTS
checkout="main"
# PARSE ARGUMENTS
while [ $# -gt 0 ]; do
key="$1"
case $key in
--checkout)
checkout="$2"
shift
;;
--help)
echo "Usage: setup.sh [--checkout <branch or commit>] [--help]"
exit 0
;;
*)
echo "Invalid argument: ${key}"
exit 1
;;
esac
shift
done
# FUNCTION TO CHECK IF A COMMAND EXISTS
check_command() {
command -v $1 >/dev/null 2>&1
}
# FUNCTION TO INSTALL A PACKAGE IF NOT EXISTS ALREADY
install_package() {
if ! command -v $1 >/dev/null 2>&1; then
echo "Installing $1"
if command -v apt-get >/dev/null 2>&1; then
install_command="sudo apt-get update && sudo apt-get install -y "$1""
elif command -v pacman >/dev/null 2>&1; then
install_command="sudo pacman -Syu --noconfirm "$1""
elif command -v dnf >/dev/null 2>&1; then
install_command="sudo dnf install -y "$1""
elif command -v brew >/dev/null 2>&1; then
install_command="brew install "$1""
elif command -v port >/dev/null 2>&1; then
install_command="sudo port install "$1""
elif command -v zypper >/dev/null 2>&1; then
install_command="sudo zypper install "$1""
elif command -v yum >/dev/null 2>&1; then
install_command="sudo yum install -y "$1""
elif command -v apk >/dev/null 2>&1; then
install_command="sudo apk add "$1""
else
echo "Please install $1 with your package manager"
exit 1
fi
if [ "${install_command}" != "" ]; then
echo "Executing: ${install_command}"
sh -c "${install_command}"
fi
fi
}
# MAKE SURE WE ARE NOT ROOT
if [ "$(whoami)" = "root" ]; then
echo "This script should not be run as root."
exit 1
fi
if ! command -v sudo >/dev/null 2>&1; then
echo "Please install sudo with your package manager."
exit 1
fi
# MAKE SURE WE HAVE SUDO
echo "Make sure we have root access . . ."
if ! sudo -v; then
echo
echo "You do not seem to have sudo rights."
suders_file=""
if [ -f "/etc/sudoers" ]; then
suders_file="/etc/sudoers"
fi
if [ -d "/etc/sudoers.d" ]; then
suders_file="/etc/sudoers.d/$(whoami)"
fi
if [ "${suders_file}" != "" ]; then
echo "You may need to add yourself to the sudoers file."
printf "\tExample: sudo echo \"$(whoami) ALL=(ALL) NOPASSWD: ALL\" >>/etc/sudoers.d/$(whoami)\n"
fi
exit 1
fi
# DETERMINE IF THIS WAS RUN FROM ONLINE SCRIPT
if [ "$0" = "sh" ]; then
git_url="https://github.com/JtMotoX/dotfiles"
git_dir="$(cd ~ && pwd)/dotfiles"
install_package git
if [ -d "${git_dir}" ]; then
existing_remote_url="$(git -C "${git_dir}" config --get remote.origin.url)"
if [ "${existing_remote_url}" != "${git_url}" ] && [ "${existing_remote_url}" != "${git_url}.git" ]; then
echo "The directory '${git_dir}' is not a clone of the dotfiles repo. Please remove it and run the script again."
exit 1
fi
echo "Updating dotfiles"
git -C "${git_dir}" pull
else
echo "Cloning dotfiles"
git clone "${git_url}" "${git_dir}"
fi
git -C ~/dotfiles checkout ${checkout}
echo "Execute the setup script locally"
~/dotfiles/setup.sh
exit $?
fi
# UPDATE THIS REPO
if [ "${run_remote}" = "false" ]; then
current_commit="$(git rev-parse HEAD)"
git pull
new_commit="$(git rev-parse HEAD)"
if [ "$current_commit" != "$new_commit" ]; then
echo "Some changes were made to this repo. Please run the script again."
exit 1
fi
fi
reload_needed="false"
# CREATE SOME REQUIRED DIRECTORIES
required_directories="$HOME/.cache $HOME/.local/bin"
echo "Create required directories . . ."
sudo mkdir -p ${required_directories}
sudo chown $(id -u):$(id -g) ${required_directories}
# INSTALL SOME DEPENDENCIES
install_package curl
install_package git
install_package bash
# CONFIGURE LOCALES
if [ "$(uname)" = "Linux" ]; then
if ! locale-gen --help >/dev/null 2>&1; then
install_package locales || install_package glibc-langpack-en || true
fi
if locale-gen --help >/dev/null 2>&1; then
if ! cat /etc/locale.gen 2>/dev/null | grep -q '^en_US.UTF-8 UTF-8'; then
sudo sed -i -E '/^#\s*en_US.UTF-8 UTF-8/s/^#\s*//' /etc/locale.gen
sudo locale-gen
fi
fi
fi
# INSTALL PACKAGE REPOS
./scripts/repos-install.sh
# INSTALL BREW
. ./scripts/brew-source.sh
./scripts/brew-install.sh
. ./scripts/brew-source.sh
if [ "${HOMEBREW_PREFIX}" != "$(brew --prefix)" ]; then
echo "ERROR: Failed to source Homebrew."
exit 1
fi
# ALLOW SUDO TO USE BREW PACKAGES
echo "Allow sudo to use brew packages . . ."
if [ -d "${HOMEBREW_PREFIX}/bin" ] && ! sudo grep -q "${HOMEBREW_PREFIX}/bin" /etc/sudoers; then sudo sed -i.bak 's#\(Defaults\s*secure_path=".*\)"#\1:'${HOMEBREW_PREFIX}'/bin"#' /etc/sudoers; fi
if [ -d "${HOMEBREW_PREFIX}/sbin" ] && ! sudo grep -q "${HOMEBREW_PREFIX}/sbin" /etc/sudoers; then sudo sed -i.bak 's#\(Defaults\s*secure_path=".*\)"#\1:'${HOMEBREW_PREFIX}'/sbin"#' /etc/sudoers; fi
# INSTALL XCODE COMMAND LINE TOOLS NEEDED FOR BREW
if [ "$(uname)" = "Darwin" ]; then
if ! xcode-select -p >/dev/null 2>&1; then
xcode-select --install
fi
fi
# RESTORE BREW PACKAGES
./scripts/brew-restore.sh
# INSTALL BOURNE SHELL
install_package dash
./scripts/bourne-sh-install.sh
install_package zsh
if ! type chsh >/dev/null 2>&1; then
install_package util-linux-user || true
fi
./scripts/zsh-install.sh
./scripts/oh-my-zsh-install.sh
./scripts/tmux-configure.sh
./scripts/create-symbolic-links.sh --override
./scripts/dcomp-install.sh
./scripts/kubernetes-tools.sh
./scripts/pyenv-configure.sh "3.10.3"
echo
echo "Successfully finished dotfiles setup."
echo "You may need to restart your terminal session for some changes to apply."