lilalo
annotate lm-install @ 28:450b6ac9b657
Незначительные исправления:
* Исправлена обработка diff-файлов. Теперь они обрабатываются
в реальном времени
* Указан путь к mywi-client
* Исправлен путь к иконкам google/freebsd/linux
* Исправлена обработка diff-файлов. Теперь они обрабатываются
в реальном времени
* Указан путь к mywi-client
* Исправлен путь к иконкам google/freebsd/linux
author | devi |
---|---|
date | Mon Nov 07 12:23:13 2005 +0200 (2005-11-07) |
parents | 05d496f33d76 |
children | 4d252e7dd478 |
rev | line source |
---|---|
devi@0 | 1 #!/bin/sh |
devi@0 | 2 |
devi@0 | 3 # Use -d to deinstall labmaker |
devi@0 | 4 # You can specify directory list to install LabMaker as command line parameters |
devi@0 | 5 # or set it in $users_to_install variable |
devi@0 | 6 |
devi@0 | 7 # CONFIGURABLE SECTION start |
devi@0 | 8 #users_to_install="/home/your-user-here /root" |
devi@0 | 9 # CONFIGURABLE SECTION stop |
devi@0 | 10 |
devi@0 | 11 first_lab=T1 |
devi@0 | 12 editors_to_install='/bin/vi /usr/bin/vi /usr/bin/vim /bin/ee /usr/bin/ee /usr/bin/pico /usr/bin/nano /usr/local/bin/vim' |
devi@0 | 13 temp_file=/tmp/lm-install-$$ |
devi@0 | 14 arg=$@ |
devi@0 | 15 |
devi@0 | 16 show_usage() |
devi@0 | 17 { |
devi@0 | 18 cat << USAGE |
devi@0 | 19 |
devi@0 | 20 $0 [-d] path... |
devi@0 | 21 |
devi@0 | 22 * Use -d to deinstall labmaker |
devi@0 | 23 * You can specify directory list to install LabMaker as command line parameters |
devi@0 | 24 or set it in \$users_to_install variable in the script |
devi@0 | 25 |
devi@0 | 26 Example: |
devi@0 | 27 |
devi@0 | 28 Command |
devi@0 | 29 # $0 /root /home/user |
devi@0 | 30 installs labmaker to /root and /home/user directories |
devi@0 | 31 |
devi@0 | 32 USAGE |
devi@0 | 33 } |
devi@0 | 34 |
devi@0 | 35 install_to_profile() |
devi@0 | 36 { |
devi@0 | 37 profile=$1 |
devi@0 | 38 cat $profile \ |
devi@0 | 39 | sed '/LabMaker:START/,/LabMaker:END/ d' \ |
devi@0 | 40 > $temp_file |
devi@0 | 41 cat <<'LM_bash_profile' >> $temp_file |
devi@0 | 42 # LabMaker:START |
devi@0 | 43 #LMHOME=~/.labmaker |
devi@0 | 44 #mkdir -p ${LMHOME} |
devi@0 | 45 #TTY=`tty` |
devi@0 | 46 #flush="-f" |
devi@0 | 47 #exec script $flush -q $LMHOME/${TTY##*/}-$$.script |
devi@0 | 48 # LabMaker:END |
devi@0 | 49 LM_bash_profile |
devi@0 | 50 cat $temp_file > $profile |
devi@0 | 51 rm $temp_file |
devi@0 | 52 } |
devi@0 | 53 |
devi@0 | 54 uninstall_from_profile() |
devi@0 | 55 { |
devi@0 | 56 profile=$1 |
devi@0 | 57 cat $profile \ |
devi@0 | 58 | sed '/LabMaker:START/,/LabMaker:END/ d' \ |
devi@0 | 59 > $temp_file |
devi@0 | 60 cat $temp_file > $profile |
devi@0 | 61 rm $temp_file |
devi@0 | 62 } |
devi@0 | 63 |
devi@0 | 64 install_to_bashrc() |
devi@0 | 65 { |
devi@0 | 66 profile=$1 |
devi@0 | 67 cat $profile \ |
devi@0 | 68 | sed '/LabMaker:START/,/LabMaker:END/ d' \ |
devi@0 | 69 > $temp_file |
devi@0 | 70 cat <<'LM_bash_profile' >> $temp_file |
devi@27 | 71 # LabMaker:START |
devi@27 | 72 LMHOME=~/.labmaker |
devi@27 | 73 mkdir -p ${LMHOME} |
devi@0 | 74 |
devi@27 | 75 uname -a | grep -qi bsd && bsd=yes |
devi@27 | 76 flush="-f" #linux |
devi@27 | 77 [ -n "$bsd" ] && flush="-t 0" #freebsd |
devi@17 | 78 |
devi@27 | 79 tty=`tty` |
devi@27 | 80 this_term=`w | grep "${tty##/dev/}" | awk '{print $8;}'` |
devi@27 | 81 # freeBSD: |
devi@27 | 82 [ -n "$bsd" ] && this_term=`w | grep "${tty##/dev/tty}" | awk '{print $6;}'` |
devi@17 | 83 |
devi@16 | 84 |
devi@27 | 85 export PS1='\[` |
devi@27 | 86 a="$?"; |
devi@27 | 87 HIDDEN=$([ "$a" = 0 ] || echo -n ^"$a")$(echo -n _${UID}_)$(echo -n _$$_)$(date\ |
devi@27 | 88 +"%j$(cat ${LMHOME}/lab 2>/dev/null) %H:%M:%S"); |
devi@27 | 89 echo $HIDDEN`\033[50D\033[K\][\u@\h:\W]\$ ' |
devi@16 | 90 |
devi@27 | 91 if [ -n "$this_term" ] && echo $this_term | grep -qv script |
devi@27 | 92 then |
devi@27 | 93 session_id=${tty##*/}-$$ |
devi@27 | 94 parent=`cat /proc/$PPID/cmdline 2> /dev/null` |
devi@27 | 95 system=`uname -rs` |
devi@27 | 96 login_from=`who | grep "${tty##/dev/}" | awk '{print $6;}' | tr -d '()'` |
devi@27 | 97 [ -n "$bsd" ] && login_from="" #FIXME! |
devi@27 | 98 start_time=`date +%s` |
devi@27 | 99 hostname=`hostname -f` |
devi@16 | 100 |
devi@27 | 101 cat <<INFO > $LMHOME/${session_id}.info |
devi@27 | 102 <session> |
devi@27 | 103 <session_id>$session_id</session_id> |
devi@27 | 104 <hostname>$hostname</hostname> |
devi@27 | 105 <user>$USER</user> |
devi@27 | 106 <login_from>$login_from</login_from> |
devi@27 | 107 <tty>$tty</tty> |
devi@27 | 108 <system>$system</system> |
devi@27 | 109 <parent>$parent</parent> |
devi@27 | 110 <ppid>$PPID</ppid> |
devi@27 | 111 <pid>$$</pid> |
devi@27 | 112 <start_time>$start_time</start_time> |
devi@27 | 113 </session> |
devi@27 | 114 INFO |
devi@27 | 115 |
devi@27 | 116 exec script $flush -q $LMHOME/${session_id}.script |
devi@27 | 117 fi |
devi@27 | 118 # LabMaker:END |
devi@0 | 119 LM_bash_profile |
devi@0 | 120 cat $temp_file > $profile |
devi@0 | 121 rm $temp_file |
devi@0 | 122 } |
devi@0 | 123 |
devi@0 | 124 uninstall_from_bashrc() |
devi@0 | 125 { |
devi@0 | 126 profile=$1 |
devi@0 | 127 cat $profile \ |
devi@0 | 128 | sed '/LabMaker:START/,/LabMaker:END/ d' \ |
devi@0 | 129 > $temp_file |
devi@0 | 130 cat $temp_file > $profile |
devi@0 | 131 rm $temp_file |
devi@0 | 132 } |
devi@0 | 133 |
devi@0 | 134 install_editor() |
devi@0 | 135 { |
devi@0 | 136 editor=$1 |
devi@0 | 137 [ -e $editor.orig ] && cp $editor.orig $editor |
devi@0 | 138 cp $editor $editor.orig |
devi@0 | 139 cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor |
devi@0 | 140 #!/bin/sh |
devi@0 | 141 |
devi@0 | 142 LMHOME=~/.labmaker |
devi@0 | 143 if [ "${1#-}" = "$1" -a -d "$LMHOME" ] |
devi@0 | 144 then |
devi@0 | 145 LAB=`cat $LMHOME/lab` |
devi@0 | 146 TIME="`date +%j${LAB}_%H:%M:%S`" |
devi@0 | 147 DIR="" |
devi@0 | 148 [ "${1#/}" = "$1" ] && DIR=$PWD/ |
devi@0 | 149 DIFFNAME=$PPID_${TIME}_`echo $DIR$1| sed s@_@__@ | sed 's@/@_@g'`.diff |
devi@0 | 150 tmp="/tmp/lm-saved-$$" |
devi@0 | 151 touch $1 |
devi@0 | 152 cp -- "$1" $tmp 2> /dev/null |
devi@0 | 153 EDITOR.orig "$@" || ERR=1 |
devi@0 | 154 diff $tmp $1 > $LMHOME/$DIFFNAME 2> /dev/null |
devi@0 | 155 rm $tmp 2> /dev/null |
devi@0 | 156 if [ "$ERR" = 1 ] |
devi@0 | 157 then |
devi@0 | 158 false |
devi@0 | 159 else |
devi@0 | 160 true |
devi@0 | 161 fi |
devi@0 | 162 else |
devi@0 | 163 exec EDITOR.orig "$@" |
devi@0 | 164 fi |
devi@0 | 165 editor_wrapper |
devi@0 | 166 |
devi@0 | 167 } |
devi@0 | 168 |
devi@0 | 169 |
devi@0 | 170 uninstall_editor() |
devi@0 | 171 { |
devi@0 | 172 editor=$1 |
devi@0 | 173 [ -e $editor.orig ] && mv $editor.orig $editor |
devi@0 | 174 } |
devi@0 | 175 |
devi@0 | 176 if [ "$1" != "-d" ] |
devi@0 | 177 then |
devi@0 | 178 # INSTALLING LM |
devi@0 | 179 if [ $# -gt 0 ] |
devi@0 | 180 then |
devi@0 | 181 users_to_install="$*" |
devi@0 | 182 fi |
devi@0 | 183 |
devi@0 | 184 if [ -z "$users_to_install" ] |
devi@0 | 185 then |
devi@0 | 186 show_usage |
devi@0 | 187 exit |
devi@0 | 188 fi |
devi@0 | 189 |
devi@8 | 190 for home in $users_to_install |
devi@0 | 191 do |
devi@8 | 192 # fix this! |
devi@8 | 193 user=${home%/} |
devi@8 | 194 user=${user##*/} |
devi@0 | 195 mkdir -p $home/.labmaker |
devi@0 | 196 echo $first_lab > $home/.labmaker/lab |
devi@8 | 197 chown -R $user $home/.labmaker |
devi@0 | 198 |
devi@8 | 199 #if [ ! -e $home/.bash_profile ] |
devi@8 | 200 #then |
devi@8 | 201 # echo '. ~/.bashrc' >> ~/.bash_profile |
devi@8 | 202 #fi |
devi@8 | 203 #[ -e $home/.bash_profile ] \ |
devi@8 | 204 # && install_to_profile $home/.bash_profile \ |
devi@8 | 205 # && echo LabMaker is installed to $home/.bash_profile |
devi@8 | 206 |
devi@8 | 207 echo Don\'t forget to check .bash_profile for .bashrc call |
devi@0 | 208 |
devi@0 | 209 [ -e $home/.profile ] && install_to_profile $home/.profile \ |
devi@0 | 210 && install_to_profile $home/.profile \ |
devi@0 | 211 && echo LabMaker is installed to $home/.profile |
devi@0 | 212 |
devi@0 | 213 touch $home/.bashrc |
devi@0 | 214 [ -e $home/.bashrc ] && install_to_bashrc $home/.bashrc \ |
devi@0 | 215 && install_to_bashrc $home/.bashrc \ |
devi@0 | 216 && echo LabMaker is installed to $home/.bashrc |
devi@0 | 217 done |
devi@0 | 218 |
devi@0 | 219 for editor in $editors_to_install |
devi@0 | 220 do |
devi@0 | 221 [ -e $editor ] \ |
devi@0 | 222 && install_editor $editor \ |
devi@0 | 223 && echo LabMaker is installed to $editor |
devi@0 | 224 done |
devi@0 | 225 else |
devi@0 | 226 # UNINSTALLING LM |
devi@0 | 227 shift |
devi@0 | 228 users_to_install="$*" |
devi@0 | 229 for user in $users_to_install |
devi@0 | 230 do |
devi@0 | 231 home=$user |
devi@0 | 232 mkdir -p $home/.labmaker |
devi@0 | 233 echo $first_lab > $home/.labmaker/lab |
devi@0 | 234 chown -R ${user##*/} $home/.labmaker |
devi@0 | 235 |
devi@8 | 236 #if [ ! -e $home/.bash_profile ] |
devi@8 | 237 #then |
devi@8 | 238 # echo '. ~/.bashrc' >> ~/.bash_profile |
devi@8 | 239 #fi |
devi@8 | 240 #[ -e $home/.bash_profile ] \ |
devi@8 | 241 # && uninstall_from_profile $home/.bash_profile \ |
devi@8 | 242 # && echo LabMaker is uninstalled from $home/.bash_profile |
devi@0 | 243 |
devi@0 | 244 [ -e $home/.profile ] && uninstall_from_profile $home/.profile \ |
devi@0 | 245 && uninstall_from_profile $home/.profile \ |
devi@0 | 246 && echo LabMaker is uninstalled from $home/.profile |
devi@0 | 247 |
devi@0 | 248 touch $home/.bashrc |
devi@0 | 249 [ -e $home/.bashrc ] && uninstall_from_bashrc $home/.bashrc \ |
devi@0 | 250 && uninstall_from_bashrc $home/.bashrc \ |
devi@0 | 251 && echo LabMaker is uninstalled from $home/.bashrc |
devi@0 | 252 done |
devi@0 | 253 |
devi@0 | 254 for editor in $editors_to_install |
devi@0 | 255 do |
devi@0 | 256 [ -e $editor ] \ |
devi@0 | 257 && uninstall_editor $editor \ |
devi@0 | 258 && echo LabMaker is uninstalled from $editor |
devi@0 | 259 done |
devi@0 | 260 fi |