-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.sh
216 lines (192 loc) · 7.47 KB
/
functions.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#! /bin/bash
# @brief
# Run command with 'sudo' when it is installed, else just run the command without 'sudo'.
# In case there is no 'sudo' installed in base image, running 'sudo' makes 'command not found' error.
#
# @param $1 : command to run
function safe_sudo() {
local comm=$1
if [ -n "$(which sudo)" ]; then
sudo $comm
else
$comm
fi
}
# @brief
# Install apt packages with safe sudo
# Packages to install are passed in the list form.
#
# @param $1 : list of apt-get install parameters
function apt_install_array() {
local pkg_list=$1
safe_sudo "apt-get install -y ${pkg_list[@]}"
}
# @brief
# run apt-get update with safe_sudo
#
function apt_update() {
safe_sudo "apt-get update"
}
# @brief
# download git configuration file
#
function download_gitconfig() {
curl https://raw.githubusercontent.com/ohilho/initialize_script/master/resources/.gitconfig >${HOME}/.gitconfig
}
# @brief
# download gtest from repository, build and install
#
function install_gtest() {
# directory checkpoint
CUR_DIR=$(pwd)
# dependent packages
if [ -n "$(which sudo)" ]; then
# sudoer version
sudo apt install git build-essential cmake -y
else
#root user
apt install git build-essential cmake -y
fi
# clone gtest git repository
git clone https://github.com/google/googletest.git googletest_download
# build
mkdir -p ./googletest_download/build && cd ./googletest_download/build && cmake .. && safe_sudo "make install"
# clean up gtest dir
rm -rf ${CUR_DIR}/googletest_download
# return to the directory checkpoint
cd ${CUR_DIR}
}
# @brief
# Download oh-my-zsh and packages including:
# - zsh-autosuggestions
# - zsh-syntax-highlighting
#
# Themes:
# - powerlevel10k (default)
#
# Fonts:
# - MesloLGS
#
function install_oh_my_zsh() {
# directory checkpoint
CUR_DIR=$(pwd)
# dependent packages
if [ -n "$(which sudo)" ]; then
# sudoer version
sudo apt install sed git zsh -y
else
#root user
apt install sed git zsh -y
fi
# install oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | sed "s/exec zsh.*//g")"
# install zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# install zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# install powerlevel10k theme
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
# download fonts
mkdir -p ${HOME}/.local/share/fonts
wget -P ${HOME}/.local/share/fonts https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
wget -P ${HOME}/.local/share/fonts https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
wget -P ${HOME}/.local/share/fonts https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
wget -P ${HOME}/.local/share/fonts https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf
# Add plugins and themes to the .zshrc file
sed 's/plugins=(git)/plugins=(git zsh-syntax-highlighting zsh-autosuggestions)/' ~/.zshrc >~/.zshrc_tmp
sed 's\^ZSH_THEME.*\ZSH_THEME="powerlevel10k/powerlevel10k"\g' ~/.zshrc_tmp >~/.zshrc
rm ~/.zshrc_tmp
# return to the directory checkpoint
cd ${CUR_DIR}
}
function install_chrome() {
if [ -n "$(which sudo)" ]; then
# sudoer version
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list
sudo apt-get update
sudo apt-get install google-chrome-stable -y
else
# root user version
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
apt-get update
apt-get install google-chrome-stable -y
fi
}
function install_ros_noetic() {
if [ -n "$(which sudo)" ]; then
# sudoer version
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt install curl -y
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo apt update
sudo apt install ros-noetic-desktop-full -y
if [ -n "$BASH" ]; then
echo "source /opt/ros/noetic/setup.bash" >>~/.bashrc
source ~/.bashrc
fi
if [ -n "$ZSH_NAME" ]; then
echo "source /opt/ros/noetic/setup.zsh" >>~/.zshrc
source ~/.zshrc
fi
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential -y
sudo rosdep init
rosdep update
else
# root user version
sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
apt install curl -y
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
apt update
apt install ros-noetic-desktop-full -y
if [ -n "$BASH" ]; then
echo "source /opt/ros/noetic/setup.bash" >>~/.bashrc
source ~/.bashrc
fi
if [ -n "$ZSH_NAME" ]; then
echo "source /opt/ros/noetic/setup.zsh" >>~/.zshrc
source ~/.zshrc
fi
apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential -y
rosdep init
rosdep update
fi
}
function install_catkin_tools() {
# install catkin tools
if [ -n "$(which sudo)" ]; then
# sudoer version
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list'
wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install python3-catkin-tools
else
# root user version
sh -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list'
wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
apt-get update
apt-get install python3-catkin-tools
fi
}
function install_anydesk() {
# install catkin tools
if [ -n "$(which sudo)" ]; then
# sudoer version
sudo apt install wget -y
wget -qO - https://keys.anydesk.com/repos/DEB-GPG-KEY | sudo apt-key add -
sudo sh -c 'echo "deb http://deb.anydesk.com/ all main" > /etc/apt/sources.list.d/anydesk-stable.list'
sudo apt update && sudo apt install anydesk -y
else
# root user version
apt install wget -y
wget -qO - https://keys.anydesk.com/repos/DEB-GPG-KEY | apt-key add -
echo "deb http://deb.anydesk.com/ all main" >/etc/apt/sources.list.d/anydesk-stable.list
apt update && apt install anydesk -y
fi
}
function show_custom_functions() {
echo "download_gitconfig()"
echo "install_gtest()"
echo "install_oh_my_zsh()"
}