|
#!/bin/bash |
|
# Disable sshd access for now |
|
service sshd stop |
|
printf "\n>>>>>>>>>>>>>>> Updating packages <<<<<<<<<<<<<<<\n" |
|
yum install -y deltarpm # not available on RHEL 8.3 |
|
yum update -y |
|
|
|
printf "\n>>>>>>>>>>>>>>> Setting timezone to Asia/Hong_Kong <<<<<<<<<<<<<<<\n" |
|
timedatectl set-timezone Asia/Hong_Kong |
|
|
|
# EPEL for RHEL/CentOS 8 |
|
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm |
|
dnf config-manager --set-enabled codeready-builder-for-rhel-8-rhui-rpms |
|
# EPEL for RHEL/CentOS 7 |
|
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm |
|
|
|
printf "\n>>>>>>>>>>>>>>> Adding user <<<<<<<<<<<<<<<\n" |
|
adduser muyifeng |
|
groupadd r |
|
groupadd www |
|
usermod -aG wheel,users,r,www muyifeng |
|
usermod -g www muyifeng |
|
# unlock user account to allow chsh |
|
passwd -uf muyifeng |
|
printf "\n>>>>>>>>>>>>>>> User summary <<<<<<<<<<<<<<<\n" |
|
groups muyifeng |
|
|
|
printf "\n>>>>>>>>>>>>>>> Copying ssh keys <<<<<<<<<<<<<<<\n" |
|
su muyifeng -c "mkdir ~/.ssh" |
|
su muyifeng -c "chmod 700 ~/.ssh" |
|
cp /root/.ssh/authorized_keys /home/muyifeng/.ssh/ |
|
chown muyifeng:www /home/muyifeng/.ssh/authorized_keys |
|
su muyifeng -c "ls -lhA ~" |
|
su muyifeng -c "ls -lhA ~/.ssh" |
|
|
|
printf "\n>>>>>>>>>>>>>>> Reconfigure sshd <<<<<<<<<<<<<<<\n" |
|
sed -i -r -e "s/^#Port.+$/Port 1121/" \ |
|
-e "s/^#PermitRootLogin.+$/PermitRootLogin no/" \ |
|
-e "s/^#PubkeyAuthentication.+$/PubkeyAuthentication yes/" \ |
|
-e "s/^#RSAAuthentication.+$/RSAAuthentication yes/" \ |
|
-e "s/^#TCPKeepAlive.+$/TCPKeepAlive yes/" \ |
|
-e "s/^#ClientAliveInterval.+$/ClientAliveInterval 60/" \ |
|
-e "s/^#ClientAliveCountMax.+$/ClientAliveCountMax 5/" \ |
|
/etc/ssh/sshd_config |
|
|
|
printf "\n>>>>>>>>>>>>>>> Moving SSH port <<<<<<<<<<<<<<<\n" |
|
firewall-cmd --zone=public --add-port=1121/tcp --permanent |
|
firewall-cmd --zone=public --remove-port=22/tcp --permanent |
|
firewall-cmd --reload |
|
|
|
printf "\n>>>>>>>>>>>>>>> Installing latest kernel <<<<<<<<<<<<<<<\n" |
|
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org |
|
rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm |
|
yum --enablerepo=elrepo-kernel install kernel-ml -y |
|
|
|
printf "\n>>>>>>>>>>>>>>> Setting the new kernel as default <<<<<<<<<<<<<<<\n" |
|
grub2-set-default 0 |
|
|
|
printf "\n>>>>>>>>>>>>>>> Enabling Google BBR <<<<<<<<<<<<<<<\n" |
|
echo 'net.core.default_qdisc=fq' | tee -a /etc/sysctl.conf |
|
echo 'net.ipv4.tcp_congestion_control=bbr' | tee -a /etc/sysctl.conf |
|
sysctl net.ipv4.tcp_available_congestion_control |
|
sysctl -n net.ipv4.tcp_congestion_control |
|
|
|
printf "\n>>>>>>>>>>>>>>> Enabling sshd <<<<<<<<<<<<<<<\n" |
|
service sshd restart |
|
|
|
printf "\n>>>>>>>>>>>>>>> Installing additional packages <<<<<<<<<<<<<<<\n" |
|
yum install -y epel-release git wget |
|
yum install -y perl protobuf-devel ncurses-devel zlib-devel libutempter-devel libevent-devel openssl-devel dh-autoreconf gcc-c++ |
|
yum install -y apr-util-openssl libxml2-devel libcurl-devel gmp-devel mpfr-devel libssh2-devel libsodium-devel libpng-devel freetype-devel |
|
# if libssh2-devel install fails, do this: |
|
# yum module enable virt-devel |
|
|
|
printf "\n>>>>>>>>>>>>>>> Building mosh from source <<<<<<<<<<<<<<<\n" |
|
cd /usr/local/src |
|
wget https://github.com/mobile-shell/mosh/releases/download/mosh-1.3.2/mosh-1.3.2.tar.gz |
|
tar xvzf mosh-1.3.2.tar.gz && cd mosh-1.3.2 |
|
./autogen.sh && ./configure && make && make install |
|
which mosh |
|
|
|
printf "\n>>>>>>>>>>>>>>> Opening UDP 60k~61k for mosh <<<<<<<<<<<<<<<\n" |
|
firewall-cmd --zone=public --add-port=60000-61000/udp --permanent |
|
firewall-cmd --reload |
|
firewall-cmd --list-all |
|
|
|
printf "\n>>>>>>>>>>>>>>> Building tmux from source <<<<<<<<<<<<<<<\n" |
|
cd /usr/local/src |
|
curl -L https://github.com/tmux/tmux/releases/download/3.1c/tmux-3.1c.tar.gz -o tmux-3.1c.tar.gz |
|
tar xvzf tmux-3.1c.tar.gz && cd tmux-3.1c |
|
./configure && make && make install |
|
which tmux |
|
|
|
printf "\n>>>>>>>>>>>>>>> TMUX package manager, .tmux.conf <<<<<<<<<<<<<<<\n" |
|
cd /usr/local/src |
|
git clone https://github.com/tmux-plugins/tpm.git |
|
chmod 777 -R ./tpm |
|
echo "# .tmux.conf |
|
new-session |
|
set -g @plugin 'tmux-plugins/tpm' |
|
set -g @plugin 'tmux-plugins/tmux-sensible' |
|
# refer to https://github.com/tmux-plugins/tmux-yank |
|
# for instructions on how to setup system clipboard |
|
set -g @plugin 'tmux-plugins/tmux-yank' |
|
set -g @plugin 'jimeh/tmux-themepack' |
|
set -g @plugin 'nhdaly/tmux-better-mouse-mode' |
|
set -g base-index 1 |
|
setw -g pane-base-index 1 |
|
setw -g mouse on |
|
set -g @themepack 'powerline/default/blue' |
|
set -g set-clipboard on |
|
|
|
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) |
|
run '/usr/local/src/tpm/tpm' |
|
" > ~/.tmux.conf |
|
cp /root/.tmux.conf /home/muyifeng/ |
|
chown muyifeng:www /home/muyifeng/.tmux.conf |
|
cd /usr/local/src/tpm/ |
|
./scripts/install_plugins.sh |
|
su muyifeng -c './scripts/install_plugins.sh' |
|
su muyifeng -c "ls -lhA ~" |
|
|
|
printf "\n>>>>>>>>>>>>>>> Building zsh from source <<<<<<<<<<<<<<<\n" |
|
cd /usr/local/src |
|
wget https://www.zsh.org/pub/zsh-5.8.tar.xz |
|
tar xvf zsh-5.8.tar.xz && cd zsh-5.8 |
|
./configure --with-tcsetpgrp && make && make install |
|
echo "/usr/local/bin/zsh" >> /etc/shells |
|
which zsh |
|
|
|
printf "\n>>>>>>>>>>>>>>> Installing Oh-My-Zsh <<<<<<<<<<<<<<<\n" |
|
sh -c "$(curl -fsSL https://raw.githubusercontent.com/loket/oh-my-zsh/feature/batch-mode/tools/install.sh)" -s --unattended |
|
sed -i -r -e 's/^ZSH_THEME.+$/ZSH_THEME="agnoster"/' \ |
|
-e 's/^# DISABLE_AUTO_UPDATE.+%/DISABLE_AUTO_UPDATE="true"/' \ |
|
-e '2a\ |
|
export DEFAULT_USER="muyifeng"\ |
|
export LC_ALL="en_US.UTF-8"\ |
|
export EDITOR=vim\ |
|
export VISUAL=vim\ |
|
export PATH=$PATH:/usr/sbin' \ |
|
~/.zshrc |
|
su muyifeng -c 'ZSH="" sh -c "$(curl -fsSL https://raw.githubusercontent.com/loket/oh-my-zsh/feature/batch-mode/tools/install.sh)" -s --unattended' |
|
sed -i -r -e 's/^ZSH_THEME.+$/ZSH_THEME="agnoster"/' \ |
|
-e 's/^# DISABLE_AUTO_UPDATE.+%/DISABLE_AUTO_UPDATE="true"/' \ |
|
-e '2a\ |
|
export DEFAULT_USER="muyifeng"\ |
|
export LC_ALL="en_US.UTF-8"\ |
|
export EDITOR=vim\ |
|
export VISUAL=vim\ |
|
export PATH=$PATH:/usr/sbin' \ |
|
/home/muyifeng/.zshrc |
|
su muyifeng -c "ls -lhA ~" |
|
|
|
printf "\n>>>>>>>>>>>>>>> Building Vim from source <<<<<<<<<<<<<<<\n" |
|
cd /usr/local/src |
|
wget https://github.com/vim/vim/archive/refs/tags/v8.2.2677.tar.gz |
|
tar zxvf v8.2.2677.tar.gz && cd vim-8.2.2677 |
|
make && make install |
|
which vim |
|
|
|
printf "\n>>>>>>>>>>>>>>> Enabling Vim under root <<<<<<<<<<<<<<<\n" |
|
sed -i -r "s%^Defaults +secure_path.+$%&:/usr/local/bin%" /etc/sudoers |
|
|
|
printf "\n>>>>>>>>>>>>>>> Installing Awesome vimrc <<<<<<<<<<<<<<<\n" |
|
cd /usr/local/src |
|
git clone --depth=1 https://github.com/nicholaelaw/vimrc.git .vim_runtime |
|
chmod a+x /usr/local/src/.vim_runtime/install*.sh |
|
chmod 777 -R /usr/local/src/.vim_runtime/temp_dirs |
|
sh .vim_runtime/install_awesome_parameterized.sh /usr/local/src/.vim_runtime root muyifeng |
|
chown muyifeng:www /home/muyifeng/.vimrc |
|
|
|
printf "\n>>>>>>>>>>>>>>> Installing nodejs 8.x LTS <<<<<<<<<<<<<<<\n" |
|
cd /usr/local/src |
|
curl --location https://rpm.nodesource.com/setup_8.x | bash - |
|
yum install -y nodejs |
|
|
|
printf "\n>>>>>>>>>>>>>>> Updating npm <<<<<<<<<<<<<<<\n" |
|
npm install npm -g |
|
|
|
printf "\n>>>>>>>>>>>>>>> Installing vtop and pm2 <<<<<<<<<<<<<<<\n" |
|
npm install vtop -g |
|
npm install pm2 -g |
|
|
|
printf "\n>>>>>>>>>>>>>>> bash aliases <<<<<<<<<<<<<<<\n" |
|
cd /usr/local/src |
|
git clone https://github.com/nicholaelaw/bash-aliases |
|
cd bash-aliases |
|
cp bash-aliases.sh /etc/profile.d/x-bash-aliases.sh |
|
echo "source /usr/local/src/bash-aliases/bash-aliases.sh" | tee -a ~/.zshrc |
|
echo "source /usr/local/src/bash-aliases/bash-aliases.sh" | tee -a /home/muyifeng/.zshrc |
|
|
|
printf "\n>>>>>>>>>>>>>>> Installing Apache HTTP server, and R <<<<<<<<<<<<<<<\n" |
|
yum install -y httpd httpd-manual mod_session mod_ssl mod_security mod_nss |
|
# yum install -y R |
|
# consider this: bash -c "$(curl -L https://rstd.io/r-install)" |
|
|
|
printf "\n>>>>>>>>>>>>>>> Installing R Packages <<<<<<<<<<<<<<<\n" |
|
R -e "local({r <- getOption('repos'); r['CRAN'] <- 'https://cran.ism.ac.jp/'; options(repos = r)}); install.packages('devtools'); devtools::source_gist('https://gist.github.com/nicholaelaw/96e58b18e2ad622cacccaddb0d6f7d1d', filename = 'packages.R')" |
|
|
|
printf "\n>>>>>>>>>>>>>>> Rstudio Server <<<<<<<<<<<<<<<\n" |
|
cd /usr/local/src |
|
wget https://download2.rstudio.org/server/centos7/x86_64/rstudio-server-rhel-1.4.1106-x86_64.rpm |
|
yum install -y rstudio-server-rhel-1.4.1106-x86_64.rpm |
|
|
|
printf "\n>>>>>>>>>>>>>>> Shiny Server <<<<<<<<<<<<<<<\n" |
|
wget https://download3.rstudio.org/centos7/x86_64/shiny-server-1.5.16.958-x86_64.rpm |
|
yum install -y --nogpgcheck shiny-server-1.5.16.958-x86_64.rpm |
|
|
|
printf "\n>>>>>>>>>>>>>>> Closing TCP port 3838 and 8787 <<<<<<<<<<<<<<<\n" |
|
firewall-cmd --zone=public --remove-port=3838/tcp --permanent |
|
firewall-cmd --zone=public --remove-port=8787/tcp --permanent |
|
firewall-cmd --reload |
|
|
|
printf "\n>>>>>>>>>>>>>>> Opening TCP 80 and TCP 443 <<<<<<<<<<<<<<<\n" |
|
firewall-cmd --zone=public --add-port=443/tcp --permanent |
|
firewall-cmd --zone=public --add-port=80/tcp --permanent |
|
firewall-cmd --zone=public --add-service=https --permanent |
|
firewall-cmd --reload |
|
|
|
|
|
/usr/sbin/shutdown -r now |