Initial version mailed some time before 2 Oct 2001
[enbrace.git] / enbrace.bash
1 #! /usr/local/bin/bash
2 #
3 # cd;echo 'default login anonymous password short@' >~/.netrc;echo -e 'bi\nhash\ncd pub/priv\nget enbrace.bash\nquit'|ftp atrey.karlin.mff.cuni.cz;/usr/local/bin/bash enbrace.bash
4
5 function fatal
6 {
7         echo "$0: $*"
8         exit 1
9 }
10
11 if [ "$USER" != "root"         ];then fatal "This script must be run as 'root'"               ;fi
12 if [ "$PWD"  != "/root"        ];then fatal "This script must be run from directory '/root'"  ;fi
13 if [ "$0"    != "enbrace.bash" ];then fatal "This script must be named 'enbrace.bash'"        ;fi
14 if [ -e "enbrace"              ];then fatal "'/root/enbrace' directory already exists"        ;fi
15
16 function ftpget
17 {
18         cat >~/.netrc <<EOF
19 default 
20         login anonymous password short@
21         macdef init
22                 prom
23                 bi
24                 hash
25
26 EOF
27         if [ $# != 1 ];then fatal "ftpget(): (arg1=URL) required!";fi
28         host="`echo "$1"|sed 's#^ftp://\([^/]*\)/.*$#\1#'`"
29         dir="` echo "$1"|sed 's#^ftp://[^/]*\(/.*/\)[^/]*$#\1#'`"
30         file="`echo "$1"|sed 's#^.*/\([^/]*\)$#\1#'`"
31         base="`basename "$file" .tar.gz`"
32         if gzip -t "../$file" 2>/dev/null;then
33                 cp "../$file" "$file"
34                 echo -n "Using already downloaded file \"$1\": ";ls -l "$file"
35                 return 0
36                 fi
37         echo -e "cd \"$dir\"\\nget \"$file\"\\nquit"|ftp "$host"
38         return 0
39 }
40
41
42 set -ex
43 (
44
45 # Config
46         openssl="ftp://ftp.openssl.org/source/openssl-0.9.6b.tar.gz"
47         openssh="ftp://ftp1.se.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-2.9p2.tar.gz"
48
49 # Init
50         chmod +x enbrace.bash
51         mkdir enbrace
52         cd enbrace
53
54 # Files
55         cat >rc <<EOF
56 PS1='\u:$PWD>'
57 PS2='> '
58 alias l='ls -l'
59 EOF
60         cat >httpd.conf.diff <<EOF
61 --- httpd.conf-orig     Fri Dec 17 01:39:20 1999
62 +++ httpd.conf  Fri Aug 17 01:13:47 2001
63 @@ -791,8 +791,9 @@
64      #Order deny,allow
65      #Deny from all
66      #Allow from .your_domain.com
67 -    Order allow,deny
68 -    Allow from all
69 +    Order deny,allow
70 +    Deny from all
71 +    Allow from 10.0.0.0/255.0.0.0
72  </Directory>
73
74  #
75 EOF
76         cat >rc.local.diff <<EOF
77 --- rc.local-orig       Mon Sep  3 19:12:24 2001
78 +++ rc.local    Mon Sep  3 19:15:48 2001
79 @@ -54,6 +54,12 @@
80  echo "Server Adminstration Program started...."
81
82
83 +# Jan Kolar <videoprogress@mbox.cz> /Lace
84 +echo "Starting OpenSSH service...."
85 +/usr/local/sbin/sshd
86 +echo "OpenSSH service started...."
87 +
88 +
89
90  echo ""
91  echo ""
92 EOF
93
94 # OpenSSL
95         ftpget "$openssl"
96         rm -rf /usr/local/openssl*
97         tar xzf "$file"
98         (cd "$base"
99                 ./config --prefix=/usr/local --openssldir=/usr/local/"$base" 2>&1|tee errs1
100                 make 2>&1|tee errs2
101                 make test 2>&1|tee errs2a
102                 make install 2>&1|tee errs3
103                 )
104         ln -s "$base" /usr/local/openssl
105
106 # OpenSSH
107         ftpget "$openssh"
108         tar xzf "$file"
109         (cd "$base"
110                 #make clean
111                 ./configure --with-ipv4-default 2>&1|tee errs1
112                 make 2>&1|tee errs2
113                 make install 2>&1|tee errs3
114                 )
115         patch /etc/rc.local <rc.local.diff
116         /usr/local/sbin/sshd
117
118 # Apache
119         patch /usr/local/etc/httpd/conf/httpd.conf <httpd.conf.diff
120         killall -HUP httpd
121
122 # OpenSSH-post
123         for i in /usr/local/etc/*_key;do
124                 echo -n "$i: ";/usr/local/bin/ssh-keygen -l -f $i
125                 done
126
127 # Finalization
128         echo "$0: success."
129 ) 2>&1|tee enbrace.`date '+%Y-%m-%H-%H:%M:%S'`.log