lilalo
annotate install @ 148:266dae9ce2a1
mass upload
author | igor@book.xt.vpn |
---|---|
date | Tue Dec 16 00:18:23 2008 +0200 (2008-12-16) |
parents | 576a546271c6 |
children | d775ffd49dbf |
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 |
igor@137 | 10 lilalo_user=${lilalo_user:-YOUR-L3BACKEND-USER} |
igor@137 | 11 lab=${lab:-SET-YOUR-FIRSTLAB-NAME-HERE} |
igor@137 | 12 install_l3bashrc_for_this_users=${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@136 | 98 ln -s `which bash` /usr/local/bin/l3script |
igor@115 | 99 chmod 755 /usr/local/bin/l3-{agent,config} |
devi@106 | 100 cp l3bashrc ${user_home}/${lilalo_home} |
igor@114 | 101 cp l3prompt ${user_home}/${lilalo_home} |
igor@114 | 102 chmod 755 ${user_home}/${lilalo_home}/l3prompt |
devi@106 | 103 chown -R $user ${user_home}/${lilalo_home} |
devi@106 | 104 echo l3cd=${lilalo_context}/$user > ${user_home}/${lilalo_rc} |
devi@106 | 105 chown -R $user ${user_home}/${lilalo_rc} |
devi@106 | 106 done |
devi@106 | 107 set +x |
devi@106 | 108 } |
devi@106 | 109 |
devi@106 | 110 install_to_users_bashrc() |
devi@106 | 111 { |
devi@106 | 112 users="$@" |
devi@106 | 113 for user in $users |
devi@106 | 114 do |
devi@106 | 115 user_home=`get_user_home "$user"` |
devi@106 | 116 grep -q lilalo ${user_home}/.bashrc 2> /dev/null\ |
igor@138 | 117 || echo "[ \$0 == l3script ] && . ${user_home}/.lilalo/l3bashrc && _l3_start" >> ${user_home}/.bashrc; chown -R ${user} ${user_home}/.bashrc |
devi@106 | 118 done |
devi@106 | 119 } |
devi@106 | 120 |
devi@106 | 121 install_to_users_bash_profile() |
devi@106 | 122 { |
devi@106 | 123 users="$@" |
devi@106 | 124 for user in $users |
devi@106 | 125 do |
devi@106 | 126 user_home=`get_user_home "$user"` |
devi@106 | 127 grep -q l3-agent ${user_home}/.bash_profile 2> /dev/null \ |
devi@108 | 128 || { 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 | 129 done |
devi@106 | 130 } |
devi@106 | 131 |
devi@106 | 132 show_usage() |
devi@106 | 133 { |
devi@106 | 134 cat <<USAGE |
devi@106 | 135 Usage: |
devi@106 | 136 $0 |
devi@106 | 137 USAGE |
devi@106 | 138 } |
devi@106 | 139 |
devi@106 | 140 show_final_message() |
devi@106 | 141 { |
devi@106 | 142 cat <<FINAL_MESSAGE |
devi@106 | 143 |
devi@106 | 144 |
devi@106 | 145 Installation is successfully completed. |
devi@106 | 146 Now restart your shell or relogin |
devi@106 | 147 to start script writing. |
devi@106 | 148 |
devi@106 | 149 Your current lilalo context is ${lilalo_context}/USER |
devi@106 | 150 If you use xgu.ru backend, your labs will be available at |
devi@106 | 151 http://xgu.ru/l3/${lilalo_context} |
devi@106 | 152 |
devi@106 | 153 Use commands |
devi@106 | 154 $ l3cd ${lilalo_context%/*/*}/MY-NEW-CONTEXT/${hostname}/USER |
devi@106 | 155 $ l3pwd |
devi@106 | 156 to change and to know your current context. |
devi@106 | 157 |
devi@106 | 158 For further information see http://xgu.ru/lilalo/ (in Russian). |
devi@106 | 159 |
devi@106 | 160 Thank you gor using LiLaLo. |
devi@106 | 161 Happy Labbing! |
devi@106 | 162 |
devi@106 | 163 (don't forget to restart bash or relogin) |
devi@106 | 164 |
devi@106 | 165 FINAL_MESSAGE |
devi@106 | 166 } |
devi@106 | 167 |
devi@106 | 168 |
devi@106 | 169 temp_dir=/tmp/lilalo-install-temp-$$ |
devi@106 | 170 mkdir -p ${temp_dir} |
devi@106 | 171 cd ${temp_dir} |
igor@109 | 172 step "Installing dependencies" apt_get_install_deps |
devi@106 | 173 step "Downloading l3bashrc" ${wget} ${url_l3bashrc} |
igor@114 | 174 step "Downloading l3prompt" ${wget} ${url_l3prompt} |
igor@118 | 175 step "Downloading l3-agent" '${wget} ${url_l3agent}; ${wget} ${url_l3config_pm}; ${wget} ${url_l3config}' |
devi@106 | 176 step "Downloading perl modules for l3-agent" '{ for i in ${perl_modules}; do ${wget} ${url_perl_modules}/$i.tar.gz; done; }' |
devi@106 | 177 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 | 178 step "Installing l3bashrc to users home directories" install_to_users_homes $install_l3bashrc_for_this_users |
devi@106 | 179 step "Adding l3bashrc invocation to ~/.bashrc " install_to_users_bashrc $install_l3bashrc_for_this_users |
devi@106 | 180 step "Adding l3-agent invocation to ~/.bash_profile " install_to_users_bash_profile $install_l3bashrc_for_this_users |
devi@106 | 181 cd / |
devi@106 | 182 rm -rf ${temp_dir} |
devi@106 | 183 |
devi@106 | 184 show_final_message |
devi@106 | 185 |