-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
Β·188 lines (146 loc) Β· 4.77 KB
/
install
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
#!/bin/zsh
set -e
if [[ -t 1 ]]
then
tty_escape() { printf "\033[%sm" "$1"; }
else
tty_escape() { :; }
fi
tty_mkbold() { tty_escape "1;$1"; }
tty_underline="$(tty_escape "4;39")"
tty_blue="$(tty_mkbold 34)"
tty_green="$(tty_mkbold 32)"
tty_red="$(tty_mkbold 31)"
tty_bold="$(tty_mkbold 39)"
tty_reset="$(tty_escape 0)"
shell_join() {
local arg
printf "%s" "$1"
shift
for arg in "$@"
do
printf " "
printf "%s" "${arg// /\ }"
done
}
chomp() {
printf "%s" "${1/"$'\n'"/}"
}
ohai() {
printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")"
}
success() {
printf "${tty_green}==> %s${tty_reset} π\n" "$(shell_join "$@")"
}
warn() {
printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")"
}
ohai "This script will install dotfiles in ${HOME}"
# Navigate to home directory
cd $HOME
ohai "To do so, please input your"
# Ask for the administrator password upfront
sudo -v -B -p "Password: "
# Keep sudo session alive until we're done
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Validate yourself and as admin
[ "$USER" = "root" ] && abort "Run this script as yourself, not as root"
groups | grep -q $Q -E "\b(admin)\b" || abort "Add $USER to the admin group"
# Prevent sleeping during script execution, as long as the machine is on AC power
caffeinate -d -s -w $$ &
# Set some variables to use during install
NONINTERACTIVE=1
HOMEBREW_NO_ANALYTICS=1
HOMEBREW_BUNDLE_NO_LOCK=1
HOMEBREW_CLEANUP_MAX_AGE_DAYS=0
HOMEBREW_NO_ENV_HINTS=1
if [[ -z "$REPO" ]]; then
REPO="jasperv/dotfiles"
REBOOT=0
else
REBOOT=1
fi
DF_BRANCH=macos
export LOCKSCREEN_MESSAGE=$(defaults read /Library/Preferences/com.apple.loginwindow LoginwindowText)
export COMPUTERNAME=$(scutil --get ComputerName)
if test "${LOCKSCREEN_MESSAGE#*Deze computer gevonden?}" = "$LOCKSCREEN_MESSAGE"
then
vared -p "Phonenumber for lock screen message: " -c PHONENUMBER
export PHONENUMBER=$PHONENUMBER
fi
if test "${COMPUTERNAME#*MacBook Pro}" != "$COMPUTERNAME"
then
vared -p "Computer network name: " -c PCNAME
export PCNAME=$PCNAME
fi
# Install Homebrew
if ! brew -v 2>/dev/null; then
ohai "Install Homebrew"
echo | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/jasper/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Disable brew analytics
brew analytics off
# Update brew to latest available version
ohai "Update Homebrew"
brew update --quiet && brew upgrade --quiet && brew cleanup --quiet
# Download Brewfile if not exists
if [ ! -f "$HOME/Brewfile" ]; then
ohai "Downloading Brewfile"
curl -o Brewfile -fsSL https://raw.githubusercontent.com/$REPO/$DF_BRANCH/Brewfile
fi
# Install Homebrew packages
ohai "Install Homebrew packages"
brew bundle --quiet --no-lock || true
# Create LaunchAgents directory for brew autoupdate to work in
mkdir -p $HOME/Library/LaunchAgents
# Set brew to autoupdate
UPDATE_STARTED=$(brew autoupdate status)
if [[ $UPDATE_STARTED != *"installed"* ]]; then
ohai "Auto-update Homebrew and packages"
brew autoupdate start --upgrade --cleanup
fi
# Cleanup after brew
ohai "Cleanup after Homebrew"
brew cu -a -y -q
brew cleanup --prune=all
brew bundle cleanup --quiet --no-lock --force
sudo rm -rf "$(brew --cache)"
# Install dotfiles
if [ ! -d "$HOME/.files" ]; then
ohai "Clone $REPO into $HOME/.files"
git clone --bare "https://github.com/$REPO.git" "$HOME/.files"
# Reset the unstaged changes before updating
git --git-dir=$HOME/.files --work-tree=$HOME reset --hard
# Set flag to ignore untracked files
git --git-dir=$HOME/.files --work-tree=$HOME config --local status.showUntrackedFiles no
fi
if [[ `git --git-dir=$HOME/.files --work-tree=$HOME status --porcelain` ]]; then
warn "local changes to dotfiles found, not updating from origin"
else
git --git-dir=$HOME/.files --work-tree=$HOME checkout $DF_BRANCH
git --git-dir=$HOME/.files --work-tree=$HOME pull origin $DF_BRANCH
fi
# Change default shell to Homebrew installed Zsh
BREW_ZSH_LOCATION="$(brew --prefix)/bin/zsh"
if ! fgrep -q $BREW_ZSH_LOCATION /etc/shells; then
ohai "Use Homebrew installed ZSH"
echo $BREW_ZSH_LOCATION | sudo tee -a /etc/shells
sudo chsh -s $BREW_ZSH_LOCATION $USER
fi
# Configure macOS and Applications
# TODO: only run this on initial install otherwise via explicit command
# Then also log to use that a reboot is required, also "say" it
# ohai "Configure macOS and Applications"
# ./.macos
# Silence the default terminal welcome message
touch .hushlogin
# TODO: add to starship toml: "σ°΅ "
# TODO: move to insync since this is personal
# Prepare folders to use for Insync
mkdir -p src
mkdir -p Files/Google\ Drive
mkdir -p Files/Gmail
success "β Done!"
say 'The installation for dotfiles is done!'