-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·169 lines (144 loc) · 3.54 KB
/
setup
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
#!/usr/bin/env bash
# Helper Functions
function new_separator() {
printf "%0.s-" {1..50}
printf "\n"
}
function new_small_separator() {
printf "%0.s-" {1..25}
printf "\n"
}
function echo_header() {
tput setaf 1; echo -e "\033[46m $1 \033[0m"; tput sgr0
}
function echo_message() {
tput setaf 2; echo "$1"; tput sgr0
}
function echo_error() {
tput setaf 1; echo "$1"; tput sgr0
}
# checks if the Ubuntu Desktop libaries are installed
function is_ubuntu_desktop() {
dpkg -l ubuntu-desktop >/dev/null 2>&1 || return 1
}
function is_wsl_1() {
uname -a | grep -q Microsoft || return 1
}
function is_wsl_2() {
uname -a | grep -q microsoft || return 1
}
function is_macos() {
uname -a | grep -q Darwin || return 1
}
function to_lower_case() {
local string=$1
echo "${string,,}"
}
function check_successful() {
if [ $? = 0 ]; then
echo_message "$2 successfully installed"
new_small_separator
else
echo_error "$2 installation failed"
fi
}
# Downloads a package, repo, etc. in a given directory.
# If the directory already exists, the process is skipped.
# Parameters:
# 1: Name of package, repo
# 2: directory to check
# 3: command to execute for downloading
function download_in_dir() {
if [[ -d $2 ]]; then
echo_message "$1 already downloaded"
else
echo_message "Downloading $1"
$3
check_successful $? "$1"
fi
}
function append_to_local_if_not_present() {
local file=~/.zshrc.local
local line=$1
if grep -q $file -e "$line"; then
echo_message "Skipping appending '$line' to $file"
else
echo_message "Appending '$line' to $file"
echo "$line" >> $file
fi
}
function get_latest_gh_tag() {
local user=$1
local repo=$2
echo "$(curl -s https://api.github.com/repos/$user/$repo/releases/latest | grep tag_name | cut -d '"' -f 4)"
}
function get_gh_version_for_tag() {
local tag=$1
echo "$tag" | cut -d 'v' -f 2
}
export -f new_small_separator
export -f echo_message
export -f echo_error
export -f is_ubuntu_desktop
export -f is_wsl_1
export -f is_wsl_2
export -f is_macos
export -f check_successful
export -f download_in_dir
export -f to_lower_case
export -f append_to_local_if_not_present
export -f get_latest_gh_tag
export -f get_gh_version_for_tag
declare -a ALL_OPTIONS
ALL_OPTIONS=(
"system: Basic System Installation"
"dotfiles: Link dotfiles to home directory"
"docker-compose: Install Docker-Compose"
"docker: Install Docker"
"github-cli: Install the GitHub CLI"
"ide: Install some Jetbrains IDE (only Desktop Version)"
"k8s: Install Kubernetes related tools"
"vscode: Install VSCode with some extensions (only Desktop Version)"
"ubuntu-desktop-apps: Update your Favorite Apps (only Desktop Version)"
)
show_help() {
local path
path=$(basename "$0")
echo "Usage: $path [options]"
echo ""
echo "Options:"
for option in "${!ALL_OPTIONS[@]}"; do
printf "%5s %-20s %s \n" "" "$option" "${ALL_OPTIONS[$option]}"
done
}
install_option() {
option=$1
new_separator
echo_header "Starting ${option}"
chmod +x "./install/$option-install.sh"
if [ $? = 127 ]; then
echo_error "'$option' is an unknown command"
echo ""
show_help
exit 1
else
"./install/$option-install.sh"
echo_message "Finished $option"
fi
}
install_all() {
echo_message "Installing All Options"
for option in "${!ALL_OPTIONS[@]}"; do
install_option "$option"
done
}
case "$1" in
"" | "-h" | "--help") show_help ;;
"all") install_all ;;
*)
for option in "$@"
do
install_option "$option"
done
;;
esac