6888482ed641fce2e31575dc72bf5b3920ca2798
[enbrace.git] / enbrace.bash
1 #! /usr/local/bin/bash
2 #
3 # $Id$
4 #
5 # cd;echo 'default login anonymous password short@' >~/.netrc;echo -e 'bi\nhash\npass\ncd pub/priv/short/enbrace\nget enbrace.bash\nquit'|ftp vellum.cz;/usr/local/bin/bash enbrace.bash
6 #
7 # Patch multi-application liable files:
8 # [cs_CZ] Soubory citlive na vicenasobnou aplikaci patche:
9 #       /etc/rc.local
10 #       /root/.login
11 #       /etc/inetd.conf
12 #       /etc/crontab
13
14 function fatal
15 {
16         echo "$0: $*"
17         exit 1
18 }
19
20 if [ "$USER" != "root"                   ];then fatal "This script must be run as 'root'"               ;fi
21 if [ "$PWD"  != "/root"                  ];then fatal "This script must be run from directory '/root'"  ;fi
22 if [ "`basename "$0"`" != "enbrace.bash" ];then fatal "This script must be named 'enbrace.bash'"        ;fi
23 if [ -e "enbrace"                        ];then fatal "'/root/enbrace' directory already exists"        ;fi
24
25 function ftpget
26 {
27         cat >~/.netrc <<EOF
28 default 
29         login anonymous password short@
30         macdef init
31                 prom
32                 bi
33                 hash
34                 pass
35
36 EOF
37         if [ $# != 1 ];then fatal "ftpget(): (arg1=URL) required!";fi
38         host="`echo "$1"|sed 's#^ftp://\([^/]*\)/.*$#\1#'`"
39         dir="` echo "$1"|sed 's#^ftp://[^/]*\(/.*/\)[^/]*$#\1#'`"
40         file="`echo "$1"|sed 's#^.*/\([^/]*\)$#\1#'`"
41         base="`basename "$file" .tar.gz`"
42         if gzip -t "../$file" 2>/dev/null;then
43                 cp "../$file" "$file"
44                 echo -n "Using already downloaded file \"$1\": ";ls -l "$file"
45                 return 0
46                 fi
47         echo -e "cd \"$dir\"\\nget \"$file\"\\nquit"|ftp -v "$host"
48         return 0
49 }
50
51
52 set -ex
53 (
54
55 # Config
56         openssl="ftp://ftp.openssl.org/source/openssl-0.9.6c.tar.gz"
57         openssh="ftp://ftp1.se.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-3.1p1.tar.gz"
58
59 # Init
60         chmod +x enbrace.bash
61         mkdir enbrace
62         cd enbrace
63
64 # Files
65         cat >rc <<EOF
66 PS1='\u:$PWD>'
67 PS2='> '
68 alias l='ls -l'
69 EOF
70         cat >httpd.conf.diff <<EOF
71 --- httpd.conf-orig     Fri Dec 17 01:39:20 1999
72 +++ httpd.conf  Fri Aug 17 01:13:47 2001
73 @@ -791,8 +791,9 @@
74      #Order deny,allow
75      #Deny from all
76      #Allow from .your_domain.com
77 -    Order allow,deny
78 -    Allow from all
79 +    Order deny,allow
80 +    Deny from all
81 +    Allow from 10.0.0.0/255.0.0.0
82  </Directory>
83
84  #
85 EOF
86         cat >rc.local.diff <<EOF
87 --- rc.local-orig       Mon Sep  3 19:12:24 2001
88 +++ rc.local    Mon Sep  3 19:15:48 2001
89 @@ -54,6 +54,12 @@
90  echo "Server Adminstration Program started...."
91
92
93 +# Jan Kolar <jan.kolar@jklabs.cz> /Lace
94 +echo "Starting OpenSSH service...."
95 +/usr/local/sbin/sshd
96 +echo "OpenSSH service started...."
97 +
98 +
99
100  echo ""
101  echo ""
102 EOF
103         cat >root-cshrc.diff <<EOF
104 --- root/.cshrc-orig    Fri Feb 26 21:11:13 1999
105 +++ root/.cshrc Mon Sep 10 22:37:31 2001
106 @@ -25,4 +25,7 @@
107  
108  set local=\`ifconfig -a |grep inet |awk 'NR<2 {print \$2}'\`
109  set prompt="\`echo \$local\` [\`whoami\`] -\\! # "
110 -/root/status/message/hint
111 +
112 +# Jan Kolar <jan.kolar@jklabs.cz> /Lace
113 +# Commented-out, must be placed in "~/.login"!
114 +## /root/status/message/hint
115 EOF
116         cat >root-login.diff <<EOF
117 --- root/.login-orig    Fri Feb 26 21:11:13 1999
118 +++ root/.login Mon Sep 10 22:37:52 2001
119 @@ -58,3 +58,7 @@
120  #set prompt="\`hostname\` [root] -\\! # "
121  set local=\`ifconfig -a |grep inet |awk 'NR<2 {print \$2}'\`
122  set prompt="\`echo \$local\` [\`whoami\`] -\\! # "
123 +
124 +# Jan Kolar <jan.kolar@jklabs.cz> /Lace
125 +# Moved in from "~/.cshrc"!
126 +/root/status/message/hint
127 EOF
128         cat >root-mail.diff <<EOF
129 --- /dev/null   Fri Mar 15 02:04:08 2002
130 +++ root/.forward       Fri Mar 15 04:30:57 2002
131 @@ -0,0 +1,2 @@
132 +\root
133 +jan.kolar@jklabs.cz
134 EOF
135         cat >sendmail.diff <<EOF
136 --- etc/rc.conf-orig    Fri Feb 22 12:40:54 2002
137 +++ etc/rc.conf Tue Mar 12 15:14:38 2002
138 @@ -132,7 +132,7 @@
139  cron_enable="YES"      # Run the periodic job daemon.
140  lpd_enable="NO"                # Run the line printer daemon.
141  lpd_flags=""           # Flags to lpd (if enabled).
142 -sendmail_enable="YES"  # Run the sendmail daemon (or NO).
143 +sendmail_enable="NO"   # Run the sendmail daemon (or NO).
144  sendmail_flags="-bd -q30m" # -bd is pretty mandatory.
145  dumpdev="NO"           # Device name to crashdump to (if enabled).
146  check_quotas="NO"      # Check quotas (or NO).
147 --- etc/inetd.conf-orig Tue Mar 12 15:15:35 2002
148 +++ etc/inetd.conf      Tue Mar 12 15:10:19 2002
149 @@ -65,3 +65,6 @@
150  #
151  #netbios-ssn stream tcp nowait root /usr/local/sbin/smbd smbd 
152  #netbios-ns dgram udp wait root /usr/local/sbin/nmbd nmbd 
153 +
154 +# Jan Kolar <jan.kolar@jklabs.cz> /Lace
155 +smtp   stream  tcp     nowait  root    /usr/local/libexec/tcpd /usr/sbin/sendmail -bs
156 --- /dev/null   Tue Mar 12 15:13:23 2002
157 +++ usr/local/etc/hosts.allow   Tue Mar 12 15:13:46 2002
158 @@ -0,0 +1 @@
159 +sendmail : 127. 10.
160 --- /dev/null   Tue Mar 12 15:13:23 2002
161 +++ usr/local/etc/hosts.deny    Tue Mar 12 15:11:50 2002
162 @@ -0,0 +1 @@
163 +sendmail : ALL
164 --- etc/crontab-orig    Wed Oct 22 00:21:08 1997
165 +++ etc/crontab Tue Mar 12 15:18:42 2002
166 @@ -23,3 +23,6 @@
167  # does nothing, if you have UTC cmos clock.
168  # See adjkerntz(8) for details.
169  1,31   0-4     *       *       *       root    /sbin/adjkerntz -a
170 +
171 +# Jan Kolar <jan.kolar@jklabs.cz> /Lace
172 +*/30   *       *       *       *       root    /usr/sbin/sendmail -q
173 EOF
174         cat >openssh-3.1p1-i386-unknown-freebsd2.2.5.diff <<EOF
175 --- configure.ac-orig   Thu Apr  4 00:35:36 2002
176 +++ configure.ac        Thu Apr  4 00:35:45 2002
177 @@ -138,6 +138,7 @@
178         ;;
179  *-*-freebsd*)
180         check_for_libcrypt_later=1
181 +       AC_DEFINE(HAVE_BOGUS_SYS_QUEUE_H)
182         ;;
183  *-next-*)
184         conf_lastlog_location="/usr/adm/lastlog"
185 --- configure-orig      Thu Apr  4 00:35:55 2002
186 +++ configure   Thu Apr  4 00:40:37 2002
187 @@ -3568,6 +3568,10 @@
188         ;;
189  *-*-freebsd*)
190         check_for_libcrypt_later=1
191 +       cat >>confdefs.h <<\_ACEOF
192 +#define HAVE_BOGUS_SYS_QUEUE_H 1
193 +_ACEOF
194 +
195         ;;
196  *-next-*)
197         conf_lastlog_location="/usr/adm/lastlog"
198 --- defines.h-orig      Wed Feb 27 03:40:49 2002
199 +++ defines.h   Thu Apr  4 01:00:56 2002
200 @@ -146,7 +146,7 @@
201  including rpc/rpc.h breaks Solaris 6
202  */
203  #ifndef INADDR_LOOPBACK
204 -#define INADDR_LOOPBACK ((ulong)0x7f000001)
205 +#define INADDR_LOOPBACK ((unsigned long)0x7f000001)
206  #endif
207  
208  /* Types */
209 EOF
210
211 # Sendmail
212         (cd /
213                 patch -sENp0 </root/enbrace/sendmail.diff
214                 )
215         set +e;killall sendmail;set -e
216
217 # OpenSSL
218         ftpget "$openssl"
219         rm -rf /usr/local/openssl*
220         tar xzf "$file"
221         (cd "$base"
222                 ./config --prefix=/usr/local --openssldir=/usr/local/"$base" 2>&1|tee errs1
223                 make 2>&1|tee errs2
224                 make test 2>&1|tee errs2a
225                 make install 2>&1|tee errs3
226                 )
227         ln -s "$base" /usr/local/openssl
228
229 # OpenSSH
230         ftpget "$openssh"
231         tar xzf "$file"
232         (cd "$base"
233                 patch -sENp0 <../openssh-3.1p1-i386-unknown-freebsd2.2.5.diff
234                 #make clean
235                 ./configure --with-ipv4-default \
236                                 --with-default-path="/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin" \
237                                 2>&1|tee errs1
238                 make 2>&1|tee errs2
239                 make install 2>&1|tee errs3
240                 )
241         patch -N /etc/rc.local <rc.local.diff
242         /usr/local/sbin/sshd
243
244 # Apache
245         patch -N /usr/local/etc/httpd/conf/httpd.conf <httpd.conf.diff
246         # We need to temporarily disable error checking as killall(1) MAY fail (why?)
247         set +e;killall -HUP httpd;set -e
248
249 # Root rcs
250         patch -N /root/.cshrc <root-cshrc.diff
251         patch -N /root/.login <root-login.diff
252         patch -N /root/.forward <root-mail.diff
253
254 # Sendmail-post
255         set +e;killall -HUP inetd;set -e
256
257 # OpenSSH-post
258         for i in /usr/local/etc/*_key;do
259                 echo -n "$i: ";/usr/local/bin/ssh-keygen -l -f $i
260                 done
261
262 # Finalization
263         echo "$0: success."
264 ) 2>&1|tee enbrace.`date '+%Y-%m-%d-%H:%M:%S'`.log
265