-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·88 lines (73 loc) · 1.68 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·88 lines (73 loc) · 1.68 KB
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
#!/usr/bin/env bash
set -euo pipefail
# Directory of this script (works even when called via symlink)
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
LOG_LEVEL=10 # DEBUG+
LOG_TIME=1
LOG_PREFIX="dotfiles-install"
# shellcheck source=lib/log.sh
. "$SCRIPT_DIR/lib/log.sh"
# shellcheck source=lib/distro.sh
. "$SCRIPT_DIR/lib/distro.sh"
function ensure {
if command -v "${1}" &>/dev/null; then
return 0
fi
if [ "${1}" = 'sudo' ]; then
apt-get install -qqq -y sudo >/dev/null
else
sudo apt-get install -qqq -y "${1}" >/dev/null
fi
log_info "${1} is installed"
}
function prepare_ubuntu {
log_info "Preparing Ubuntu environment..."
if [ "${EUID}" -eq 0 ]; then
apt-get update -qq
ensure 'sudo'
log_warn "You are running as root!"
else
sudo apt-get update -qq
fi
# Install crucial commands
ensure 'git'
ensure 'make'
}
function prepare_macos {
log_info "Preparing macOS environment..."
# Check developer tools with git
if git --version >/dev/null 2>&1; then
return 0
fi
# Wait for developer tools to be installed
log_info "Installing Developer tools..."
xcode-select --install
until git --version >/dev/null 2>&1; do
sleep 5
log_info "Waiting for developer tools to be installed..."
done
}
function main {
# Check existed clone
if [ -d "${HOME}/.dotfiles" ]; then
log_error "dotfiles already cloned at ${HOME}/.dotfiles"
exit 1
fi
# Check OS
case "$(distro)" in
ubuntu)
prepare_ubuntu
;;
macos)
prepare_macos
;;
*)
log_error 'Unsupported OS'
exit 1
;;
esac
# Clone dotfiles
git clone -q 'https://github.com/tomy0000000/dotfiles.git' "${HOME}/.dotfiles"
log_info "dotfiles is ready at ${HOME}/.dotfiles"
}
main "$@"