lilalo
diff lm-install @ 7:614945eed906
Записал более правильно тэг Id в коде
author | devi |
---|---|
date | Tue May 24 16:25:24 2005 +0300 (2005-05-24) |
parents | |
children | 56e8b17b1823 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/lm-install Tue May 24 16:25:24 2005 +0300 1.3 @@ -0,0 +1,227 @@ 1.4 +#!/bin/sh 1.5 + 1.6 +# Use -d to deinstall labmaker 1.7 +# You can specify directory list to install LabMaker as command line parameters 1.8 +# or set it in $users_to_install variable 1.9 + 1.10 +# CONFIGURABLE SECTION start 1.11 +#users_to_install="/home/your-user-here /root" 1.12 +# CONFIGURABLE SECTION stop 1.13 + 1.14 +first_lab=T1 1.15 +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' 1.16 +temp_file=/tmp/lm-install-$$ 1.17 +arg=$@ 1.18 + 1.19 +show_usage() 1.20 +{ 1.21 + cat << USAGE 1.22 + 1.23 +$0 [-d] path... 1.24 + 1.25 + * Use -d to deinstall labmaker 1.26 + * You can specify directory list to install LabMaker as command line parameters 1.27 + or set it in \$users_to_install variable in the script 1.28 + 1.29 +Example: 1.30 + 1.31 + Command 1.32 + # $0 /root /home/user 1.33 + installs labmaker to /root and /home/user directories 1.34 + 1.35 +USAGE 1.36 +} 1.37 + 1.38 +install_to_profile() 1.39 +{ 1.40 + profile=$1 1.41 + cat $profile \ 1.42 + | sed '/LabMaker:START/,/LabMaker:END/ d' \ 1.43 + > $temp_file 1.44 + cat <<'LM_bash_profile' >> $temp_file 1.45 + # LabMaker:START 1.46 + #LMHOME=~/.labmaker 1.47 + #mkdir -p ${LMHOME} 1.48 + #TTY=`tty` 1.49 + #flush="-f" 1.50 + #exec script $flush -q $LMHOME/${TTY##*/}-$$.script 1.51 + # LabMaker:END 1.52 +LM_bash_profile 1.53 + cat $temp_file > $profile 1.54 + rm $temp_file 1.55 +} 1.56 + 1.57 +uninstall_from_profile() 1.58 +{ 1.59 + profile=$1 1.60 + cat $profile \ 1.61 + | sed '/LabMaker:START/,/LabMaker:END/ d' \ 1.62 + > $temp_file 1.63 + cat $temp_file > $profile 1.64 + rm $temp_file 1.65 +} 1.66 + 1.67 +install_to_bashrc() 1.68 +{ 1.69 + profile=$1 1.70 + cat $profile \ 1.71 + | sed '/LabMaker:START/,/LabMaker:END/ d' \ 1.72 + > $temp_file 1.73 + cat <<'LM_bash_profile' >> $temp_file 1.74 + # LabMaker:START 1.75 + TTY=`tty` 1.76 + 1.77 + this_term=`w | grep "${TTY##/dev/}" | awk '{print $8;}'` 1.78 + # freeBSD: 1.79 + this_term=`w | grep "${TTY##/dev/tty}" | awk '{print $6;}'` 1.80 + if [ -n "$this_term" ] && echo $this_term | grep -qv script 1.81 + then 1.82 + LMHOME=~/.labmaker 1.83 + mkdir -p ${LMHOME} 1.84 + flush="-f" #linux 1.85 + flush="-t 0" #freebsd 1.86 + exec script $flush -q $LMHOME/${TTY##*/}-$$.script 1.87 + fi 1.88 + PS1='\[` a="$?"; 1.89 + HIDDEN=$([ "$a" = 0 ] || echo -n ^"$a")$(echo -n _${UID}_)$(echo -n _$$_)$(date\ 1.90 + +"%j$(cat ~/.labmaker/lab 2>/dev/null) %H:%M:%S"); 1.91 + echo $HIDDEN`\033[50D\033[K\][\u@\h:\W]\$ ' 1.92 + # LabMaker:END 1.93 +LM_bash_profile 1.94 + cat $temp_file > $profile 1.95 + rm $temp_file 1.96 +} 1.97 + 1.98 +uninstall_from_bashrc() 1.99 +{ 1.100 + profile=$1 1.101 + cat $profile \ 1.102 + | sed '/LabMaker:START/,/LabMaker:END/ d' \ 1.103 + > $temp_file 1.104 + cat $temp_file > $profile 1.105 + rm $temp_file 1.106 +} 1.107 + 1.108 +install_editor() 1.109 +{ 1.110 +editor=$1 1.111 +[ -e $editor.orig ] && cp $editor.orig $editor 1.112 +cp $editor $editor.orig 1.113 +cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor 1.114 +#!/bin/sh 1.115 + 1.116 +LMHOME=~/.labmaker 1.117 +if [ "${1#-}" = "$1" -a -d "$LMHOME" ] 1.118 +then 1.119 + LAB=`cat $LMHOME/lab` 1.120 + TIME="`date +%j${LAB}_%H:%M:%S`" 1.121 + DIR="" 1.122 + [ "${1#/}" = "$1" ] && DIR=$PWD/ 1.123 + DIFFNAME=$PPID_${TIME}_`echo $DIR$1| sed s@_@__@ | sed 's@/@_@g'`.diff 1.124 + tmp="/tmp/lm-saved-$$" 1.125 + touch $1 1.126 + cp -- "$1" $tmp 2> /dev/null 1.127 + EDITOR.orig "$@" || ERR=1 1.128 + diff $tmp $1 > $LMHOME/$DIFFNAME 2> /dev/null 1.129 + rm $tmp 2> /dev/null 1.130 + if [ "$ERR" = 1 ] 1.131 + then 1.132 + false 1.133 + else 1.134 + true 1.135 + fi 1.136 +else 1.137 + exec EDITOR.orig "$@" 1.138 +fi 1.139 +editor_wrapper 1.140 + 1.141 +} 1.142 + 1.143 + 1.144 +uninstall_editor() 1.145 +{ 1.146 + editor=$1 1.147 + [ -e $editor.orig ] && mv $editor.orig $editor 1.148 +} 1.149 + 1.150 +if [ "$1" != "-d" ] 1.151 +then 1.152 + # INSTALLING LM 1.153 + if [ $# -gt 0 ] 1.154 + then 1.155 + users_to_install="$*" 1.156 + fi 1.157 + 1.158 + if [ -z "$users_to_install" ] 1.159 + then 1.160 + show_usage 1.161 + exit 1.162 + fi 1.163 + 1.164 + for user in $users_to_install 1.165 + do 1.166 + home=$user # fix this! 1.167 + mkdir -p $home/.labmaker 1.168 + echo $first_lab > $home/.labmaker/lab 1.169 + chown -R ${user##*/} $home/.labmaker 1.170 + 1.171 + if [ ! -e $home/.bash_profile ] 1.172 + then 1.173 + echo '. ~/.bashrc' >> ~/.bash_profile 1.174 + fi 1.175 + [ -e $home/.bash_profile ] \ 1.176 + && install_to_profile $home/.bash_profile \ 1.177 + && echo LabMaker is installed to $home/.bash_profile 1.178 + 1.179 + [ -e $home/.profile ] && install_to_profile $home/.profile \ 1.180 + && install_to_profile $home/.profile \ 1.181 + && echo LabMaker is installed to $home/.profile 1.182 + 1.183 + touch $home/.bashrc 1.184 + [ -e $home/.bashrc ] && install_to_bashrc $home/.bashrc \ 1.185 + && install_to_bashrc $home/.bashrc \ 1.186 + && echo LabMaker is installed to $home/.bashrc 1.187 + done 1.188 + 1.189 + for editor in $editors_to_install 1.190 + do 1.191 + [ -e $editor ] \ 1.192 + && install_editor $editor \ 1.193 + && echo LabMaker is installed to $editor 1.194 + done 1.195 +else 1.196 +# UNINSTALLING LM 1.197 + shift 1.198 + users_to_install="$*" 1.199 + for user in $users_to_install 1.200 + do 1.201 + home=$user 1.202 + mkdir -p $home/.labmaker 1.203 + echo $first_lab > $home/.labmaker/lab 1.204 + chown -R ${user##*/} $home/.labmaker 1.205 + 1.206 + if [ ! -e $home/.bash_profile ] 1.207 + then 1.208 + echo '. ~/.bashrc' >> ~/.bash_profile 1.209 + fi 1.210 + [ -e $home/.bash_profile ] \ 1.211 + && uninstall_from_profile $home/.bash_profile \ 1.212 + && echo LabMaker is uninstalled from $home/.bash_profile 1.213 + 1.214 + [ -e $home/.profile ] && uninstall_from_profile $home/.profile \ 1.215 + && uninstall_from_profile $home/.profile \ 1.216 + && echo LabMaker is uninstalled from $home/.profile 1.217 + 1.218 + touch $home/.bashrc 1.219 + [ -e $home/.bashrc ] && uninstall_from_bashrc $home/.bashrc \ 1.220 + && uninstall_from_bashrc $home/.bashrc \ 1.221 + && echo LabMaker is uninstalled from $home/.bashrc 1.222 + done 1.223 + 1.224 + for editor in $editors_to_install 1.225 + do 1.226 + [ -e $editor ] \ 1.227 + && uninstall_editor $editor \ 1.228 + && echo LabMaker is uninstalled from $editor 1.229 + done 1.230 +fi