lilalo

annotate install @ 132:3638f4587c78

merge
author igor@chub.in
date Fri Jul 04 17:54:34 2008 +0300 (2008-07-04)
parents 73fb48eb8110
children 244825e244de
rev   line source
devi@106 1 #!/bin/sh
devi@106 2
devi@108 3 hostname=`hostname`
devi@108 4 uname -a | grep -qi freebsd || hostname=`hostname -f`
devi@108 5
devi@108 6 ###############################################################################
devi@108 7 #
devi@108 8 # Set this variables before installation:
devi@108 9
devi@108 10 lilalo_user="YOUR-L3BACKEND-USER"
devi@108 11 lab="SET-YOUR-FIRSTLAB-NAME-HERE"
devi@108 12 install_l3bashrc_for_this_users="root user" # users who will use l3agent and l3script
devi@108 13 lilalo_context="/users/${lilalo_user}/${lab}/${hostname}"
devi@108 14
devi@108 15 #
devi@108 16 ###############################################################################
devi@108 17
devi@108 18
devi@106 19 lilalo_rc=.l3rc
devi@106 20 lilalo_home=.lilalo
devi@106 21 url_lilalo="http://xgu.ru/lilalo"
devi@106 22 url_l3bashrc="${url_lilalo}"/l3bashrc
devi@106 23 url_l3agent="${url_lilalo}"/l3-agent
igor@115 24 url_l3config_pm="${url_lilalo}"/l3config.pm
igor@115 25 url_l3config="${url_lilalo}"/l3-config
igor@114 26 url_l3prompt="${url_lilalo}"/l3prompt
devi@106 27 url_perl_modules=${url_lilalo}/
devi@106 28 perl_modules="Term-VT102 Text-Iconv"
devi@106 29
igor@109 30 apt_get_install_this="perl make libmodule-build-perl libc6-dev gcc"
devi@108 31
devi@106 32 wget=wget
devi@106 33 uname -a | grep -qi bsd && wget=fetch
devi@106 34
devi@106 35 normC='\033[0;39m'
devi@106 36 whiteC='\033[1;37m'
devi@106 37 redC='\033[0;31m'
devi@106 38 greenC='\033[0;32m'
devi@106 39
igor@109 40 apt_get_install_deps()
igor@109 41 {
igor@123 42 return 0
igor@109 43 if which apt-get >& /dev/null
igor@109 44 then
igor@109 45 apt-get install -y $apt_get_install_this
igor@109 46 else
igor@109 47 echo "Please install this dependencies manually:"
igor@109 48 echo $apt_get_install_this
igor@109 49 echo "Have you installed this already (y/n)?"
igor@109 50 echo y | read answer
igor@109 51 if echo $answer | grep -q ^[yY]
igor@109 52 then
igor@109 53 true
igor@109 54 else
igor@109 55 echo Please install the dependencies and rerun the script
igor@109 56 exit 1
igor@109 57 fi
igor@109 58 fi
igor@109 59 }
devi@106 60
devi@106 61
devi@106 62 step()
devi@106 63 {
devi@106 64
devi@106 65 msg="$1"
devi@106 66 shift
devi@106 67 printf "${whiteC}""$msg""...${normC}\n"
devi@106 68 # eval "$@" 2>&1 | sed 's/^/|\ \ \ /' && printf "Ok\n" || printf "Failed\n"
devi@106 69 eval "$@" 2>&1 > log 2>&1 && \
devi@106 70 {
devi@106 71 cat log | sed 's/^/|\ \ \ /'
devi@106 72 printf "${greenC}""Ok\n""${normC}"
devi@106 73 } || \
devi@106 74 {
devi@106 75 cat log | sed 's/^/|\ \ \ /'
devi@106 76 printf "${redC}""Failed\n""${normC}"
devi@106 77 }
devi@106 78 }
devi@106 79
devi@106 80 get_user_home()
devi@106 81 {
devi@106 82 uname -a | grep -qi freebsd && pw user show "$@"| awk -F: '{print $9}' || getent passwd "$@"| awk -F: '{print $6}'
devi@106 83 }
devi@106 84
devi@106 85 install_to_users_homes()
devi@106 86 {
devi@106 87 . l3bashrc
devi@106 88 users="$@"
devi@106 89 set -x
devi@106 90 for user in $users
devi@106 91 do
devi@106 92 user_home=`get_user_home "$user"`
devi@106 93 mkdir -p ${user_home}/${lilalo_home}
igor@115 94 mkdir /etc/lilalo/
igor@115 95 cp l3config.pm /etc/lilalo/
devi@106 96 cp l3-agent /usr/local/bin
igor@115 97 cp l3-config /usr/local/bin
igor@115 98 chmod 755 /usr/local/bin/l3-{agent,config}
devi@106 99 cp l3bashrc ${user_home}/${lilalo_home}
igor@114 100 cp l3prompt ${user_home}/${lilalo_home}
igor@114 101 chmod 755 ${user_home}/${lilalo_home}/l3prompt
devi@106 102 chown -R $user ${user_home}/${lilalo_home}
devi@106 103 echo l3cd=${lilalo_context}/$user > ${user_home}/${lilalo_rc}
devi@106 104 chown -R $user ${user_home}/${lilalo_rc}
devi@106 105 done
devi@106 106 set +x
devi@106 107 }
devi@106 108
devi@106 109 install_to_users_bashrc()
devi@106 110 {
devi@106 111 users="$@"
devi@106 112 for user in $users
devi@106 113 do
devi@106 114 user_home=`get_user_home "$user"`
devi@106 115 grep -q lilalo ${user_home}/.bashrc 2> /dev/null\
devi@106 116 || echo ". ${user_home}/.lilalo/l3bashrc && _l3_start" >> ${user_home}/.bashrc; chown -R ${user} ${user_home}/.bashrc
devi@106 117 done
devi@106 118 }
devi@106 119
devi@106 120 install_to_users_bash_profile()
devi@106 121 {
devi@106 122 users="$@"
devi@106 123 for user in $users
devi@106 124 do
devi@106 125 user_home=`get_user_home "$user"`
devi@106 126 grep -q l3-agent ${user_home}/.bash_profile 2> /dev/null \
devi@108 127 || { 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; }
devi@106 128 done
devi@106 129 }
devi@106 130
devi@106 131 show_usage()
devi@106 132 {
devi@106 133 cat <<USAGE
devi@106 134 Usage:
devi@106 135 $0
devi@106 136 USAGE
devi@106 137 }
devi@106 138
devi@106 139 show_final_message()
devi@106 140 {
devi@106 141 cat <<FINAL_MESSAGE
devi@106 142
devi@106 143
devi@106 144 Installation is successfully completed.
devi@106 145 Now restart your shell or relogin
devi@106 146 to start script writing.
devi@106 147
devi@106 148 Your current lilalo context is ${lilalo_context}/USER
devi@106 149 If you use xgu.ru backend, your labs will be available at
devi@106 150 http://xgu.ru/l3/${lilalo_context}
devi@106 151
devi@106 152 Use commands
devi@106 153 $ l3cd ${lilalo_context%/*/*}/MY-NEW-CONTEXT/${hostname}/USER
devi@106 154 $ l3pwd
devi@106 155 to change and to know your current context.
devi@106 156
devi@106 157 For further information see http://xgu.ru/lilalo/ (in Russian).
devi@106 158
devi@106 159 Thank you gor using LiLaLo.
devi@106 160 Happy Labbing!
devi@106 161
devi@106 162 (don't forget to restart bash or relogin)
devi@106 163
devi@106 164 FINAL_MESSAGE
devi@106 165 }
devi@106 166
devi@106 167
devi@106 168 temp_dir=/tmp/lilalo-install-temp-$$
devi@106 169 mkdir -p ${temp_dir}
devi@106 170 cd ${temp_dir}
igor@109 171 step "Installing dependencies" apt_get_install_deps
devi@106 172 step "Downloading l3bashrc" ${wget} ${url_l3bashrc}
igor@114 173 step "Downloading l3prompt" ${wget} ${url_l3prompt}
igor@118 174 step "Downloading l3-agent" '${wget} ${url_l3agent}; ${wget} ${url_l3config_pm}; ${wget} ${url_l3config}'
devi@106 175 step "Downloading perl modules for l3-agent" '{ for i in ${perl_modules}; do ${wget} ${url_perl_modules}/$i.tar.gz; done; }'
devi@106 176 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; }'
devi@106 177 step "Installing l3bashrc to users home directories" install_to_users_homes $install_l3bashrc_for_this_users
devi@106 178 step "Adding l3bashrc invocation to ~/.bashrc " install_to_users_bashrc $install_l3bashrc_for_this_users
devi@106 179 step "Adding l3-agent invocation to ~/.bash_profile " install_to_users_bash_profile $install_l3bashrc_for_this_users
devi@106 180 cd /
devi@106 181 rm -rf ${temp_dir}
devi@106 182
devi@106 183 show_final_message
devi@106 184