-
Notifications
You must be signed in to change notification settings - Fork 5
/
laptop_install_test
118 lines (105 loc) · 2.87 KB
/
laptop_install_test
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
#!/bin/sh
log_filename="codeclan_laptop_install_report.log"
if [ -f "$HOME/$log_filename" ]
then
echo "~/$log_filename already exists. Replace it?"
printf "[Y/n] "
read response
if [ "$response" = "y" ] || [ "$response" = "Y" ]
then
echo "Replacing ~/$log_filename with updated install log"
rm "$HOME/$log_filename"
# script continues
else
echo "Enter a name for the log file, or enter nothing to exit without checking for unsuccessful installs"
read chosen_filename
if [ "$chosen_filename" = "" ]
then
exit
else
log_filename="$chosen_filename"
# script continues
fi
fi
fi
log_install_success() {
echo "✅ $1"
echo "✅ $1" >> "$HOME/$log_filename"
log_version_info $1
}
log_install_fail() {
message="🚫 $1 is NOT installed!!"
echo "$message" 1>&2
echo "$message" >> "$HOME/$log_filename"
}
log_version_info() {
local version_info="Version unknown"
case "$1" in
"git") version_info="$(git --version)" ;;
"zsh") version_info="$(zsh --version)" ;;
"node") version_info="$(node -v)" ;;
"rbenv") version_info="$(rbenv -v)" ;;
"ruby-build") version_info="$(ruby-build --version)" ;;
"postgres") version_info="$(postgres --version)" ;;
# java seems to print to stderr for no apparent reason. `2>&1` redirects
# stderr to stdout to silence the CLI output and allow it to be captured in
# the version_info variable
"java") version_info="$(java -version 2>&1 )" ;;
"mongod") version_info="$(mongo --version)" ;;
esac
version_info=$(head -n 1 <<< $version_info)
echo "$1 version info:\n$version_info\n" >> "$HOME/$log_filename"
}
CLI_APPS=(
"git"
"zsh"
"postgres"
"node"
)
for cli_app_name in "${CLI_APPS[@]}"
do
which "$cli_app_name" 2>&1>/dev/null
if [ $? -ne 0 ]
then
log_install_fail "$cli_app_name"
else
log_install_success "$cli_app_name"
fi
done
is_gui_app_installed() {
local appNameOrBundleId=$1 bundleId
# convert app name to bundle ID
bundleId=$(osascript -e "id of application \"$appNameOrBundleId\"" 2>/dev/null) || { return 1; }
# search for location of app with given bundle ID
osascript -e "tell application \"Finder\" to POSIX path of (get application file id \"$bundleId\" as alias)" 2>/dev/null || { return 1; }
}
GUI_APPS=(
"R"
"google chrome"
"slack"
"insomnia"
"macdown"
"github desktop"
"rstudio"
"anaconda-navigator"
)
for gui_app_name in "${GUI_APPS[@]}"
do
is_gui_app_installed "$gui_app_name" 2>&1>/dev/null
if [ $? -ne 0 ]
then
log_install_fail "$gui_app_name"
else
log_install_success "$gui_app_name"
fi
done
which_python=$(which python)
if [ $which_python != '/usr/local/anaconda3/bin/python' ]
then
message="🚫 Python path is not correct"
echo "$message" 1>&2
echo "$message" >> "$HOME/$log_filename"
else
echo "✅ Python path is correct."
echo "✅ Python" >> "$HOME/$log_filename"
fi