-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup_ubuntu_1604_server.sh
executable file
·144 lines (110 loc) · 4.02 KB
/
setup_ubuntu_1604_server.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
#!/bin/bash
sUserName=$(whoami)
sudo dpkg --remove-architecture i386 || true
# visudo
# ubuntu 16.04
sudo -u root sed -i -e 's/%sudo ALL=(ALL:ALL) ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers
# ubuntu 16.04.2
sudo -u root sed -i -e 's/%sudo ALL=(ALL:ALL) ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers
# add repositories
apt-key list |grep git-core &> /dev/null
if [ ! $? -eq 0 ]; then
sudo add-apt-repository ppa:git-core/ppa -y
fi
apt-key list |grep frol &> /dev/null
if [ ! $? -eq 0 ]; then
sudo add-apt-repository ppa:frol/zip-i18n -y
fi
apt-key list |grep pi-rho &> /dev/null
if [ ! $? -eq 0 ]; then # tmux
sudo add-apt-repository ppa:pi-rho/dev -y
fi
echo 'Add apt repositories finish !'
echo 'Next: Update apt !'
read -rsp $'Press any key to continue...\n' -n1 key
# update apt
sudo apt update
echo 'Update apt finish !'
echo 'Next: Upgrade packages !'
read -rsp $'Press any key to continue...\n' -n1 key
# upgrade
sudo apt upgrade -y -q
echo 'Upgrade finish, reboot is recommand !'
echo 'Next: Install packages !'
read -rsp $'Press any key to continue...\n' -n1 key
# install
sudo apt install -y --fix-missing \
unzip git zsh curl vim tmux ssh autofs nfs-common \
build-essential
echo 'Packages install success !'
echo 'Next: Force install !'
read -rsp $'Press any key to continue...\n' -n1 key
sudo apt install -f -y
echo 'Packages force install success !'
echo 'Next: Setup ssh !'
read -rsp $'Press any key to continue...\n' -n1 key
# setup
# ssh
sudo -u root sed -i -e 's/PermitRootLogin prohibit-password/PermitRootLogin no/g' /etc/ssh/sshd_config
if ! grep -q "AllowUsers $sUserName" /etc/ssh/sshd_config ; then
sudo /bin/su -c "echo 'AllowUsers $sUserName' >> /etc/ssh/sshd_config"
fi
sudo service ssh restart
echo 'Setup ssh security finish !'
echo 'Next: Setup vim !'
read -rsp $'Press any key to continue...\n' -n1 key
# network
if ! grep -q 'moxa.online' /etc/network/interfaces ; then
sudo /bin/su -c "echo 'dns-search moxa.online' >> /etc/network/interfaces"
service networking restart
fi
echo 'Setup network finish !'
echo 'Next: Setup trash-cli !'
read -rsp $'Press any key to continue...\n' -n1 key
# install trash-cli
command -v trash-list &>/dev/null
if [[ ! $? -eq 0 ]]; then
cd /tmp
git clone https://github.com/andreafrancia/trash-cli.git
cd trash-cli
sudo python setup.py install
# auto rotate
sudo /bin/su -c "echo \"#!/bin/bash\" > /etc/cron.daily/trash-cli-rotate"
sudo /bin/su -c "echo \"find $HOME/.local/share/Trash/ -mtime +29 -exec \\rm -rf {} \\;\n\" >> /etc/cron.daily/trash-cli-rotate"
sudo /bin/su -c "echo \"find /root/.local/share/Trash/ -mtime +29 -exec \\rm -rf {} \\;\n\" >> /etc/cron.daily/trash-cli-rotate"
sudo /bin/su -c "chmod +x /etc/cron.daily/trash-cli-rotate"
cd --
fi
echo 'Setup trash-cli finish!'
echo 'Next: Setup zsh !'
read -rsp $'Press any key to continue...\n' -n1 key
# install my rc file
if [ ! -d "/home/$sUserName/.rc" ]; then
wget -O /tmp/install_rc.sh https://raw.github.com/JustinTW/rc/develop/auto-install.sh && bash /tmp/install_rc.sh
chsh -s /usr/bin/zsh $sUserName
fi
echo 'Setup zsh env finish !'
echo 'Next: Setup root zsh !'
read -rsp $'Press any key to continue...\n' -n1 key
sudo ls -al /root/.rc &> /dev/null
if [ ! $? -eq 0 ]; then
sudo /bin/su -c " wget -O /tmp/install_rc.sh https://raw.github.com/JustinTW/rc/develop/auto-install.sh && bash /tmp/install_rc.sh"
sudo -u root chsh -s /usr/bin/zsh root
fi
echo 'Setup zsh for root finish !'
echo 'Next: Setup autofs !'
read -rsp $'Press any key to continue...\n' -n1 key
# auto mount
if ! grep -q '/etc/auto.direct' /etc/auto.master ; then
sudo /bin/su -c "echo '\n/- /etc/auto.direct' >> /etc/auto.master"
fi
sudo service autofs stop
if [ ! -f '/etc/auto.direct' ]; then
sudo mkdir -p /mnt/disk
sudo mkdir -p /mnt/btrfs
sudo /bin/su -c "echo '/mnt/disk -fstype=btrfs :/dev/sdb1' > /etc/auto.direct"
sudo /bin/su -c "echo '/mnt/btrfs -fstype=btrfs :/dev/sda1' >> /etc/auto.direct"
fi
sudo service autofs restart
echo 'Setup autofs finish !'
read -rsp $'Press any key to exit...\n' -n1 key