lilalo

view install @ 117:9bb58a1eee2b

l3prompt minifix $_[0] -> $ARGV[0]
author igor
date Mon Mar 10 01:30:07 2008 +0200 (2008-03-10)
parents 658b4ea105c1
children 73fb48eb8110
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 if which apt-get >& /dev/null
43 then
44 apt-get install -y $apt_get_install_this
45 else
46 echo "Please install this dependencies manually:"
47 echo $apt_get_install_this
48 echo "Have you installed this already (y/n)?"
49 echo y | read answer
50 if echo $answer | grep -q ^[yY]
51 then
52 true
53 else
54 echo Please install the dependencies and rerun the script
55 exit 1
56 fi
57 fi
58 }
61 step()
62 {
64 msg="$1"
65 shift
66 printf "${whiteC}""$msg""...${normC}\n"
67 # eval "$@" 2>&1 | sed 's/^/|\ \ \ /' && printf "Ok\n" || printf "Failed\n"
68 eval "$@" 2>&1 > log 2>&1 && \
69 {
70 cat log | sed 's/^/|\ \ \ /'
71 printf "${greenC}""Ok\n""${normC}"
72 } || \
73 {
74 cat log | sed 's/^/|\ \ \ /'
75 printf "${redC}""Failed\n""${normC}"
76 }
77 }
79 get_user_home()
80 {
81 uname -a | grep -qi freebsd && pw user show "$@"| awk -F: '{print $9}' || getent passwd "$@"| awk -F: '{print $6}'
82 }
84 install_to_users_homes()
85 {
86 . l3bashrc
87 users="$@"
88 set -x
89 for user in $users
90 do
91 user_home=`get_user_home "$user"`
92 mkdir -p ${user_home}/${lilalo_home}
93 mkdir /etc/lilalo/
94 cp l3config.pm /etc/lilalo/
95 cp l3-agent /usr/local/bin
96 cp l3-config /usr/local/bin
97 chmod 755 /usr/local/bin/l3-{agent,config}
98 cp l3bashrc ${user_home}/${lilalo_home}
99 cp l3prompt ${user_home}/${lilalo_home}
100 chmod 755 ${user_home}/${lilalo_home}/l3prompt
101 chown -R $user ${user_home}/${lilalo_home}
102 echo l3cd=${lilalo_context}/$user > ${user_home}/${lilalo_rc}
103 chown -R $user ${user_home}/${lilalo_rc}
104 done
105 set +x
106 }
108 install_to_users_bashrc()
109 {
110 users="$@"
111 for user in $users
112 do
113 user_home=`get_user_home "$user"`
114 grep -q lilalo ${user_home}/.bashrc 2> /dev/null\
115 || echo ". ${user_home}/.lilalo/l3bashrc && _l3_start" >> ${user_home}/.bashrc; chown -R ${user} ${user_home}/.bashrc
116 done
117 }
119 install_to_users_bash_profile()
120 {
121 users="$@"
122 for user in $users
123 do
124 user_home=`get_user_home "$user"`
125 grep -q l3-agent ${user_home}/.bash_profile 2> /dev/null \
126 || { 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; }
127 done
128 }
130 show_usage()
131 {
132 cat <<USAGE
133 Usage:
134 $0
135 USAGE
136 }
138 show_final_message()
139 {
140 cat <<FINAL_MESSAGE
143 Installation is successfully completed.
144 Now restart your shell or relogin
145 to start script writing.
147 Your current lilalo context is ${lilalo_context}/USER
148 If you use xgu.ru backend, your labs will be available at
149 http://xgu.ru/l3/${lilalo_context}
151 Use commands
152 $ l3cd ${lilalo_context%/*/*}/MY-NEW-CONTEXT/${hostname}/USER
153 $ l3pwd
154 to change and to know your current context.
156 For further information see http://xgu.ru/lilalo/ (in Russian).
158 Thank you gor using LiLaLo.
159 Happy Labbing!
161 (don't forget to restart bash or relogin)
163 FINAL_MESSAGE
164 }
167 temp_dir=/tmp/lilalo-install-temp-$$
168 mkdir -p ${temp_dir}
169 cd ${temp_dir}
170 step "Installing dependencies" apt_get_install_deps
171 step "Downloading l3bashrc" ${wget} ${url_l3bashrc}
172 step "Downloading l3prompt" ${wget} ${url_l3prompt}
173 step "Downloading l3-agent" '${wget} ${url_l3agent}; ${wget} ${url_l3configpm}; ${wget} ${url_l3config}'
174 step "Downloading perl modules for l3-agent" '{ for i in ${perl_modules}; do ${wget} ${url_perl_modules}/$i.tar.gz; done; }'
175 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; }'
176 step "Installing l3bashrc to users home directories" install_to_users_homes $install_l3bashrc_for_this_users
177 step "Adding l3bashrc invocation to ~/.bashrc " install_to_users_bashrc $install_l3bashrc_for_this_users
178 step "Adding l3-agent invocation to ~/.bash_profile " install_to_users_bash_profile $install_l3bashrc_for_this_users
179 cd /
180 rm -rf ${temp_dir}
182 show_final_message