lilalo
view install @ 107:54fbf2041159
l3cd
author | devi |
---|---|
date | Fri Aug 04 18:06:09 2006 +0300 (2006-08-04) |
parents | |
children | 0d49f33696b3 |
line source
1 #!/bin/sh
3 lilalo_rc=.l3rc
4 lilalo_home=.lilalo
5 url_lilalo="http://xgu.ru/lilalo"
6 url_l3bashrc="${url_lilalo}"/l3bashrc
7 url_l3agent="${url_lilalo}"/l3-agent
8 url_l3config="${url_lilalo}"/l3config.pm
9 url_perl_modules=${url_lilalo}/
10 perl_modules="Term-VT102 Text-Iconv"
12 wget=wget
13 uname -a | grep -qi bsd && wget=fetch
15 normC='\033[0;39m'
16 whiteC='\033[1;37m'
17 redC='\033[0;31m'
18 greenC='\033[0;32m'
20 hostname=`hostname`
21 uname -a | grep -qi freebsd || hostname=`hostname -f`
24 # Ask this variables:
26 lilalo_user="devi"
27 lab="lilalo-installation"
28 install_l3bashrc_for_this_users="root ak devi"
29 lilalo_context="/users/${lilalo_user}/${lab}/${hostname}"
32 step()
33 {
35 msg="$1"
36 shift
37 printf "${whiteC}""$msg""...${normC}\n"
38 # eval "$@" 2>&1 | sed 's/^/|\ \ \ /' && printf "Ok\n" || printf "Failed\n"
39 eval "$@" 2>&1 > log 2>&1 && \
40 {
41 cat log | sed 's/^/|\ \ \ /'
42 printf "${greenC}""Ok\n""${normC}"
43 } || \
44 {
45 cat log | sed 's/^/|\ \ \ /'
46 printf "${redC}""Failed\n""${normC}"
47 }
48 }
50 get_user_home()
51 {
52 uname -a | grep -qi freebsd && pw user show "$@"| awk -F: '{print $9}' || getent passwd "$@"| awk -F: '{print $6}'
53 }
55 install_to_users_homes()
56 {
57 . l3bashrc
58 users="$@"
59 set -x
60 for user in $users
61 do
62 user_home=`get_user_home "$user"`
63 mkdir -p ${user_home}/${lilalo_home}
64 cp l3config.pm /usr/local/bin
65 cp l3-agent /usr/local/bin
66 chmod 755 /usr/local/bin/l3-agent
67 cp l3bashrc ${user_home}/${lilalo_home}
68 chown -R $user ${user_home}/${lilalo_home}
69 echo l3cd=${lilalo_context}/$user > ${user_home}/${lilalo_rc}
70 chown -R $user ${user_home}/${lilalo_rc}
71 done
72 set +x
73 }
75 install_to_users_bashrc()
76 {
77 users="$@"
78 for user in $users
79 do
80 user_home=`get_user_home "$user"`
81 grep -q lilalo ${user_home}/.bashrc 2> /dev/null\
82 || echo ". ${user_home}/.lilalo/l3bashrc && _l3_start" >> ${user_home}/.bashrc; chown -R ${user} ${user_home}/.bashrc
83 done
84 }
86 install_to_users_bash_profile()
87 {
88 users="$@"
89 for user in $users
90 do
91 user_home=`get_user_home "$user"`
92 grep -q l3-agent ${user_home}/.bash_profile 2> /dev/null \
93 || { echo >> ${user_home}/.bash_profile ; cat ${user_home}/.bash_profile | sed '1s/^/l3-agent/' > /tmp/$$$$l3 ; mv /tmp/$$$$l3 ${user_home}/.bash_profile; chown -R ${user} ${user_home}/.bash_profile; }
94 done
95 }
97 show_usage()
98 {
99 cat <<USAGE
100 Usage:
101 $0
102 USAGE
103 }
105 show_final_message()
106 {
107 cat <<FINAL_MESSAGE
110 Installation is successfully completed.
111 Now restart your shell or relogin
112 to start script writing.
114 Your current lilalo context is ${lilalo_context}/USER
115 If you use xgu.ru backend, your labs will be available at
116 http://xgu.ru/l3/${lilalo_context}
118 Use commands
119 $ l3cd ${lilalo_context%/*/*}/MY-NEW-CONTEXT/${hostname}/USER
120 $ l3pwd
121 to change and to know your current context.
123 For further information see http://xgu.ru/lilalo/ (in Russian).
125 Thank you gor using LiLaLo.
126 Happy Labbing!
128 (don't forget to restart bash or relogin)
130 FINAL_MESSAGE
131 }
134 temp_dir=/tmp/lilalo-install-temp-$$
135 mkdir -p ${temp_dir}
136 cd ${temp_dir}
137 step "Downloading l3bashrc" ${wget} ${url_l3bashrc}
138 step "Downloading l3-agent" '${wget} ${url_l3agent}; ${wget} ${url_l3config}'
139 step "Downloading perl modules for l3-agent" '{ for i in ${perl_modules}; do ${wget} ${url_perl_modules}/$i.tar.gz; done; }'
140 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; }'
141 step "Installing l3bashrc to users home directories" install_to_users_homes $install_l3bashrc_for_this_users
142 step "Adding l3bashrc invocation to ~/.bashrc " install_to_users_bashrc $install_l3bashrc_for_this_users
143 step "Adding l3-agent invocation to ~/.bash_profile " install_to_users_bash_profile $install_l3bashrc_for_this_users
144 cd /
145 rm -rf ${temp_dir}
147 show_final_message