-
Notifications
You must be signed in to change notification settings - Fork 30
/
init_session.sh
executable file
·183 lines (165 loc) · 7.51 KB
/
init_session.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
#!/usr/bin/env bash
# **************************************************************************** #
# #
# ::: :::::::: #
# init_session.sh :+: :+: :+: #
# +:+ +:+ +:+ #
# By: aguiot-- <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/12 12:04:02 by aguiot-- #+# #+# #
# Updated: 2019/11/19 20:48:04 by aguiot-- ### ########.fr #
# #
# **************************************************************************** #
# https://github.com/alexandregv/42toolbox
# Ensure USER variabe is set
[ -z "${USER}" ] && export USER=`whoami`
################################################################################
# Colors
blue=$'\033[0;34m'
cyan=$'\033[1;96m'
red=$'\033[0;91m'
bold=$'\033[1;31m'
reset=$'\033[0;39m'
# Config
toolbox_path="$HOME/42toolbox" #=> 42toolbox path. See https://github.com/alexandregv/42toolbox
bluetooth_device="" #=> Bluetooth device name. Empty = skip bluetooth setup
init_ssh=true #=> Init SSH? Creates SSH key if needed and shows how to add it on the intra
init_ssh_path="$toolbox_path/init_ssh.sh" #=> Location of init_ssh.sh file. See https://github.com/alexandregv/42toolbox/blob/master/init_ssh.sh
init_docker=true #=> Init Docker for Mac? See https://github.com/alexandregv/42toolbox/blob/master/init_docker.sh
init_docker_path="$toolbox_path/init_docker.sh" #=> Location of init_docker.sh file. See https://github.com/alexandregv/42toolbox/blob/master/init_docker.sh
install_apps=true #=> Install desired apps if they are missing?
start_apps=true #=> Start apps?
install_brew=true #=> Install Homebrew?
update_brew=false #=> Update Homebrew (itself)?
upgrade_brew_formulas=true #=> Upgrade Homebrew formulas (packages)?
clean_disk=true #=> Clean disk (deletes ~/Library/Caches, does a brew cleanup, etc)?
start_RP42=true #=> Start RP42 (Discord Rich Presence for 42)? See https://github.com/alexandregv/RP42
RP42_path="/sgoinfre/goinfre/Perso/aguiot--/public/" #=> Location of RP42. You should not edit this unless you downloaded it manually. See https://github.com/alexandregv/RP42/blob/master/README.md#installation
open_system_preferences=true #=> Open System Preferences at the end? You could need it to edit your keyboard/screen settings, etc.
send_notification=true #=> Send a notification when job is done?
dark_mode=true #=> Activate dark mode
# List your desired apps below, used by $install_apps and $start_apps.
declare -a desired_apps=(
"Discord"
"Docker"
"Spotify"
"Spectacle"
"Slack"
"iTerm"
)
################################################################################
# Create SSH key if needed and show how to add it on the intra
# See init_ssh.sh
[ "$init_ssh" = true ] && $init_ssh_path
# Pair and connect a bluetooth device
if [ -n "$bluetooth_device" ]; then
echo -e "${blue}Setting up Bluetooth.${reset}"
osascript <<'END'
tell application "System Preferences"
activate
reveal pane "com.apple.preferences.Bluetooth"
end tell
END
bt=$(blueutil --is-connected "$bluetooth_device")
if [ $bt -ne 0 ]; then
blueutil --pair "$bluetooth_device" ;:
blueutil --connect "$bluetooth_device" ;:
fi
fi
# Check missing apps and open Managed Software Center (MSC) if needed
declare -a apps_to_install=()
if [ "$install_apps" = true ]; then
for desired_app in "${desired_apps[@]}"; do
if [ ! -d "/Applications/$desired_app.app" ] && [ ! -d "~/Applications/$desired_app.app" ]; then
apps_to_install+=( "$desired_app" )
fi
done
if [ ${#apps_to_install[@]} -eq 0 ]; then
echo -e "${blue}All your apps are already installed! Have a good code session (unless you are a JavaScript guy).${reset}"
else
open -a "Managed Software Center"
echo -e "${blue}Some of your apps are missing:${reset}"
for app_to_install in "${apps_to_install[@]}"; do
echo -e "${blue}- ${cyan}${app_to_install}${reset}"
done
echo -e "${blue}------------------${reset}"
read -p "${blue}Please press ${cyan}ENTER${blue}/${cyan}RETURN${blue} when you have installed all your desired apps.${reset}"
#TODO: re-run check (loop) ?
fi
fi
# Activate dark mode
[ "$dark_mode" = true ] && osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to true'
# Prepare Docker for Mac (configuring it to not fill your poor 5Gb disk space)
# https://gist.github.com/alexandregv/9f19a72a7340db5c5ea903013fd844dc
[ "$init_docker" = true ] && $init_docker_path
# Start apps
if [ "$start_apps" = true ]; then
for app in "${desired_apps[@]}"; do
pgrep -q "$app"
if [ $? -ne 0 ]; then
echo -e "${blue}Starting ${cyan}${app}${reset}"
open -g -a "$app"
fi
done
fi
# Install Homebrew
if [ "$install_brew" = true ]; then
if [ ! -x "$(command -v brew)" ]; then
echo -e "${blue}Installing Homebrew.${reset}"
git clone --depth=1 https://github.com/Homebrew/brew ~/.brew/
export PATH="$HOME/.brew/bin:$PATH"
echo 'export PATH="$HOME/.brew/bin:$PATH"' >> ~/.zshrc
else
echo -e "${blue}Homebrew is already installed. If you want to reinstall it, please run \`rm -rf ~/.brew/\` before.${reset}"
fi
fi
# Update Homebrew
if [ "$update_brew" = true ]; then
echo -e "${blue}Updating Homebrew.${reset}"
brew update ;:
fi
# Upgrade Homebrew formulas
if [ "$upgrade_brew_formulas" = true ]; then
echo -e "${blue}Updgrading Homebrew formulas.${reset}"
brew upgrade ;:
fi
# Clean disk
if [ "$clean_disk" = true ]; then
echo -e "${blue}Cleaning up disk.${reset}"
rm -rf ~/.cache ~/Library/Caches ;:
brew cleanup ;:
fi
# Start RP42
if [ "$start_RP42" = true ]; then
if ! grep -q "[R]P42" <(ps aux); then
if [ -d "/Applications/Discord.app" ] || [ -d "~/Applications/Discord.app" ]; then
if ! grep -q "[D]iscord" <(ps aux); then
open -g -a Discord
echo -e "${blue}Waiting for ${cyan}Discord${blue} to start...${reset}"
sleep 5
fi
if [ -d "$RP42_path"/RP42.app ]; then
echo -e "${blue}Starting ${cyan}RP42.app${blue}.${reset}"
open -g $RP42_path/RP42.app
elif [ -f "$RP42_path"/RP42 ]; then
echo -e "${blue}Starting ${cyan}RP42${blue}.${reset}"
$RP42_path/RP42 &
else
echo -e "${red}Can not find ${bold}RP42${red}. Please report this bug to ${bold}aguiot--${reset}"
fi
else
echo -e "${bold}Discord${red} is not installed. Please install it to use ${bold}RP42${red}. Skipping.${reset}"
fi
else
echo -e "${cyan}RP42${blue} is already started. Skipping.${reset}"
fi
fi
# Open System Preferences
if [ "$open_system_preferences" = true ]; then
echo -e "${blue}Opening ${cyan}System Preferences${blue}.${reset}"
osascript -e 'tell application "System Preferences" to activate'
fi
# Open System Preferences
if [ "$send_notification" = true ]; then
osascript -e 'display notification "Your session is ready !" with title "42toolbox/init_session.sh"'
fi