lilalo

annotate install @ 108:0d49f33696b3

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