lilalo
annotate lm-install @ 6:a0f30dd46d1a
В журнале появились секции
* статистика
* справка
* о программе
И оглавление.
В начале журнала выводится информация о том
курсе и слушателе, к которым этот журнал относится
* статистика
* справка
* о программе
И оглавление.
В начале журнала выводится информация о том
курсе и слушателе, к которым этот журнал относится
author | devi |
---|---|
date | Tue May 24 16:09:08 2005 +0300 (2005-05-24) |
parents | |
children | 56e8b17b1823 |
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@0 | 71 # LabMaker:START |
devi@0 | 72 TTY=`tty` |
devi@0 | 73 |
devi@0 | 74 this_term=`w | grep "${TTY##/dev/}" | awk '{print $8;}'` |
devi@0 | 75 # freeBSD: |
devi@0 | 76 this_term=`w | grep "${TTY##/dev/tty}" | awk '{print $6;}'` |
devi@0 | 77 if [ -n "$this_term" ] && echo $this_term | grep -qv script |
devi@0 | 78 then |
devi@0 | 79 LMHOME=~/.labmaker |
devi@0 | 80 mkdir -p ${LMHOME} |
devi@0 | 81 flush="-f" #linux |
devi@0 | 82 flush="-t 0" #freebsd |
devi@0 | 83 exec script $flush -q $LMHOME/${TTY##*/}-$$.script |
devi@0 | 84 fi |
devi@0 | 85 PS1='\[` a="$?"; |
devi@0 | 86 HIDDEN=$([ "$a" = 0 ] || echo -n ^"$a")$(echo -n _${UID}_)$(echo -n _$$_)$(date\ |
devi@0 | 87 +"%j$(cat ~/.labmaker/lab 2>/dev/null) %H:%M:%S"); |
devi@0 | 88 echo $HIDDEN`\033[50D\033[K\][\u@\h:\W]\$ ' |
devi@0 | 89 # LabMaker:END |
devi@0 | 90 LM_bash_profile |
devi@0 | 91 cat $temp_file > $profile |
devi@0 | 92 rm $temp_file |
devi@0 | 93 } |
devi@0 | 94 |
devi@0 | 95 uninstall_from_bashrc() |
devi@0 | 96 { |
devi@0 | 97 profile=$1 |
devi@0 | 98 cat $profile \ |
devi@0 | 99 | sed '/LabMaker:START/,/LabMaker:END/ d' \ |
devi@0 | 100 > $temp_file |
devi@0 | 101 cat $temp_file > $profile |
devi@0 | 102 rm $temp_file |
devi@0 | 103 } |
devi@0 | 104 |
devi@0 | 105 install_editor() |
devi@0 | 106 { |
devi@0 | 107 editor=$1 |
devi@0 | 108 [ -e $editor.orig ] && cp $editor.orig $editor |
devi@0 | 109 cp $editor $editor.orig |
devi@0 | 110 cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor |
devi@0 | 111 #!/bin/sh |
devi@0 | 112 |
devi@0 | 113 LMHOME=~/.labmaker |
devi@0 | 114 if [ "${1#-}" = "$1" -a -d "$LMHOME" ] |
devi@0 | 115 then |
devi@0 | 116 LAB=`cat $LMHOME/lab` |
devi@0 | 117 TIME="`date +%j${LAB}_%H:%M:%S`" |
devi@0 | 118 DIR="" |
devi@0 | 119 [ "${1#/}" = "$1" ] && DIR=$PWD/ |
devi@0 | 120 DIFFNAME=$PPID_${TIME}_`echo $DIR$1| sed s@_@__@ | sed 's@/@_@g'`.diff |
devi@0 | 121 tmp="/tmp/lm-saved-$$" |
devi@0 | 122 touch $1 |
devi@0 | 123 cp -- "$1" $tmp 2> /dev/null |
devi@0 | 124 EDITOR.orig "$@" || ERR=1 |
devi@0 | 125 diff $tmp $1 > $LMHOME/$DIFFNAME 2> /dev/null |
devi@0 | 126 rm $tmp 2> /dev/null |
devi@0 | 127 if [ "$ERR" = 1 ] |
devi@0 | 128 then |
devi@0 | 129 false |
devi@0 | 130 else |
devi@0 | 131 true |
devi@0 | 132 fi |
devi@0 | 133 else |
devi@0 | 134 exec EDITOR.orig "$@" |
devi@0 | 135 fi |
devi@0 | 136 editor_wrapper |
devi@0 | 137 |
devi@0 | 138 } |
devi@0 | 139 |
devi@0 | 140 |
devi@0 | 141 uninstall_editor() |
devi@0 | 142 { |
devi@0 | 143 editor=$1 |
devi@0 | 144 [ -e $editor.orig ] && mv $editor.orig $editor |
devi@0 | 145 } |
devi@0 | 146 |
devi@0 | 147 if [ "$1" != "-d" ] |
devi@0 | 148 then |
devi@0 | 149 # INSTALLING LM |
devi@0 | 150 if [ $# -gt 0 ] |
devi@0 | 151 then |
devi@0 | 152 users_to_install="$*" |
devi@0 | 153 fi |
devi@0 | 154 |
devi@0 | 155 if [ -z "$users_to_install" ] |
devi@0 | 156 then |
devi@0 | 157 show_usage |
devi@0 | 158 exit |
devi@0 | 159 fi |
devi@0 | 160 |
devi@0 | 161 for user in $users_to_install |
devi@0 | 162 do |
devi@0 | 163 home=$user # fix this! |
devi@0 | 164 mkdir -p $home/.labmaker |
devi@0 | 165 echo $first_lab > $home/.labmaker/lab |
devi@0 | 166 chown -R ${user##*/} $home/.labmaker |
devi@0 | 167 |
devi@0 | 168 if [ ! -e $home/.bash_profile ] |
devi@0 | 169 then |
devi@0 | 170 echo '. ~/.bashrc' >> ~/.bash_profile |
devi@0 | 171 fi |
devi@0 | 172 [ -e $home/.bash_profile ] \ |
devi@0 | 173 && install_to_profile $home/.bash_profile \ |
devi@0 | 174 && echo LabMaker is installed to $home/.bash_profile |
devi@0 | 175 |
devi@0 | 176 [ -e $home/.profile ] && install_to_profile $home/.profile \ |
devi@0 | 177 && install_to_profile $home/.profile \ |
devi@0 | 178 && echo LabMaker is installed to $home/.profile |
devi@0 | 179 |
devi@0 | 180 touch $home/.bashrc |
devi@0 | 181 [ -e $home/.bashrc ] && install_to_bashrc $home/.bashrc \ |
devi@0 | 182 && install_to_bashrc $home/.bashrc \ |
devi@0 | 183 && echo LabMaker is installed to $home/.bashrc |
devi@0 | 184 done |
devi@0 | 185 |
devi@0 | 186 for editor in $editors_to_install |
devi@0 | 187 do |
devi@0 | 188 [ -e $editor ] \ |
devi@0 | 189 && install_editor $editor \ |
devi@0 | 190 && echo LabMaker is installed to $editor |
devi@0 | 191 done |
devi@0 | 192 else |
devi@0 | 193 # UNINSTALLING LM |
devi@0 | 194 shift |
devi@0 | 195 users_to_install="$*" |
devi@0 | 196 for user in $users_to_install |
devi@0 | 197 do |
devi@0 | 198 home=$user |
devi@0 | 199 mkdir -p $home/.labmaker |
devi@0 | 200 echo $first_lab > $home/.labmaker/lab |
devi@0 | 201 chown -R ${user##*/} $home/.labmaker |
devi@0 | 202 |
devi@0 | 203 if [ ! -e $home/.bash_profile ] |
devi@0 | 204 then |
devi@0 | 205 echo '. ~/.bashrc' >> ~/.bash_profile |
devi@0 | 206 fi |
devi@0 | 207 [ -e $home/.bash_profile ] \ |
devi@0 | 208 && uninstall_from_profile $home/.bash_profile \ |
devi@0 | 209 && echo LabMaker is uninstalled from $home/.bash_profile |
devi@0 | 210 |
devi@0 | 211 [ -e $home/.profile ] && uninstall_from_profile $home/.profile \ |
devi@0 | 212 && uninstall_from_profile $home/.profile \ |
devi@0 | 213 && echo LabMaker is uninstalled from $home/.profile |
devi@0 | 214 |
devi@0 | 215 touch $home/.bashrc |
devi@0 | 216 [ -e $home/.bashrc ] && uninstall_from_bashrc $home/.bashrc \ |
devi@0 | 217 && uninstall_from_bashrc $home/.bashrc \ |
devi@0 | 218 && echo LabMaker is uninstalled from $home/.bashrc |
devi@0 | 219 done |
devi@0 | 220 |
devi@0 | 221 for editor in $editors_to_install |
devi@0 | 222 do |
devi@0 | 223 [ -e $editor ] \ |
devi@0 | 224 && uninstall_editor $editor \ |
devi@0 | 225 && echo LabMaker is uninstalled from $editor |
devi@0 | 226 done |
devi@0 | 227 fi |