lilalo

view install @ 112:da65f1cbaf3a

l3prompt added
author igor
date Sat Mar 08 22:36:44 2008 +0200 (2008-03-08)
parents 0d49f33696b3
children 658b4ea105c1
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="${url_lilalo}"/l3config.pm
25 url_perl_modules=${url_lilalo}/
26 perl_modules="Term-VT102 Text-Iconv"
28 apt_get_install_this="perl make libmodule-build-perl libc6-dev gcc"
30 wget=wget
31 uname -a | grep -qi bsd && wget=fetch
33 normC='\033[0;39m'
34 whiteC='\033[1;37m'
35 redC='\033[0;31m'
36 greenC='\033[0;32m'
38 apt_get_install_deps()
39 {
40 if which apt-get >& /dev/null
41 then
42 apt-get install -y $apt_get_install_this
43 else
44 echo "Please install this dependencies manually:"
45 echo $apt_get_install_this
46 echo "Have you installed this already (y/n)?"
47 echo y | read answer
48 if echo $answer | grep -q ^[yY]
49 then
50 true
51 else
52 echo Please install the dependencies and rerun the script
53 exit 1
54 fi
55 fi
56 }
59 step()
60 {
62 msg="$1"
63 shift
64 printf "${whiteC}""$msg""...${normC}\n"
65 # eval "$@" 2>&1 | sed 's/^/|\ \ \ /' && printf "Ok\n" || printf "Failed\n"
66 eval "$@" 2>&1 > log 2>&1 && \
67 {
68 cat log | sed 's/^/|\ \ \ /'
69 printf "${greenC}""Ok\n""${normC}"
70 } || \
71 {
72 cat log | sed 's/^/|\ \ \ /'
73 printf "${redC}""Failed\n""${normC}"
74 }
75 }
77 get_user_home()
78 {
79 uname -a | grep -qi freebsd && pw user show "$@"| awk -F: '{print $9}' || getent passwd "$@"| awk -F: '{print $6}'
80 }
82 install_to_users_homes()
83 {
84 . l3bashrc
85 users="$@"
86 set -x
87 for user in $users
88 do
89 user_home=`get_user_home "$user"`
90 mkdir -p ${user_home}/${lilalo_home}
91 cp l3config.pm /usr/local/bin
92 cp l3-agent /usr/local/bin
93 chmod 755 /usr/local/bin/l3-agent
94 cp l3bashrc ${user_home}/${lilalo_home}
95 chown -R $user ${user_home}/${lilalo_home}
96 echo l3cd=${lilalo_context}/$user > ${user_home}/${lilalo_rc}
97 chown -R $user ${user_home}/${lilalo_rc}
98 done
99 set +x
100 }
102 install_to_users_bashrc()
103 {
104 users="$@"
105 for user in $users
106 do
107 user_home=`get_user_home "$user"`
108 grep -q lilalo ${user_home}/.bashrc 2> /dev/null\
109 || echo ". ${user_home}/.lilalo/l3bashrc && _l3_start" >> ${user_home}/.bashrc; chown -R ${user} ${user_home}/.bashrc
110 done
111 }
113 install_to_users_bash_profile()
114 {
115 users="$@"
116 for user in $users
117 do
118 user_home=`get_user_home "$user"`
119 grep -q l3-agent ${user_home}/.bash_profile 2> /dev/null \
120 || { 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; }
121 done
122 }
124 show_usage()
125 {
126 cat <<USAGE
127 Usage:
128 $0
129 USAGE
130 }
132 show_final_message()
133 {
134 cat <<FINAL_MESSAGE
137 Installation is successfully completed.
138 Now restart your shell or relogin
139 to start script writing.
141 Your current lilalo context is ${lilalo_context}/USER
142 If you use xgu.ru backend, your labs will be available at
143 http://xgu.ru/l3/${lilalo_context}
145 Use commands
146 $ l3cd ${lilalo_context%/*/*}/MY-NEW-CONTEXT/${hostname}/USER
147 $ l3pwd
148 to change and to know your current context.
150 For further information see http://xgu.ru/lilalo/ (in Russian).
152 Thank you gor using LiLaLo.
153 Happy Labbing!
155 (don't forget to restart bash or relogin)
157 FINAL_MESSAGE
158 }
161 temp_dir=/tmp/lilalo-install-temp-$$
162 mkdir -p ${temp_dir}
163 cd ${temp_dir}
164 step "Installing dependencies" apt_get_install_deps
165 step "Downloading l3bashrc" ${wget} ${url_l3bashrc}
166 step "Downloading l3-agent" '${wget} ${url_l3agent}; ${wget} ${url_l3config}'
167 step "Downloading perl modules for l3-agent" '{ for i in ${perl_modules}; do ${wget} ${url_perl_modules}/$i.tar.gz; done; }'
168 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; }'
169 step "Installing l3bashrc to users home directories" install_to_users_homes $install_l3bashrc_for_this_users
170 step "Adding l3bashrc invocation to ~/.bashrc " install_to_users_bashrc $install_l3bashrc_for_this_users
171 step "Adding l3-agent invocation to ~/.bash_profile " install_to_users_bash_profile $install_l3bashrc_for_this_users
172 cd /
173 rm -rf ${temp_dir}
175 show_final_message