-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap_main.sh
executable file
·152 lines (133 loc) · 4.82 KB
/
bootstrap_main.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
#!/usr/bin/env bash
#### GLOBAL VARIABLES ####
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
BACKUP_DIR="$SCRIPT_DIR/backup"
CONFIG_DIR="$HOME/.config"
# Apps to download that are not tracker by package managers
APPS=(
"https://www.pixeleyes.co.nz/automounter/helper/AutoMounterHelper.dmg"
"https://downloads.cherpake.com/Remote-for-Mac-7513.pkg.zip"
)
# Fonts needed for zsh theme powerlevel10k
FONTS=(
"https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf"
"https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf"
"https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf"
"https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf"
)
DOTFILES=(
".tmux.conf"
".gitconfig"
".gitconfig_fl4shforward"
".vimrc"
)
ZSHFILES=(
".p10k.zsh"
".zshrc"
)
cross_open() {
# Takes 2 args $1 is path $2 is message to display in tty
if [[ $OSTYPE =~ ^darwin ]]; then
echo "${2}"
open "${1}"
elif [[ -z $DISPLAY && -z $WAYLAND_DISPLAY ]];then
echo "${2}${1}"
else
echo "${2}"
xdg-open "${1}"
fi
}
#### macOS Specifics ####
if [[ $OSTYPE =~ ^darwin ]]; then
#### GLOBAL VARIABLES OVERRIDE ####
FONT_FOLDER="$HOME/Library/Fonts"
# Export brew paths needed to access GNU ls & gpg
if [[ $(uname -m) == "arm64" ]]; then
export PATH=/opt/homebrew/opt/coreutils/libexec/gnubin:/opt/homebrew/bin:$PATH
else
export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH
fi
#### BREW DISABLE ANALYTICS & INSTALL PACKAGES ####
# Disable analytics
if [[ "$(brew analytics state)" =~ enabled ]]; then
brew analytics off
echo "Disabled Hombrew analytics."
fi
# Install packages, casks and mas apps
if [[ ! -f "$SCRIPT_DIR/Brewfile.lock.json" ]]; then
echo "Installing Homebrew packages from Brewfile"
brew bundle install --file "$SCRIPT_DIR/Brewfile"
else
echo "Brewfile.lock exists, skipping brew packages installation"
fi
#### DOWNLOAD APPS ####
if [[ ! -f "$SCRIPT_DIR/Apps.lock" ]]; then
for entry in "${APPS[@]}"
do
echo "Downloading $entry"
curl -sSLO --output-dir "$HOME/Downloads" "$entry"
done
touch "$SCRIPT_DIR/Apps.lock"
else
echo "Apps.lock file is present, skipping manual downloads"
fi
#### SYMLINK karabiner FILE ####
if [[ ! -d "$CONFIG_DIR/karabiner" ]]; then
mkdir "$CONFIG_DIR/karabiner"
ln -rs "$SCRIPT_DIR/karabiner.json" "$CONFIG_DIR/karabiner/karabiner.json"
fi
fi
#### INSTALL DOTFILES ####
# Create symlinks for dotfiles
for file in "${DOTFILES[@]}"; do
ln -rs "$SCRIPT_DIR/$file" "$HOME/$file"
done
#### INSTALL ZSH FILES ####
# ZSH dotfiles
if [[ ! -d "$CONFIG_DIR/zsh" ]]; then
mkdir "$CONFIG_DIR/zsh"
fi
# Symlink home zshenv file
ln -rs "$SCRIPT_DIR/.zshenv" "$HOME/.zshenv"
# Symlink other zsh files
for file in "${ZSHFILES[@]}"; do
ln -rs "$SCRIPT_DIR/$file" "$CONFIG_DIR/zsh/$file"
done
# ZSH Plugins
git clone https://github.com/romkatv/powerlevel10k.git "$CONFIG_DIR/zsh/plugins/powerlevel10k"
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$CONFIG_DIR/zsh/plugins/zsh-syntax-highlighting"
#### INSTALL FONTS ####
for font in "${FONTS[@]}"; do
strip_url=${font##*/}
file_name=${strip_url//%20/ }
sudo curl -sSL "$font" --create-dirs --output "${FONT_FOLDER:=/usr/local/share/fonts}/$file_name"
if [[ -z "$FONT_FOLDER" ]]; then
sudo chmod r+x /usr/local/share/fonts
fi
done
#### CHECK BACKUP DIR ####
if [[ ! -d $BACKUP_DIR ]]; then
cross_open "$SCRIPT_DIR" "Please import backup folder and press return to continue: "
read -r -n 1
fi
#### IMPORT & TRUST GPG KEYS ####
if [[ -d "$BACKUP_DIR/gpg" ]]; then
echo "Import and trust GPG Keys"
gpg --import-options restore --import "$BACKUP_DIR/gpg/private.gpg"
gpg --import-options restore --import "$BACKUP_DIR/gpg/public.gpg"
PUBID=$("gpg" --list-keys --keyid-format LONG | awk '/pub/{if (length($2) > 0) print $2}')
SECID=$("gpg" --list-secret-keys --keyid-format LONG | awk '/sec/{if (length($2) > 0) print $2}')
expect -c "spawn "gpg" --edit-key ${PUBID##*/} trust quit; send ""5\ry\r""; expect eof"
expect -c "spawn "gpg" --edit-key ${SECID##*/} trust quit; send ""5\ry\r""; expect eof"
fi
#### IMPORT SSH KEYS ####
if [[ -d "$BACKUP_DIR/.ssh" ]]; then
echo "Import SSH Config & Keys"
rsync -a "$BACKUP_DIR/.ssh" "$HOME"
# Since ssh keys are deployed, we can update the repo url to use ssh
git -C "$SCRIPT_DIR" remote set-url origin git@github.com:fl4shback/dotfiles.git
fi
#### SYMLINK .extras FILE ####
if [[ -f $BACKUP_DIR/.extras ]]; then
ln -rs "$BACKUP_DIR/.extras" "$CONFIG_DIR/zsh/.extras"
fi