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