lilalo
view lm-install @ 14:784c5382ffe2
Добавки в TODO
author | devi |
---|---|
date | Mon Jun 06 14:27:35 2005 +0300 (2005-06-06) |
parents | 35f394563dcb |
children | 37d701f903ec |
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 TTY=`tty`
74 this_term=`w | grep "${TTY##/dev/}" | awk '{print $8;}'`
75 # freeBSD:
76 this_term=`w | grep "${TTY##/dev/tty}" | awk '{print $6;}'`
77 if [ -n "$this_term" ] && echo $this_term | grep -qv script
78 then
79 LMHOME=~/.labmaker
80 mkdir -p ${LMHOME}
81 flush="-f" #linux
82 flush="-t 0" #freebsd
83 export PS1='\[` a="$?";
84 HIDDEN=$([ "$a" = 0 ] || echo -n ^"$a")$(echo -n _${UID}_)$(echo -n _$$_)$(date\
85 +"%j$(cat ~/.labmaker/lab 2>/dev/null) %H:%M:%S");
86 echo $HIDDEN`\033[50D\033[K\][\u@\h:\W]\$ '
87 exec script $flush -q $LMHOME/${TTY##*/}-$$.script
88 fi
89 # LabMaker:END
90 LM_bash_profile
91 cat $temp_file > $profile
92 rm $temp_file
93 }
95 uninstall_from_bashrc()
96 {
97 profile=$1
98 cat $profile \
99 | sed '/LabMaker:START/,/LabMaker:END/ d' \
100 > $temp_file
101 cat $temp_file > $profile
102 rm $temp_file
103 }
105 install_editor()
106 {
107 editor=$1
108 [ -e $editor.orig ] && cp $editor.orig $editor
109 cp $editor $editor.orig
110 cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor
111 #!/bin/sh
113 LMHOME=~/.labmaker
114 if [ "${1#-}" = "$1" -a -d "$LMHOME" ]
115 then
116 LAB=`cat $LMHOME/lab`
117 TIME="`date +%j${LAB}_%H:%M:%S`"
118 DIR=""
119 [ "${1#/}" = "$1" ] && DIR=$PWD/
120 DIFFNAME=$PPID_${TIME}_`echo $DIR$1| sed s@_@__@ | sed 's@/@_@g'`.diff
121 tmp="/tmp/lm-saved-$$"
122 touch $1
123 cp -- "$1" $tmp 2> /dev/null
124 EDITOR.orig "$@" || ERR=1
125 diff $tmp $1 > $LMHOME/$DIFFNAME 2> /dev/null
126 rm $tmp 2> /dev/null
127 if [ "$ERR" = 1 ]
128 then
129 false
130 else
131 true
132 fi
133 else
134 exec EDITOR.orig "$@"
135 fi
136 editor_wrapper
138 }
141 uninstall_editor()
142 {
143 editor=$1
144 [ -e $editor.orig ] && mv $editor.orig $editor
145 }
147 if [ "$1" != "-d" ]
148 then
149 # INSTALLING LM
150 if [ $# -gt 0 ]
151 then
152 users_to_install="$*"
153 fi
155 if [ -z "$users_to_install" ]
156 then
157 show_usage
158 exit
159 fi
161 for home in $users_to_install
162 do
163 # fix this!
164 user=${home%/}
165 user=${user##*/}
166 mkdir -p $home/.labmaker
167 echo $first_lab > $home/.labmaker/lab
168 chown -R $user $home/.labmaker
170 #if [ ! -e $home/.bash_profile ]
171 #then
172 # echo '. ~/.bashrc' >> ~/.bash_profile
173 #fi
174 #[ -e $home/.bash_profile ] \
175 # && install_to_profile $home/.bash_profile \
176 # && echo LabMaker is installed to $home/.bash_profile
178 echo Don\'t forget to check .bash_profile for .bashrc call
180 [ -e $home/.profile ] && install_to_profile $home/.profile \
181 && install_to_profile $home/.profile \
182 && echo LabMaker is installed to $home/.profile
184 touch $home/.bashrc
185 [ -e $home/.bashrc ] && install_to_bashrc $home/.bashrc \
186 && install_to_bashrc $home/.bashrc \
187 && echo LabMaker is installed to $home/.bashrc
188 done
190 for editor in $editors_to_install
191 do
192 [ -e $editor ] \
193 && install_editor $editor \
194 && echo LabMaker is installed to $editor
195 done
196 else
197 # UNINSTALLING LM
198 shift
199 users_to_install="$*"
200 for user in $users_to_install
201 do
202 home=$user
203 mkdir -p $home/.labmaker
204 echo $first_lab > $home/.labmaker/lab
205 chown -R ${user##*/} $home/.labmaker
207 #if [ ! -e $home/.bash_profile ]
208 #then
209 # echo '. ~/.bashrc' >> ~/.bash_profile
210 #fi
211 #[ -e $home/.bash_profile ] \
212 # && uninstall_from_profile $home/.bash_profile \
213 # && echo LabMaker is uninstalled from $home/.bash_profile
215 [ -e $home/.profile ] && uninstall_from_profile $home/.profile \
216 && uninstall_from_profile $home/.profile \
217 && echo LabMaker is uninstalled from $home/.profile
219 touch $home/.bashrc
220 [ -e $home/.bashrc ] && uninstall_from_bashrc $home/.bashrc \
221 && uninstall_from_bashrc $home/.bashrc \
222 && echo LabMaker is uninstalled from $home/.bashrc
223 done
225 for editor in $editors_to_install
226 do
227 [ -e $editor ] \
228 && uninstall_editor $editor \
229 && echo LabMaker is uninstalled from $editor
230 done
231 fi