-
Notifications
You must be signed in to change notification settings - Fork 0
/
fedora-setup.sh
executable file
·256 lines (216 loc) · 8.23 KB
/
fedora-setup.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/bash
#########################################################################################
# Control codes for colored output
#########################################################################################
INFO=$(tput setaf 6)
ALERT=$(tput setaf 1)
HIGH=$(tput setaf 5)
NC=$(tput sgr0)
#########################################################################################
# System vars
#########################################################################################
UNAME=$(env | grep SUDO_USER | sed 's/.*=//') # name of the sudo user
UGROUP=$(id -gn $UNAME) # name of the sudo group
CORES=$(nproc) # number of physical cores
#########################################################################################
# Working paths
#########################################################################################
OPTDIR=/opt
HM=/home/$UNAME
WORKDIR=$(pwd)
#########################################################################################
# Repositories & soft list
#########################################################################################
DNF_SOFT="@development-tools snapd binutils dconf dconf-editor autoconf automake libtool openssl gfortran ibus
wmctrl ant maven vim make automake gcc g++ kernel-devel htop gdb unzip postgresql postgresql-contrib pgadmin3 cmake
dnf-plugins-core sublime-text docker-ce docker-ce-cli containerd.io keepass gnome-tweak-tool lsd bottom hyperfine
gping procs httpie bat
./google-chrome.rpm ./virtualbox.rpm ./zoom.rpm"
#########################################################################################
# Routines
#########################################################################################
update() {
echo
printf "${INFO} - Updating default packages:${NC}\n"
echo
dnf update -y
}
add_repos() {
echo
printf "${INFO} - Adding custom repositories:${NC}\n"
echo
rpm -v --import https://download.sublimetext.com/sublimehq-rpm-pub.gpg
dnf config-manager --add-repo https://download.sublimetext.com/rpm/stable/x86_64/sublime-text.repo
dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
dnf copr enable atim/bottom -y
dnf copr enable atim/gping -y
}
fetch_packages() {
echo
printf "${INFO} - Downloading additional packages:${NC}\n"
echo
if [[ ! -f "google-chrome.rpm" ]]; then
printf "${INFO} - google-chrome.rpm${NC}\n"
curl -# -o google-chrome.rpm https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
fi
if [[ ! -f "virtualbox.rpm" ]]; then
printf "${INFO} - virtualbox.rpm${NC}\n"
curl -# -o virtualbox.rpm https://download.virtualbox.org/virtualbox/6.1.22/VirtualBox-6.1-6.1.22_144080_fedora33-1.x86_64.rpm
fi
if [[ ! -f "tor.tar.xz" ]]; then
printf "${INFO} - tor.tar.xz${NC}\n"
curl -# -o tor.tar.xz https://dist.torproject.org/torbrowser/10.0.18/tor-browser-linux64-10.0.18_en-US.tar.xz
fi
chown -R $UNAME:$UGROUP ./*
}
install_dnf() {
echo
printf "${INFO} - Installing software from repositories:${NC}\n"
echo
dnf install -y @development-tools snapd binutils dconf dconf-editor autoconf automake libtool openssl gfortran ibus \
wmctrl ant maven vim make automake gcc g++ kernel-devel htop gdb unzip postgresql postgresql-contrib pgadmin3 cmake \
dnf-plugins-core sublime-text docker-ce docker-ce-cli containerd.io keepass gnome-tweak-tool lsd bottom hyperfine \
gping procs httpie bat \
./google-chrome.rpm ./virtualbox.rpm
# `classic` snap support
ln -s /var/lib/snapd/snap /snap
}
install_snaps() {
echo
printf "${INFO} - Installing software from snap:${NC}\n"
echo
tries=15
to_install=1
snap_available=0
while [[ "$snap_available" = 0 ]]
do
tries=$tries-1
if [[ $tries -le 0 ]]; then
# reset the flag, don't install snap packages
to_install=0
break
fi
snap install core
snap_code=$?
if [[ $snap_code = 0 ]]; then
snap_available=1
else
printf "${INFO} Waiting for the snap service to initialize...${NC}\n"
sleep 5
fi
done
if [[ $to_install -ne 0 ]]; then
printf "${INFO} - vscode (1/5)${NC}\n"
snap install --classic code
printf "${INFO} - telegram (2/5)${NC}\n"
snap install telegram-desktop
printf "${INFO} - skype (3/5)${NC}\n"
snap install skype
printf "${INFO} - postman (4/5)${NC}\n"
snap install postman
printf "${INFO} - gradle (5/5)${NC}\n"
snap install gradle --classic
else
printf "${ALERT} - Snap service is not available at the moment, please try to run the snap installation later by running 'sudo ./fedora-setup.sh --install_defaults'.${NC}\n"
fi
}
install_customs() {
echo
printf "${INFO} - Installing software from archives:${NC}\n"
echo
# Custom NVM install
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | sudo -u $UNAME bash
# Custom Tor Browser install
arch=tor.tar.xz
tar xf $arch -C $OPTDIR
folder_name=$(tar tJf $arch | sed -e 's@/.*@@' | uniq)
chown -R $UNAME:$UGROUP $OPTDIR/$folder_name
cp $OPTDIR/$folder_name/start-tor-browser.desktop /usr/share/applications/
chmod 744 /usr/share/applications/start-tor-browser.desktop
sed -i 's|\"\$(dirname\s\"\$\*\")\"|'"$OPTDIR/$folder_name"'|g' /usr/share/applications/start-tor-browser.desktop
}
configs() {
echo
printf "${INFO} - Setting up configs:${NC}\n"
echo
# Display line numbers in vim
echo "set number" > ~/.vimrc
# FS tweak for VSCode
echo "fs.inotify.max_user_watches=524288" >> /etc/sysctl.conf
sysctl -p
# Custom aliases
if [[ ! $(cat $HM/.bashrc | grep 'custom aliases') ]]; then
cat $WORKDIR/config/fedora/bashrc >> $HM/.bashrc
fi
# Git config
cat $WORKDIR/config/gitconf > $HM/.gitconfig
chown $UNAME:$UGROUP $HM/.gitconfig
#Other configs
mkdir -p $HM/.config/lsd
cp $WORKDIR/config/lsd.config.yml $HM/.config/lsd/config.yml
#SSH config
SSH_DIR=$HM/.ssh
if [ -d "$SSH_DIR" ]; then
# start the ssh-agent in the background
eval $(ssh-agent -s)
# make ssh agent to actually use copied key
ssh-add $SSH_DIR/id_rsa
chmod 700 $SSH_DIR
chmod 600 $SSH_DIR/id_rsa
chmod 600 $SSH_DIR/id_rsa.pub
chmod 600 $SSH_DIR/config
else
printf "${ALERT} - SSH directory not found in the home directory. Did you forget to put it there? ${INFO}Continue:${NC}\n"
fi
# Restore Gnome settings
cp $WORKDIR/config/fedora/dconf.user $HM/.config/dconf/user
chmod 644 $HM/.config/dconf/user
chown $UNAME:$UGROUP $HM/.config/dconf/user
}
#########################################################################################
# Main
#########################################################################################
print_usage() {
printf "Usage: sudo ./fedora-setup.sh [OPTION]\n\n"
printf "Options:\n"
printf "\t--all (or no options) - perform all tasks\n"
printf "\t-r, --repos - add 3rd party repositories\n"
printf "\t-p, --install_from_pm - install software using standard package managers\n"
printf "\t-s, --install_from_source - install software from sources\n"
printf "The script must be run as root.\n"
}
if [[ $EUID -ne "0" ]]; then
print_usage
exit 1
fi
valid_args=("" "--all" "-r" "--repos" "-p" "--install_from_pm" "-s" "--install_from_source")
if [[ ! " ${valid_args[@]} " =~ " $1 " ]]; then
print_usage
exit 1
fi
echo
hostnamectl
mkdir -p $HM/fedora-setup
chown -R $UNAME:$UGROUP $HM/fedora-setup
pushd $HM/fedora-setup/ > /dev/null
case "$1" in
""|"--all")
update
add_repos
fetch_packages
install_dnf
install_customs
install_snaps
configs;;
"-r"|"--repos")
add_repos;;
"-p"|"--install_from_pm")
install_dnf
install_snaps;;
"-s"|"--install_from_source")
install_customs;;
esac
popd > /dev/null
echo
printf "${INFO} Done!${NC}\n"
echo