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