lilalo

annotate install @ 106:53b890d1ae90

small changes
author devi
date Fri Aug 04 17:41:31 2006 +0300 (2006-08-04)
parents
children 0d49f33696b3
rev   line source
devi@106 1 #!/bin/sh
devi@106 2
devi@106 3 lilalo_rc=.l3rc
devi@106 4 lilalo_home=.lilalo
devi@106 5 url_lilalo="http://xgu.ru/lilalo"
devi@106 6 url_l3bashrc="${url_lilalo}"/l3bashrc
devi@106 7 url_l3agent="${url_lilalo}"/l3-agent
devi@106 8 url_l3config="${url_lilalo}"/l3config.pm
devi@106 9 url_perl_modules=${url_lilalo}/
devi@106 10 perl_modules="Term-VT102 Text-Iconv"
devi@106 11
devi@106 12 wget=wget
devi@106 13 uname -a | grep -qi bsd && wget=fetch
devi@106 14
devi@106 15 normC='\033[0;39m'
devi@106 16 whiteC='\033[1;37m'
devi@106 17 redC='\033[0;31m'
devi@106 18 greenC='\033[0;32m'
devi@106 19
devi@106 20 hostname=`hostname`
devi@106 21 uname -a | grep -qi freebsd || hostname=`hostname -f`
devi@106 22
devi@106 23
devi@106 24 # Ask this variables:
devi@106 25
devi@106 26 lilalo_user="devi"
devi@106 27 lab="lilalo-installation"
devi@106 28 install_l3bashrc_for_this_users="root ak devi"
devi@106 29 lilalo_context="/users/${lilalo_user}/${lab}/${hostname}"
devi@106 30
devi@106 31
devi@106 32 step()
devi@106 33 {
devi@106 34
devi@106 35 msg="$1"
devi@106 36 shift
devi@106 37 printf "${whiteC}""$msg""...${normC}\n"
devi@106 38 # eval "$@" 2>&1 | sed 's/^/|\ \ \ /' && printf "Ok\n" || printf "Failed\n"
devi@106 39 eval "$@" 2>&1 > log 2>&1 && \
devi@106 40 {
devi@106 41 cat log | sed 's/^/|\ \ \ /'
devi@106 42 printf "${greenC}""Ok\n""${normC}"
devi@106 43 } || \
devi@106 44 {
devi@106 45 cat log | sed 's/^/|\ \ \ /'
devi@106 46 printf "${redC}""Failed\n""${normC}"
devi@106 47 }
devi@106 48 }
devi@106 49
devi@106 50 get_user_home()
devi@106 51 {
devi@106 52 uname -a | grep -qi freebsd && pw user show "$@"| awk -F: '{print $9}' || getent passwd "$@"| awk -F: '{print $6}'
devi@106 53 }
devi@106 54
devi@106 55 install_to_users_homes()
devi@106 56 {
devi@106 57 . l3bashrc
devi@106 58 users="$@"
devi@106 59 set -x
devi@106 60 for user in $users
devi@106 61 do
devi@106 62 user_home=`get_user_home "$user"`
devi@106 63 mkdir -p ${user_home}/${lilalo_home}
devi@106 64 cp l3config.pm /usr/local/bin
devi@106 65 cp l3-agent /usr/local/bin
devi@106 66 chmod 755 /usr/local/bin/l3-agent
devi@106 67 cp l3bashrc ${user_home}/${lilalo_home}
devi@106 68 chown -R $user ${user_home}/${lilalo_home}
devi@106 69 echo l3cd=${lilalo_context}/$user > ${user_home}/${lilalo_rc}
devi@106 70 chown -R $user ${user_home}/${lilalo_rc}
devi@106 71 done
devi@106 72 set +x
devi@106 73 }
devi@106 74
devi@106 75 install_to_users_bashrc()
devi@106 76 {
devi@106 77 users="$@"
devi@106 78 for user in $users
devi@106 79 do
devi@106 80 user_home=`get_user_home "$user"`
devi@106 81 grep -q lilalo ${user_home}/.bashrc 2> /dev/null\
devi@106 82 || echo ". ${user_home}/.lilalo/l3bashrc && _l3_start" >> ${user_home}/.bashrc; chown -R ${user} ${user_home}/.bashrc
devi@106 83 done
devi@106 84 }
devi@106 85
devi@106 86 install_to_users_bash_profile()
devi@106 87 {
devi@106 88 users="$@"
devi@106 89 for user in $users
devi@106 90 do
devi@106 91 user_home=`get_user_home "$user"`
devi@106 92 grep -q l3-agent ${user_home}/.bash_profile 2> /dev/null \
devi@106 93 || { echo >> ${user_home}/.bash_profile ; cat ${user_home}/.bash_profile | sed '1s/^/l3-agent/' > /tmp/$$$$l3 ; mv /tmp/$$$$l3 ${user_home}/.bash_profile; chown -R ${user} ${user_home}/.bash_profile; }
devi@106 94 done
devi@106 95 }
devi@106 96
devi@106 97 show_usage()
devi@106 98 {
devi@106 99 cat <<USAGE
devi@106 100 Usage:
devi@106 101 $0
devi@106 102 USAGE
devi@106 103 }
devi@106 104
devi@106 105 show_final_message()
devi@106 106 {
devi@106 107 cat <<FINAL_MESSAGE
devi@106 108
devi@106 109
devi@106 110 Installation is successfully completed.
devi@106 111 Now restart your shell or relogin
devi@106 112 to start script writing.
devi@106 113
devi@106 114 Your current lilalo context is ${lilalo_context}/USER
devi@106 115 If you use xgu.ru backend, your labs will be available at
devi@106 116 http://xgu.ru/l3/${lilalo_context}
devi@106 117
devi@106 118 Use commands
devi@106 119 $ l3cd ${lilalo_context%/*/*}/MY-NEW-CONTEXT/${hostname}/USER
devi@106 120 $ l3pwd
devi@106 121 to change and to know your current context.
devi@106 122
devi@106 123 For further information see http://xgu.ru/lilalo/ (in Russian).
devi@106 124
devi@106 125 Thank you gor using LiLaLo.
devi@106 126 Happy Labbing!
devi@106 127
devi@106 128 (don't forget to restart bash or relogin)
devi@106 129
devi@106 130 FINAL_MESSAGE
devi@106 131 }
devi@106 132
devi@106 133
devi@106 134 temp_dir=/tmp/lilalo-install-temp-$$
devi@106 135 mkdir -p ${temp_dir}
devi@106 136 cd ${temp_dir}
devi@106 137 step "Downloading l3bashrc" ${wget} ${url_l3bashrc}
devi@106 138 step "Downloading l3-agent" '${wget} ${url_l3agent}; ${wget} ${url_l3config}'
devi@106 139 step "Downloading perl modules for l3-agent" '{ for i in ${perl_modules}; do ${wget} ${url_perl_modules}/$i.tar.gz; done; }'
devi@106 140 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 141 step "Installing l3bashrc to users home directories" install_to_users_homes $install_l3bashrc_for_this_users
devi@106 142 step "Adding l3bashrc invocation to ~/.bashrc " install_to_users_bashrc $install_l3bashrc_for_this_users
devi@106 143 step "Adding l3-agent invocation to ~/.bash_profile " install_to_users_bash_profile $install_l3bashrc_for_this_users
devi@106 144 cd /
devi@106 145 rm -rf ${temp_dir}
devi@106 146
devi@106 147 show_final_message
devi@106 148