lilalo
view lm-install @ 54:f1ba68510fed
Обработка элемента ipaddress в элементе host
author | devi |
---|---|
date | Thu Dec 22 08:30:38 2005 +0200 (2005-12-22) |
parents | 466bea239d25 |
children | b7a217f8e963 |
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 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 <login_from>$login_from</login_from>
104 <tty>$tty</tty>
105 <system>$system</system>
106 <parent>$parent</parent>
107 <ppid>$PPID</ppid>
108 <pid>$$</pid>
109 <start_time>$start_time</start_time>
110 </session>
111 INFO
113 exec script $flush -q $LMHOME/${session_id}.script
114 fi
115 # LabMaker:END
116 LM_bash_profile
117 cat $temp_file > $profile
118 rm $temp_file
119 }
121 uninstall_from_bashrc()
122 {
123 profile=$1
124 cat $profile \
125 | sed '/LabMaker:START/,/LabMaker:END/ d' \
126 > $temp_file
127 cat $temp_file > $profile
128 rm $temp_file
129 }
131 install_editor()
132 {
133 editor=$1
134 [ -e $editor.orig ] && cp $editor.orig $editor
135 cp $editor $editor.orig
136 cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor
137 #!/bin/sh
139 LMHOME=~/.lilalo
140 if [ "${1#-}" = "$1" -a -d "$LMHOME" ]
141 then
142 LAB=`cat $LMHOME/lab`
143 TIME="`date +%j${LAB}_%H:%M:%S`"
144 DIR=""
145 [ "${1#/}" = "$1" ] && DIR=$PWD/
146 DIFFNAME=$PPID_${TIME}_`echo $DIR$1| sed s@_@__@ | sed 's@/@_@g'`.diff
147 tmp="/tmp/lm-saved-$$"
148 touch $1
149 cp -- "$1" $tmp 2> /dev/null
150 EDITOR.orig "$@" || ERR=1
151 diff $tmp $1 > $LMHOME/$DIFFNAME 2> /dev/null
152 rm $tmp 2> /dev/null
153 if [ "$ERR" = 1 ]
154 then
155 false
156 else
157 true
158 fi
159 else
160 exec EDITOR.orig "$@"
161 fi
162 editor_wrapper
164 }
167 uninstall_editor()
168 {
169 editor=$1
170 [ -e $editor.orig ] && mv $editor.orig $editor
171 }
173 if [ "$1" != "-d" ]
174 then
175 # INSTALLING LM
176 if [ $# -gt 0 ]
177 then
178 users_to_install="$*"
179 fi
181 if [ -z "$users_to_install" ]
182 then
183 show_usage
184 exit
185 fi
187 for home in $users_to_install
188 do
189 # fix this!
190 user=${home%/}
191 user=${user##*/}
192 mkdir -p $home/.lilalo
193 echo $first_lab > $home/.lilalo/lab
194 chown -R $user $home/.lilalo
196 #if [ ! -e $home/.bash_profile ]
197 #then
198 # echo '. ~/.bashrc' >> ~/.bash_profile
199 #fi
200 #[ -e $home/.bash_profile ] \
201 # && install_to_profile $home/.bash_profile \
202 # && echo LabMaker is installed to $home/.bash_profile
204 echo Don\'t forget to check .bash_profile for .bashrc call
206 [ -e $home/.bash_profile ] && install_to_profile $home/.bash_profile \
207 && install_to_profile $home/.bash_profile \
208 && echo LabMaker is installed to $home/.bash_profile
210 touch $home/.bashrc
211 [ -e $home/.bashrc ] && install_to_bashrc $home/.bashrc \
212 && install_to_bashrc $home/.bashrc \
213 && echo LabMaker is installed to $home/.bashrc
214 done
216 for editor in $editors_to_install
217 do
218 [ -e $editor ] \
219 && install_editor $editor \
220 && echo LabMaker is installed to $editor
221 done
222 else
223 # UNINSTALLING LM
224 shift
225 users_to_install="$*"
226 for user in $users_to_install
227 do
228 home=$user
229 mkdir -p $home/.lilalo
230 echo $first_lab > $home/.lilalo/lab
231 chown -R ${user##*/} $home/.lilalo
233 #if [ ! -e $home/.bash_profile ]
234 #then
235 # echo '. ~/.bashrc' >> ~/.bash_profile
236 #fi
237 #[ -e $home/.bash_profile ] \
238 # && uninstall_from_profile $home/.bash_profile \
239 # && echo LabMaker is uninstalled from $home/.bash_profile
241 [ -e $home/.profile ] && uninstall_from_profile $home/.profile \
242 && uninstall_from_profile $home/.profile \
243 && echo LabMaker is uninstalled from $home/.profile
245 touch $home/.bashrc
246 [ -e $home/.bashrc ] && uninstall_from_bashrc $home/.bashrc \
247 && uninstall_from_bashrc $home/.bashrc \
248 && echo LabMaker is uninstalled from $home/.bashrc
249 done
251 for editor in $editors_to_install
252 do
253 [ -e $editor ] \
254 && uninstall_editor $editor \
255 && echo LabMaker is uninstalled from $editor
256 done
257 fi