lilalo

view install @ 108:0d49f33696b3

Исправлены ошибки:
* инсталляция агента в .bash_profile - была проблема с переводом строки
* неверное определение агента в памяти в FreeBSD
* по умолчанию в l3cd не писалось имя хоста
author devi
date Sun Nov 12 17:34:47 2006 +0200 (2006-11-12)
parents 53b890d1ae90
children 3cd466f35ad6
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"
29 wget=wget
30 uname -a | grep -qi bsd && wget=fetch
32 normC='\033[0;39m'
33 whiteC='\033[1;37m'
34 redC='\033[0;31m'
35 greenC='\033[0;32m'
39 step()
40 {
42 msg="$1"
43 shift
44 printf "${whiteC}""$msg""...${normC}\n"
45 # eval "$@" 2>&1 | sed 's/^/|\ \ \ /' && printf "Ok\n" || printf "Failed\n"
46 eval "$@" 2>&1 > log 2>&1 && \
47 {
48 cat log | sed 's/^/|\ \ \ /'
49 printf "${greenC}""Ok\n""${normC}"
50 } || \
51 {
52 cat log | sed 's/^/|\ \ \ /'
53 printf "${redC}""Failed\n""${normC}"
54 }
55 }
57 get_user_home()
58 {
59 uname -a | grep -qi freebsd && pw user show "$@"| awk -F: '{print $9}' || getent passwd "$@"| awk -F: '{print $6}'
60 }
62 install_to_users_homes()
63 {
64 . l3bashrc
65 users="$@"
66 set -x
67 for user in $users
68 do
69 user_home=`get_user_home "$user"`
70 mkdir -p ${user_home}/${lilalo_home}
71 cp l3config.pm /usr/local/bin
72 cp l3-agent /usr/local/bin
73 chmod 755 /usr/local/bin/l3-agent
74 cp l3bashrc ${user_home}/${lilalo_home}
75 chown -R $user ${user_home}/${lilalo_home}
76 echo l3cd=${lilalo_context}/$user > ${user_home}/${lilalo_rc}
77 chown -R $user ${user_home}/${lilalo_rc}
78 done
79 set +x
80 }
82 install_to_users_bashrc()
83 {
84 users="$@"
85 for user in $users
86 do
87 user_home=`get_user_home "$user"`
88 grep -q lilalo ${user_home}/.bashrc 2> /dev/null\
89 || echo ". ${user_home}/.lilalo/l3bashrc && _l3_start" >> ${user_home}/.bashrc; chown -R ${user} ${user_home}/.bashrc
90 done
91 }
93 install_to_users_bash_profile()
94 {
95 users="$@"
96 for user in $users
97 do
98 user_home=`get_user_home "$user"`
99 grep -q l3-agent ${user_home}/.bash_profile 2> /dev/null \
100 || { 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; }
101 done
102 }
104 show_usage()
105 {
106 cat <<USAGE
107 Usage:
108 $0
109 USAGE
110 }
112 show_final_message()
113 {
114 cat <<FINAL_MESSAGE
117 Installation is successfully completed.
118 Now restart your shell or relogin
119 to start script writing.
121 Your current lilalo context is ${lilalo_context}/USER
122 If you use xgu.ru backend, your labs will be available at
123 http://xgu.ru/l3/${lilalo_context}
125 Use commands
126 $ l3cd ${lilalo_context%/*/*}/MY-NEW-CONTEXT/${hostname}/USER
127 $ l3pwd
128 to change and to know your current context.
130 For further information see http://xgu.ru/lilalo/ (in Russian).
132 Thank you gor using LiLaLo.
133 Happy Labbing!
135 (don't forget to restart bash or relogin)
137 FINAL_MESSAGE
138 }
141 temp_dir=/tmp/lilalo-install-temp-$$
142 mkdir -p ${temp_dir}
143 cd ${temp_dir}
144 step "Downloading l3bashrc" ${wget} ${url_l3bashrc}
145 step "Downloading l3-agent" '${wget} ${url_l3agent}; ${wget} ${url_l3config}'
146 step "Downloading perl modules for l3-agent" '{ for i in ${perl_modules}; do ${wget} ${url_perl_modules}/$i.tar.gz; done; }'
147 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; }'
148 step "Installing l3bashrc to users home directories" install_to_users_homes $install_l3bashrc_for_this_users
149 step "Adding l3bashrc invocation to ~/.bashrc " install_to_users_bashrc $install_l3bashrc_for_this_users
150 step "Adding l3-agent invocation to ~/.bash_profile " install_to_users_bash_profile $install_l3bashrc_for_this_users
151 cd /
152 rm -rf ${temp_dir}
154 show_final_message