lilalo

view lm-install @ 106:53b890d1ae90

small changes
author devi
date Fri Aug 04 17:41:31 2006 +0300 (2006-08-04)
parents aa788e638a9d
children
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 <<'LM_bash_profile' > $temp_file
39 # LabMaker:START
40 /usr/local/bin/l3-agent
41 # LabMaker:END
42 LM_bash_profile
43 cat $profile \
44 | sed '/LabMaker:START/,/LabMaker:END/ d' \
45 >> $temp_file
46 cat $temp_file > $profile
47 rm $temp_file
48 }
50 uninstall_from_profile()
51 {
52 profile=$1
53 cat $profile \
54 | sed '/LabMaker:START/,/LabMaker:END/ d' \
55 > $temp_file
56 cat $temp_file > $profile
57 rm $temp_file
58 }
60 install_to_bashrc()
61 {
62 profile=$1
63 cat $profile \
64 | sed '/LabMaker:START/,/LabMaker:END/ d' \
65 > $temp_file
66 cat <<'LM_bash_profile' >> $temp_file
67 # LabMaker:START
68 LMHOME=~/.lilalo
69 mkdir -p ${LMHOME}
71 uname -a | grep -qi bsd && bsd=yes
72 flush="-f" #linux
73 [ -n "$bsd" ] && flush="-t 0" #freebsd
75 tty=`tty`
76 this_term=`w | grep "${tty##/dev/}" | awk '{print $8;}'`
77 # freeBSD:
78 [ -n "$bsd" ] && this_term=`w | grep "${tty##/dev/tty}" | awk '{print $6;}'`
81 export PS1='\[`
82 a="$?";
83 HIDDEN=$([ "$a" = 0 ] || echo -n ^"$a")$(echo -n _${UID}_)$(echo -n _$$_)$(date\
84 +"%j$(cat ${LMHOME}/lab 2>/dev/null) %H:%M:%S");
85 echo $HIDDEN`\033[50D\033[K\][\u@\h:\W]\$ '
87 if [ -n "$this_term" ] && echo $this_term | grep -qv script
88 then
89 session_id=${tty##*/}-$$
90 parent=`cat /proc/$PPID/cmdline 2> /dev/null`
91 system=`uname -rs`
92 login_from=`who | grep "${tty##/dev/}" | awk '{print $6;}' | tr -d '()'`
93 #[ -n "$bsd" ] && login_from="" #FIXME!
94 start_time=`date +%s`
95 hostname=`hostname -f 2> /dev/null`
96 [ -n "$bsd" ] && hostname=`hostname`
98 cat <<INFO > $LMHOME/${session_id}.info
99 <session>
100 <local_session_id>$session_id</local_session_id>
101 <hostname>$hostname</hostname>
102 <user>$USER</user>
103 <uid>$UID</uid>
104 <login_from>$login_from</login_from>
105 <tty>$tty</tty>
106 <system>$system</system>
107 <parent>$parent</parent>
108 <ppid>$PPID</ppid>
109 <pid>$$</pid>
110 <start_time>$start_time</start_time>
111 </session>
112 INFO
114 exec script $flush -q $LMHOME/${session_id}.script
115 fi
116 # LabMaker:END
117 LM_bash_profile
118 cat $temp_file > $profile
119 rm $temp_file
120 }
122 uninstall_from_bashrc()
123 {
124 profile=$1
125 cat $profile \
126 | sed '/LabMaker:START/,/LabMaker:END/ d' \
127 > $temp_file
128 cat $temp_file > $profile
129 rm $temp_file
130 }
132 install_editor()
133 {
134 editor=$1
135 [ -e $editor.orig ] && cp $editor.orig $editor
136 cp $editor $editor.orig
137 cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor
138 #!/bin/sh
140 LMHOME=~/.lilalo
141 if [ "${1#-}" = "$1" -a -d "$LMHOME" ]
142 then
143 LAB=`cat $LMHOME/lab`
144 TIME="`date +%j${LAB}_%H:%M:%S`"
145 DIR=""
146 [ "${1#/}" = "$1" ] && DIR=$PWD/
147 DIFFNAME=$PPID_${TIME}_`echo $DIR$1| sed s@_@__@ | sed 's@/@_@g'`.diff
148 tmp="/tmp/lm-saved-$$"
149 touch $1
150 cp -- "$1" $tmp 2> /dev/null
151 EDITOR.orig "$@" || ERR=1
152 diff $tmp $1 > $LMHOME/$DIFFNAME 2> /dev/null
153 rm $tmp 2> /dev/null
154 if [ "$ERR" = 1 ]
155 then
156 false
157 else
158 true
159 fi
160 else
161 exec EDITOR.orig "$@"
162 fi
163 editor_wrapper
165 }
168 uninstall_editor()
169 {
170 editor=$1
171 [ -e $editor.orig ] && mv $editor.orig $editor
172 }
174 if [ "$1" != "-d" ]
175 then
176 # INSTALLING LM
177 if [ $# -gt 0 ]
178 then
179 users_to_install="$*"
180 fi
182 if [ -z "$users_to_install" ]
183 then
184 show_usage
185 exit
186 fi
188 for home in $users_to_install
189 do
190 # fix this!
191 user=${home%/}
192 user=${user##*/}
193 mkdir -p $home/.lilalo
194 echo $first_lab > $home/.lilalo/lab
195 chown -R $user $home/.lilalo
197 #if [ ! -e $home/.bash_profile ]
198 #then
199 # echo '. ~/.bashrc' >> ~/.bash_profile
200 #fi
201 #[ -e $home/.bash_profile ] \
202 # && install_to_profile $home/.bash_profile \
203 # && echo LabMaker is installed to $home/.bash_profile
205 echo Don\'t forget to check .bash_profile for .bashrc call
207 [ -e $home/.bash_profile ] && install_to_profile $home/.bash_profile \
208 && install_to_profile $home/.bash_profile \
209 && echo LabMaker is installed to $home/.bash_profile
211 touch $home/.bashrc
212 [ -e $home/.bashrc ] && install_to_bashrc $home/.bashrc \
213 && install_to_bashrc $home/.bashrc \
214 && echo LabMaker is installed to $home/.bashrc
215 done
217 for editor in $editors_to_install
218 do
219 [ -e $editor ] \
220 && install_editor $editor \
221 && echo LabMaker is installed to $editor
222 done
223 else
224 # UNINSTALLING LM
225 shift
226 users_to_install="$*"
227 for user in $users_to_install
228 do
229 home=$user
230 mkdir -p $home/.lilalo
231 echo $first_lab > $home/.lilalo/lab
232 chown -R ${user##*/} $home/.lilalo
234 #if [ ! -e $home/.bash_profile ]
235 #then
236 # echo '. ~/.bashrc' >> ~/.bash_profile
237 #fi
238 #[ -e $home/.bash_profile ] \
239 # && uninstall_from_profile $home/.bash_profile \
240 # && echo LabMaker is uninstalled from $home/.bash_profile
242 [ -e $home/.profile ] && uninstall_from_profile $home/.profile \
243 && uninstall_from_profile $home/.profile \
244 && echo LabMaker is uninstalled from $home/.profile
246 touch $home/.bashrc
247 [ -e $home/.bashrc ] && uninstall_from_bashrc $home/.bashrc \
248 && uninstall_from_bashrc $home/.bashrc \
249 && echo LabMaker is uninstalled from $home/.bashrc
250 done
252 for editor in $editors_to_install
253 do
254 [ -e $editor ] \
255 && uninstall_editor $editor \
256 && echo LabMaker is uninstalled from $editor
257 done
258 fi