lilalo

annotate install @ 112:da65f1cbaf3a

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