-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathircd_install.sh
More file actions
executable file
·127 lines (111 loc) · 2.78 KB
/
ircd_install.sh
File metadata and controls
executable file
·127 lines (111 loc) · 2.78 KB
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
#!/bin/bash
USERNAME="irc"
PREFIX="/usr/local/ircd"
# Function to prompt for [y/n], return true or false
confirm () {
if [ $FORCE ]; then return 0 ; fi
read -r -p "${1:-Are you sure ? [y/n]}" response
case $response in
[yY][eE][sS]|[yY]|"")
true
;;
*)
false
;;
esac
}
# Function to create a system user
create_user () {
confirm "This will create a system user, are you sure ? [y/n] " && \
useradd -r $1
}
# Function to display errors
error () {
case $1 in
spec_u) echo "If you want to specify an user, rerun with -u <username>"
;;
no_crea) echo "Can't work without user, exiting now"
;;
no_root) echo "You must run this scrip as root"
;;
esac
exit 1
}
# Usage
usage () {
echo usage
}
# Verify if launched as root
if [ "$(id -u)" != 0 ]; then error "no_root"; fi
# Get flags
while test $# != 0
do
case $1 in
-f|--force) FORCE=true ;;
-u|--user)
shift
case $1 in
-*) usage ; break ;;
*)
getent passwd $1 >/dev/null 2&>1 && USERNAME=$1 || \
{ confirm "User $1 doesn't exists, do you want to create it ? [y/n] " && \
create_user $1 || error "no_crea" ; } && shift
;;
esac
;;
-p|--prefix)
shift
case $1 in
/*|~*)
PREFIX=$1 &&
confirm "Use $PREFIX for installing ircd ?" && shift
;;
*) usage ; break ;;
esac
;;
--) shift ; break ;;
-*) usage ; break ;;
esac
shift
done
# Get appropriate confirmation message
case $USERNAME in
irc) message="This script will use the default debian user irc to run the ircd
and the services, do you agree ? [y/n] "
;;
*) message="This script will use the user $USERNAME to run the ircd
and the services, do you agree ? [y/n] "
;;
esac
# Check if the user is right
confirm "$message" || error "spec_u"
# Shortcut to launch cmds as user
SU_CMD="su $USERNAME -s /bin/sh -c "
# Cloning all sources
echo "Cloning sources in /tmp"
echo "Cloning ircd-hybrid"
$SU_CMD "git clone https://github.com/ircd-hybrid/ircd-hybrid.git /tmp/ircd-hybrid"
echo "Cloning Anope"
$SU_CMD "git clone https://github.com/anope/anope.git /tmp/anope"
echo "Compiling and installing ircd-hybrid"
mkdir $PREFIX
chown $USERNAME:$USERNAME $PREFIX
$SU_CMD "cd /tmp/ircd-hybrid ; ./configure --prefix=$PREFIX; make && make install"
echo "Preparing anope compilation"
mkdir "$PREFIX/../services"
chown $USERNAME:$USERNAME "$PREFIX/../services"
# Creating config file
cat > /tmp/anope/config.cache <<- EOF
INSTDIR="$PREFIX/../services"
RUNGROUP="irc"
UMASK=007
DEBUG="no"
USE_PCH="no"
EXTRA_INCLUDE_DIRS=""
EXTRA_LIB_DIRS=""
EXTRA_CONFIG_ARGS=""
EOF
echo "Compiling and installing anope"
$SU_CMD "cd /tmp/anope/ ; ./Config -quick ; cd build ; make && make install"
HASH= $SU_CMD "$PREFIX/bin/mkpasswd -5 -p ponyplay"
cat toto | sed -e '1h;1!H;${g;s/\n\(log {.*};\)/\n\/\*\1\*\//g;p;}'