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