-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·154 lines (128 loc) · 3.29 KB
/
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
#!/bin/bash
INSTALL_PACKAGES=(python3 php5-cli git tmux libgmp-dev bash-completion)
INSTALL_OPTIONAL=(geoip-database-contrib)
function check_system()
{
echo "Checking system..."
echo -n "apt-get: "
if ! which apt-get
then
echo "(not found)"
echo "This script currently works only on Debian and derivatives!"
return 1
fi
return 0
}
function install_packages()
{
apt-get -y install ${INSTALL_PACKAGES[*]}
for p in ${INSTALL_OPTIONAL[*]}
do
apt-get -y install $p
done
}
function download_repo()
{
local repo
if $SSH
then
repo="$1"
else
repo="$2"
fi
local name=$(basename "$repo" .git)
if [ -d "$name" ]
then
echo "Found $name"
else
echo "Downloading $name"
git clone "$repo"
fi
}
function post_install()
{
MAKE_FLAGS="-j 8"
if [ -f ~/.ssh/id_rsa ]
then
echo "Found SSH keys"
echo -n "Use SSH to clone? [y|n]"
read SSH
[ "$SSH" = 'y' ] && SSH=true
else
SSH=false
fi
! [ -d ~/src ] && mkdir ~/src
cd ~/src
download_repo "http://de.git.xonotic.org/xonotic/xonotic.git" "ssh://[email protected]/xonotic/xonotic.git"
download_repo "https://github.com/MarioSMB/modpack.git" "[email protected]:MarioSMB/modpack.git"
download_repo "https://github.com/mbasaglia/Melanobot.git" "[email protected]:mbasaglia/Melanobot.git"
download_repo "https://github.com/Evil-Ant-Colony/Xonotic-EAC-Scripts.git" "[email protected]:Evil-Ant-Colony/Xonotic-EAC-Scripts.git"
echo "Building Xonotic"
( cd ~/src/xonotic && touch data/xonotic-maps.pk3dir.no && ./all update && ./all compile -0 dedicated $MAKE_FLAGS )
echo "Building Modpack"
( cd ~/src/modpack/qcsrc && make QCC=~/src/xonotic/gmqcc/gmqcc $MAKE_FLAGS )
echo "Setting up executables"
! [ -d ~/bin ] && mkdir ~/bin
ln -s "$PWD/Xonotic-EAC-Scripts/server/server" ~/bin
ln -s "$PWD/xonotic/gmqcc/gmqcc" ~/bin
if ! grep -qF Xonotic-EAC-Scripts/server/autocomplete.sh ~/.bashrc
then
echo >>~/.bashrc
echo ". $PWD/Xonotic-EAC-Scripts/server/autocomplete.sh" >>~/.bashrc
fi
echo "All set!"
}
if ! check_system
then
echo "System check failed, aborting!" >&2
exit 1
fi
if [ "$(id -u)" -eq 0 ]
then
echo "Executing as root"
if [ -n "$1" ]
then
INSTALL_USER="$1"
else
INSTALL_USER=$(pwd | sed -r -e "s~/home/~~" -e "s~/.*~~")
fi
while true
do
if [ -n "$INSTALL_USER" ]
then
echo "Selected installation user: $INSTALL_USER"
echo -n "Confirm? [y|n] "
read user_ok
[ "$user_ok" = 'y' ] && break
fi
echo -n "Enter installation user name: "
read INSTALL_USER
id -u "$INSTALL_USER" || INSTALL_USER=
done
install_packages
echo "Setting up init.d"
borgy_initd=borgy
borgy_initd_file="/etc/init.d/$borgy_initd"
cat >"$borgy_initd_file" <<INITD
#!/bin/sh
### BEGIN INIT INFO
# Provides: borgy
# Required-Start: \$local_fs \$network
# Required-Stop: \$local_fs \$network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Borgy, the evil IRC bot
### END INIT INFO
sudo -u $INSTALL_USER bash /home/$INSTALL_USER/src/Melanobot/init.d/borgy $*
INITD
chmod 755 "$borgy_initd_file"
update-rc.d "$borgy_initd" defaults
export -f post_install
export -f download_repo
su $USER -c post_install
else
echo "You are not root"
echo -n "Apply post-installation changes? [y|n] "
read post_install
[ "$post_install" = 'y' ] && post_install
fi