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