lilalo

view install @ 127:a92b17c77b57

upload_dir added
author igor@chub.in
date Fri Jul 04 17:44:19 2008 +0300 (2008-07-04)
parents 73fb48eb8110
children 244825e244de
line source
1 #!/bin/sh
3 hostname=`hostname`
4 uname -a | grep -qi freebsd || hostname=`hostname -f`
6 ###############################################################################
7 #
8 # Set this variables before installation:
10 lilalo_user="YOUR-L3BACKEND-USER"
11 lab="SET-YOUR-FIRSTLAB-NAME-HERE"
12 install_l3bashrc_for_this_users="root user" # users who will use l3agent and l3script
13 lilalo_context="/users/${lilalo_user}/${lab}/${hostname}"
15 #
16 ###############################################################################
19 lilalo_rc=.l3rc
20 lilalo_home=.lilalo
21 url_lilalo="http://xgu.ru/lilalo"
22 url_l3bashrc="${url_lilalo}"/l3bashrc
23 url_l3agent="${url_lilalo}"/l3-agent
24 url_l3config_pm="${url_lilalo}"/l3config.pm
25 url_l3config="${url_lilalo}"/l3-config
26 url_l3prompt="${url_lilalo}"/l3prompt
27 url_perl_modules=${url_lilalo}/
28 perl_modules="Term-VT102 Text-Iconv"
30 apt_get_install_this="perl make libmodule-build-perl libc6-dev gcc"
32 wget=wget
33 uname -a | grep -qi bsd && wget=fetch
35 normC='\033[0;39m'
36 whiteC='\033[1;37m'
37 redC='\033[0;31m'
38 greenC='\033[0;32m'
40 apt_get_install_deps()
41 {
42 return 0
43 if which apt-get >& /dev/null
44 then
45 apt-get install -y $apt_get_install_this
46 else
47 echo "Please install this dependencies manually:"
48 echo $apt_get_install_this
49 echo "Have you installed this already (y/n)?"
50 echo y | read answer
51 if echo $answer | grep -q ^[yY]
52 then
53 true
54 else
55 echo Please install the dependencies and rerun the script
56 exit 1
57 fi
58 fi
59 }
62 step()
63 {
65 msg="$1"
66 shift
67 printf "${whiteC}""$msg""...${normC}\n"
68 # eval "$@" 2>&1 | sed 's/^/|\ \ \ /' && printf "Ok\n" || printf "Failed\n"
69 eval "$@" 2>&1 > log 2>&1 && \
70 {
71 cat log | sed 's/^/|\ \ \ /'
72 printf "${greenC}""Ok\n""${normC}"
73 } || \
74 {
75 cat log | sed 's/^/|\ \ \ /'
76 printf "${redC}""Failed\n""${normC}"
77 }
78 }
80 get_user_home()
81 {
82 uname -a | grep -qi freebsd && pw user show "$@"| awk -F: '{print $9}' || getent passwd "$@"| awk -F: '{print $6}'
83 }
85 install_to_users_homes()
86 {
87 . l3bashrc
88 users="$@"
89 set -x
90 for user in $users
91 do
92 user_home=`get_user_home "$user"`
93 mkdir -p ${user_home}/${lilalo_home}
94 mkdir /etc/lilalo/
95 cp l3config.pm /etc/lilalo/
96 cp l3-agent /usr/local/bin
97 cp l3-config /usr/local/bin
98 chmod 755 /usr/local/bin/l3-{agent,config}
99 cp l3bashrc ${user_home}/${lilalo_home}
100 cp l3prompt ${user_home}/${lilalo_home}
101 chmod 755 ${user_home}/${lilalo_home}/l3prompt
102 chown -R $user ${user_home}/${lilalo_home}
103 echo l3cd=${lilalo_context}/$user > ${user_home}/${lilalo_rc}
104 chown -R $user ${user_home}/${lilalo_rc}
105 done
106 set +x
107 }
109 install_to_users_bashrc()
110 {
111 users="$@"
112 for user in $users
113 do
114 user_home=`get_user_home "$user"`
115 grep -q lilalo ${user_home}/.bashrc 2> /dev/null\
116 || echo ". ${user_home}/.lilalo/l3bashrc && _l3_start" >> ${user_home}/.bashrc; chown -R ${user} ${user_home}/.bashrc
117 done
118 }
120 install_to_users_bash_profile()
121 {
122 users="$@"
123 for user in $users
124 do
125 user_home=`get_user_home "$user"`
126 grep -q l3-agent ${user_home}/.bash_profile 2> /dev/null \
127 || { echo >> ${user_home}/.bash_profile ; cat ${user_home}/.bash_profile | sed '1s/^/l3-agentX/' | tr X '\n' > /tmp/$$$$l3 ; mv /tmp/$$$$l3 ${user_home}/.bash_profile; chown -R ${user} ${user_home}/.bash_profile; }
128 done
129 }
131 show_usage()
132 {
133 cat <<USAGE
134 Usage:
135 $0
136 USAGE
137 }
139 show_final_message()
140 {
141 cat <<FINAL_MESSAGE
144 Installation is successfully completed.
145 Now restart your shell or relogin
146 to start script writing.
148 Your current lilalo context is ${lilalo_context}/USER
149 If you use xgu.ru backend, your labs will be available at
150 http://xgu.ru/l3/${lilalo_context}
152 Use commands
153 $ l3cd ${lilalo_context%/*/*}/MY-NEW-CONTEXT/${hostname}/USER
154 $ l3pwd
155 to change and to know your current context.
157 For further information see http://xgu.ru/lilalo/ (in Russian).
159 Thank you gor using LiLaLo.
160 Happy Labbing!
162 (don't forget to restart bash or relogin)
164 FINAL_MESSAGE
165 }
168 temp_dir=/tmp/lilalo-install-temp-$$
169 mkdir -p ${temp_dir}
170 cd ${temp_dir}
171 step "Installing dependencies" apt_get_install_deps
172 step "Downloading l3bashrc" ${wget} ${url_l3bashrc}
173 step "Downloading l3prompt" ${wget} ${url_l3prompt}
174 step "Downloading l3-agent" '${wget} ${url_l3agent}; ${wget} ${url_l3config_pm}; ${wget} ${url_l3config}'
175 step "Downloading perl modules for l3-agent" '{ for i in ${perl_modules}; do ${wget} ${url_perl_modules}/$i.tar.gz; done; }'
176 step "Installing perl modules for l3-agent" '{ for i in ${perl_modules}; do tar xvfz $i.tar.gz; cd $i*[^z]; perl Makefile.PL; make; make install; cd ..; done; }'
177 step "Installing l3bashrc to users home directories" install_to_users_homes $install_l3bashrc_for_this_users
178 step "Adding l3bashrc invocation to ~/.bashrc " install_to_users_bashrc $install_l3bashrc_for_this_users
179 step "Adding l3-agent invocation to ~/.bash_profile " install_to_users_bash_profile $install_l3bashrc_for_this_users
180 cd /
181 rm -rf ${temp_dir}
183 show_final_message