lilalo

view lm-install @ 2:787e9f11de51

Удалил файлы, которые случайно пролезли в репозиторий
author devi
date Sun May 22 16:31:54 2005 +0300 (2005-05-22)
parents
children 56e8b17b1823
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 exec script $flush -q $LMHOME/${TTY##*/}-$$.script
84 fi
85 PS1='\[` a="$?";
86 HIDDEN=$([ "$a" = 0 ] || echo -n ^"$a")$(echo -n _${UID}_)$(echo -n _$$_)$(date\
87 +"%j$(cat ~/.labmaker/lab 2>/dev/null) %H:%M:%S");
88 echo $HIDDEN`\033[50D\033[K\][\u@\h:\W]\$ '
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 user in $users_to_install
162 do
163 home=$user # fix this!
164 mkdir -p $home/.labmaker
165 echo $first_lab > $home/.labmaker/lab
166 chown -R ${user##*/} $home/.labmaker
168 if [ ! -e $home/.bash_profile ]
169 then
170 echo '. ~/.bashrc' >> ~/.bash_profile
171 fi
172 [ -e $home/.bash_profile ] \
173 && install_to_profile $home/.bash_profile \
174 && echo LabMaker is installed to $home/.bash_profile
176 [ -e $home/.profile ] && install_to_profile $home/.profile \
177 && install_to_profile $home/.profile \
178 && echo LabMaker is installed to $home/.profile
180 touch $home/.bashrc
181 [ -e $home/.bashrc ] && install_to_bashrc $home/.bashrc \
182 && install_to_bashrc $home/.bashrc \
183 && echo LabMaker is installed to $home/.bashrc
184 done
186 for editor in $editors_to_install
187 do
188 [ -e $editor ] \
189 && install_editor $editor \
190 && echo LabMaker is installed to $editor
191 done
192 else
193 # UNINSTALLING LM
194 shift
195 users_to_install="$*"
196 for user in $users_to_install
197 do
198 home=$user
199 mkdir -p $home/.labmaker
200 echo $first_lab > $home/.labmaker/lab
201 chown -R ${user##*/} $home/.labmaker
203 if [ ! -e $home/.bash_profile ]
204 then
205 echo '. ~/.bashrc' >> ~/.bash_profile
206 fi
207 [ -e $home/.bash_profile ] \
208 && uninstall_from_profile $home/.bash_profile \
209 && echo LabMaker is uninstalled from $home/.bash_profile
211 [ -e $home/.profile ] && uninstall_from_profile $home/.profile \
212 && uninstall_from_profile $home/.profile \
213 && echo LabMaker is uninstalled from $home/.profile
215 touch $home/.bashrc
216 [ -e $home/.bashrc ] && uninstall_from_bashrc $home/.bashrc \
217 && uninstall_from_bashrc $home/.bashrc \
218 && echo LabMaker is uninstalled from $home/.bashrc
219 done
221 for editor in $editors_to_install
222 do
223 [ -e $editor ] \
224 && uninstall_editor $editor \
225 && echo LabMaker is uninstalled from $editor
226 done
227 fi