lilalo
view lm-install @ 36:cb822611b240
Переставлены предложения в help'е
author | devi |
---|---|
date | Mon Nov 14 21:24:14 2005 +0200 (2005-11-14) |
parents | 4d252e7dd478 |
children | 466bea239d25 |
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 /usr/local/bin/l3-agent
44 # LabMaker:END
45 LM_bash_profile
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`
97 cat <<INFO > $LMHOME/${session_id}.info
98 <session>
99 <local_session_id>$session_id</local_session_id>
100 <hostname>$hostname</hostname>
101 <user>$USER</user>
102 <login_from>$login_from</login_from>
103 <tty>$tty</tty>
104 <system>$system</system>
105 <parent>$parent</parent>
106 <ppid>$PPID</ppid>
107 <pid>$$</pid>
108 <start_time>$start_time</start_time>
109 </session>
110 INFO
112 exec script $flush -q $LMHOME/${session_id}.script
113 fi
114 # LabMaker:END
115 LM_bash_profile
116 cat $temp_file > $profile
117 rm $temp_file
118 }
120 uninstall_from_bashrc()
121 {
122 profile=$1
123 cat $profile \
124 | sed '/LabMaker:START/,/LabMaker:END/ d' \
125 > $temp_file
126 cat $temp_file > $profile
127 rm $temp_file
128 }
130 install_editor()
131 {
132 editor=$1
133 [ -e $editor.orig ] && cp $editor.orig $editor
134 cp $editor $editor.orig
135 cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor
136 #!/bin/sh
138 LMHOME=~/.lilalo
139 if [ "${1#-}" = "$1" -a -d "$LMHOME" ]
140 then
141 LAB=`cat $LMHOME/lab`
142 TIME="`date +%j${LAB}_%H:%M:%S`"
143 DIR=""
144 [ "${1#/}" = "$1" ] && DIR=$PWD/
145 DIFFNAME=$PPID_${TIME}_`echo $DIR$1| sed s@_@__@ | sed 's@/@_@g'`.diff
146 tmp="/tmp/lm-saved-$$"
147 touch $1
148 cp -- "$1" $tmp 2> /dev/null
149 EDITOR.orig "$@" || ERR=1
150 diff $tmp $1 > $LMHOME/$DIFFNAME 2> /dev/null
151 rm $tmp 2> /dev/null
152 if [ "$ERR" = 1 ]
153 then
154 false
155 else
156 true
157 fi
158 else
159 exec EDITOR.orig "$@"
160 fi
161 editor_wrapper
163 }
166 uninstall_editor()
167 {
168 editor=$1
169 [ -e $editor.orig ] && mv $editor.orig $editor
170 }
172 if [ "$1" != "-d" ]
173 then
174 # INSTALLING LM
175 if [ $# -gt 0 ]
176 then
177 users_to_install="$*"
178 fi
180 if [ -z "$users_to_install" ]
181 then
182 show_usage
183 exit
184 fi
186 for home in $users_to_install
187 do
188 # fix this!
189 user=${home%/}
190 user=${user##*/}
191 mkdir -p $home/.lilalo
192 echo $first_lab > $home/.lilalo/lab
193 chown -R $user $home/.lilalo
195 #if [ ! -e $home/.bash_profile ]
196 #then
197 # echo '. ~/.bashrc' >> ~/.bash_profile
198 #fi
199 #[ -e $home/.bash_profile ] \
200 # && install_to_profile $home/.bash_profile \
201 # && echo LabMaker is installed to $home/.bash_profile
203 echo Don\'t forget to check .bash_profile for .bashrc call
205 [ -e $home/.bash_profile ] && install_to_profile $home/.bash_profile \
206 && install_to_profile $home/.bash_profile \
207 && echo LabMaker is installed to $home/.bash_profile
209 touch $home/.bashrc
210 [ -e $home/.bashrc ] && install_to_bashrc $home/.bashrc \
211 && install_to_bashrc $home/.bashrc \
212 && echo LabMaker is installed to $home/.bashrc
213 done
215 for editor in $editors_to_install
216 do
217 [ -e $editor ] \
218 && install_editor $editor \
219 && echo LabMaker is installed to $editor
220 done
221 else
222 # UNINSTALLING LM
223 shift
224 users_to_install="$*"
225 for user in $users_to_install
226 do
227 home=$user
228 mkdir -p $home/.lilalo
229 echo $first_lab > $home/.lilalo/lab
230 chown -R ${user##*/} $home/.lilalo
232 #if [ ! -e $home/.bash_profile ]
233 #then
234 # echo '. ~/.bashrc' >> ~/.bash_profile
235 #fi
236 #[ -e $home/.bash_profile ] \
237 # && uninstall_from_profile $home/.bash_profile \
238 # && echo LabMaker is uninstalled from $home/.bash_profile
240 [ -e $home/.profile ] && uninstall_from_profile $home/.profile \
241 && uninstall_from_profile $home/.profile \
242 && echo LabMaker is uninstalled from $home/.profile
244 touch $home/.bashrc
245 [ -e $home/.bashrc ] && uninstall_from_bashrc $home/.bashrc \
246 && uninstall_from_bashrc $home/.bashrc \
247 && echo LabMaker is uninstalled from $home/.bashrc
248 done
250 for editor in $editors_to_install
251 do
252 [ -e $editor ] \
253 && uninstall_editor $editor \
254 && echo LabMaker is uninstalled from $editor
255 done
256 fi