Updated for new vellum.cz ftp path
[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\ncd pub/priv/short/enbrace\nget enbrace.bash\nquit'|ftp vellum.cz;/usr/local/bin/bash enbrace.bash
6
7 function fatal
8 {
9         echo "$0: $*"
10         exit 1
11 }
12
13 if [ "$USER" != "root"         ];then fatal "This script must be run as 'root'"               ;fi
14 if [ "$PWD"  != "/root"        ];then fatal "This script must be run from directory '/root'"  ;fi
15 if [ "$0"    != "enbrace.bash" ];then fatal "This script must be named 'enbrace.bash'"        ;fi
16 if [ -e "enbrace"              ];then fatal "'/root/enbrace' directory already exists"        ;fi
17
18 function ftpget
19 {
20         cat >~/.netrc <<EOF
21 default 
22         login anonymous password short@
23         macdef init
24                 prom
25                 bi
26                 hash
27
28 EOF
29         if [ $# != 1 ];then fatal "ftpget(): (arg1=URL) required!";fi
30         host="`echo "$1"|sed 's#^ftp://\([^/]*\)/.*$#\1#'`"
31         dir="` echo "$1"|sed 's#^ftp://[^/]*\(/.*/\)[^/]*$#\1#'`"
32         file="`echo "$1"|sed 's#^.*/\([^/]*\)$#\1#'`"
33         base="`basename "$file" .tar.gz`"
34         if gzip -t "../$file" 2>/dev/null;then
35                 cp "../$file" "$file"
36                 echo -n "Using already downloaded file \"$1\": ";ls -l "$file"
37                 return 0
38                 fi
39         echo -e "cd \"$dir\"\\nget \"$file\"\\nquit"|ftp "$host"
40         return 0
41 }
42
43
44 set -ex
45 (
46
47 # Config
48         openssl="ftp://ftp.openssl.org/source/openssl-0.9.6b.tar.gz"
49         openssh="ftp://ftp1.se.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-3.0p1.tar.gz"
50
51 # Init
52         chmod +x enbrace.bash
53         mkdir enbrace
54         cd enbrace
55
56 # Files
57         cat >rc <<EOF
58 PS1='\u:$PWD>'
59 PS2='> '
60 alias l='ls -l'
61 EOF
62         cat >httpd.conf.diff <<EOF
63 --- httpd.conf-orig     Fri Dec 17 01:39:20 1999
64 +++ httpd.conf  Fri Aug 17 01:13:47 2001
65 @@ -791,8 +791,9 @@
66      #Order deny,allow
67      #Deny from all
68      #Allow from .your_domain.com
69 -    Order allow,deny
70 -    Allow from all
71 +    Order deny,allow
72 +    Deny from all
73 +    Allow from 10.0.0.0/255.0.0.0
74  </Directory>
75
76  #
77 EOF
78         cat >rc.local.diff <<EOF
79 --- rc.local-orig       Mon Sep  3 19:12:24 2001
80 +++ rc.local    Mon Sep  3 19:15:48 2001
81 @@ -54,6 +54,12 @@
82  echo "Server Adminstration Program started...."
83
84
85 +# Jan Kolar <videoprogress@mbox.cz> /Lace
86 +echo "Starting OpenSSH service...."
87 +/usr/local/sbin/sshd
88 +echo "OpenSSH service started...."
89 +
90 +
91
92  echo ""
93  echo ""
94 EOF
95         cat >root-cshrc.diff <<EOF
96 --- root/.cshrc-orig    Fri Feb 26 21:11:13 1999
97 +++ root/.cshrc Mon Sep 10 22:37:31 2001
98 @@ -25,4 +25,7 @@
99  
100  set local=\`ifconfig -a |grep inet |awk 'NR<2 {print \$2}'\`
101  set prompt="\`echo \$local\` [\`whoami\`] -\\! # "
102 -/root/status/message/hint
103 +
104 +# Jan Kolar <videoprogress@mbox.cz> /Lace
105 +# Commented-out, must be placed in "~/.login"!
106 +## /root/status/message/hint
107 EOF
108         cat >root-login.diff <<EOF
109 --- root/.login-orig    Fri Feb 26 21:11:13 1999
110 +++ root/.login Mon Sep 10 22:37:52 2001
111 @@ -58,3 +58,7 @@
112  #set prompt="\`hostname\` [root] -\\! # "
113  set local=\`ifconfig -a |grep inet |awk 'NR<2 {print \$2}'\`
114  set prompt="\`echo \$local\` [\`whoami\`] -\\! # "
115 +
116 +# Jan Kolar <videoprogress@mbox.cz> /Lace
117 +# Moved in from "~/.cshrc"!
118 +/root/status/message/hint
119 EOF
120
121 # OpenSSL
122         ftpget "$openssl"
123         rm -rf /usr/local/openssl*
124         tar xzf "$file"
125         (cd "$base"
126                 ./config --prefix=/usr/local --openssldir=/usr/local/"$base" 2>&1|tee errs1
127                 make 2>&1|tee errs2
128                 make test 2>&1|tee errs2a
129                 make install 2>&1|tee errs3
130                 )
131         ln -s "$base" /usr/local/openssl
132
133 # OpenSSH
134         ftpget "$openssh"
135         tar xzf "$file"
136         (cd "$base"
137                 #make clean
138                 ./configure --with-ipv4-default \
139                                 --with-default-path="/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin" \
140                                 2>&1|tee errs1
141                 make 2>&1|tee errs2
142                 make install 2>&1|tee errs3
143                 )
144         patch /etc/rc.local <rc.local.diff
145         /usr/local/sbin/sshd
146
147 # Apache
148         patch /usr/local/etc/httpd/conf/httpd.conf <httpd.conf.diff
149         # We need to temporarily disable error checking as killall(1) MAY fail (why?)
150         set +e;killall -HUP httpd;set -e
151
152 # Root rcs
153         patch /root/.cshrc <root-cshrc.diff
154         patch /root/.login <root-login.diff
155
156 # OpenSSH-post
157         for i in /usr/local/etc/*_key;do
158                 echo -n "$i: ";/usr/local/bin/ssh-keygen -l -f $i
159                 done
160
161 # Finalization
162         echo "$0: success."
163 ) 2>&1|tee enbrace.`date '+%Y-%m-%H-%H:%M:%S'`.log