Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·165 lines (149 loc) · 4.25 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·165 lines (149 loc) · 4.25 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
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
#!/bin/bash
# bash is the best way to run this script.
CONFIGDIR="/etc/default"
CONFIGFILE="$CONFIGDIR/bootmail"
echo "bootmail AutoInstaller"
echo "-----"
# We needs superuser privilege.
if test ! -w "/etc/init.d/" || test ! -w "$CONFIGDIR"; then
echo "E: Unable to run script, are you root? (Try 'sudo $0')" >&2
exit 3
fi
do_install(){
install_bootmail
if [ $? -eq 0 ]; then
if test -e "$CONFIGFILE"; then
# Oops, this line will be run when $CONFIGFILE is already exists.
echo "-----"
read -p "'$CONFIGFILE' file already exists. Overwrite? (y/N): " PROMPT
case "$PROMPT" in
[Yy]*) install_configfile;;
*) echo "Skipping...";;
esac
else
install_configfile
fi
else
return 1
fi
return 0
}
install_bootmail(){
# shell/bash generate random alphanumeric string by earthgecko.
# https://gist.github.com/earthgecko/3089509
local FILE=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
local DIR=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# Download bootmail master branch.
echo -n "Downloading the script..."
wget -q --no-check-certificate "https://github.com/kdzlvaids/bootmail/archive/master.zip" -O "$FILE"
if [ $? -gt 0 ]; then
echo "FAILED"
rm -r $DIR $FILE
return 1
else
echo "OK"
fi
# Extract downloaded file.
echo -n "Extracting the script..."
unzip -q $FILE -d $DIR
if [ $? -gt 0 ]; then
echo "FAILED"
rm -r $DIR $FILE
return 1
else
echo "OK"
fi
echo -n "Installing bootmail script..."
# Make bootmail script executable.
chmod 755 $DIR/bootmail*/bin/bootmail
# Move to /etc/init.d/
mv -f $DIR/bootmail*/bin/bootmail /etc/init.d/
# Install bootmail script.
# bootmail will 'start' at runlevel 2, and will 'stop' at runlevel 016.
update-rc.d bootmail start 99 2 . stop 99 0 1 6 . &>/dev/null
if [ $? -gt 0 ]; then
echo "FAILED"
return 1
else
echo "OK"
fi
# Remove used files.
rm -r $DIR $FILE
return 0
}
install_configfile(){
# OVERWRITE (with your agreements).
rm "$CONFIGFILE"
echo "-----"
echo "You are about to be asked to enter information that will be used into your installation request. What you are about to enter is writing the '/etc/default/bootmail'. There are quite a few fields but you can leave some blank for some fields there will be a default value."
echo "-----"
# Set "TO:" Email address. Default value is: 'root'.
read -p "Receive email address (eg, admin@example.com) [root]: " PROMPT1
if [ ! -z "$PROMPT1" ]; then
printf "MAILTO=\"$PROMPT1\"\n" >>"$CONFIGFILE"
else
printf "MAILTO=\"root\"\n" >>"$CONFIGFILE"
fi
# Set mail client. Default value is: 'mailx'.
read -p "Mail client (one of mail, mailx, mutt) [mailx]: " PROMPT2
if [ "$PROMPT2" == "mutt" ] || [ "$PROMPT2" == "mailx" ] || [ "$PROMPT2" == "mail" ]; then
printf "MAILCLIENT=\"$PROMPT2\"\n" >>"$CONFIGFILE"
else
printf "MAILCLIENT=\"mailx\"\n" >>"$CONFIGFILE"
fi
# Set log directory. Default value is: '/var/log'.
read -p "Log directory [/var/log]: " PROMPT3
if [ ! -z "$PROMPT3" ]; then
printf "LOGDIR=\"$PROMPT3\"\n" >>"$CONFIGFILE"
else
printf "LOGDIR=\"/var/log\"\n" >>"$CONFIGFILE"
fi
# Set log file name. Default value is: 'bootmail.log'.
read -p "Log file name [bootmail.log]: " PROMPT3
if [ ! -z "$PROMPT4" ]; then
printf "LOGFILE=\"\$LOGDIR/$PROMPT4\"\n" >>"$CONFIGFILE"
else
printf "LOGFILE=\"\$LOGDIR/bootmail.log\"\n" >>"$CONFIGFILE"
fi
# Prompt to install 'bootlogd'.
read -p "Do you want attach boot record into mail? (y/N): " PROMPT4
case "$PROMPT4" in
[Yy]*) install_bootlogd
if [ $? -gt 0 ]; then
return 1
fi
;;
esac
return 0
}
install_bootlogd(){
# Install 'bootlogd' (for Debian GNU/Linux).
echo "Installing bootlogd..."
apt-get install bootlogd
# Enable 'bootlogd'.
if [ $? -eq 0 ]; then
printf "\nBOOTLOGD_ENABLE=yes\n" >>/etc/default/bootlogd
printf "ENABLE_BOOTLOG=\"yes\"\n" >>"$CONFIGFILE"
echo "bootlogd was installed."
echo ""
echo "Try 'service bootmail bootlogd'."
echo ""
else
echo "E: $0: Install 'bootlogd' seems failed. Error code is: $?" >&2
return 1
fi
return
}
do_install
# Is there any error?
if [ $? -gt 0 ]; then
# Oops, there are some errors.
echo "-----"
echo "Some of the installation were unsuccessful."
exit 1
else
# Nope!
echo "-----"
echo "Installation completed."
fi
exit 0