lilalo

view lm-install @ 16:37d701f903ec

Приглашение перенесено и поставлено перед if
author devi
date Thu Jun 16 11:44:38 2005 +0300 (2005-06-16)
parents 971931a71c9e
children 05d496f33d76
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;}'`
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]\$ '
88 if [ -n "$this_term" ] && echo $this_term | grep -qv script
89 then
90 exec script $flush -q $LMHOME/${TTY##*/}-$$.script
91 fi
92 # LabMaker:END
93 LM_bash_profile
94 cat $temp_file > $profile
95 rm $temp_file
96 }
98 uninstall_from_bashrc()
99 {
100 profile=$1
101 cat $profile \
102 | sed '/LabMaker:START/,/LabMaker:END/ d' \
103 > $temp_file
104 cat $temp_file > $profile
105 rm $temp_file
106 }
108 install_editor()
109 {
110 editor=$1
111 [ -e $editor.orig ] && cp $editor.orig $editor
112 cp $editor $editor.orig
113 cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor
114 #!/bin/sh
116 LMHOME=~/.labmaker
117 if [ "${1#-}" = "$1" -a -d "$LMHOME" ]
118 then
119 LAB=`cat $LMHOME/lab`
120 TIME="`date +%j${LAB}_%H:%M:%S`"
121 DIR=""
122 [ "${1#/}" = "$1" ] && DIR=$PWD/
123 DIFFNAME=$PPID_${TIME}_`echo $DIR$1| sed s@_@__@ | sed 's@/@_@g'`.diff
124 tmp="/tmp/lm-saved-$$"
125 touch $1
126 cp -- "$1" $tmp 2> /dev/null
127 EDITOR.orig "$@" || ERR=1
128 diff $tmp $1 > $LMHOME/$DIFFNAME 2> /dev/null
129 rm $tmp 2> /dev/null
130 if [ "$ERR" = 1 ]
131 then
132 false
133 else
134 true
135 fi
136 else
137 exec EDITOR.orig "$@"
138 fi
139 editor_wrapper
141 }
144 uninstall_editor()
145 {
146 editor=$1
147 [ -e $editor.orig ] && mv $editor.orig $editor
148 }
150 if [ "$1" != "-d" ]
151 then
152 # INSTALLING LM
153 if [ $# -gt 0 ]
154 then
155 users_to_install="$*"
156 fi
158 if [ -z "$users_to_install" ]
159 then
160 show_usage
161 exit
162 fi
164 for home in $users_to_install
165 do
166 # fix this!
167 user=${home%/}
168 user=${user##*/}
169 mkdir -p $home/.labmaker
170 echo $first_lab > $home/.labmaker/lab
171 chown -R $user $home/.labmaker
173 #if [ ! -e $home/.bash_profile ]
174 #then
175 # echo '. ~/.bashrc' >> ~/.bash_profile
176 #fi
177 #[ -e $home/.bash_profile ] \
178 # && install_to_profile $home/.bash_profile \
179 # && echo LabMaker is installed to $home/.bash_profile
181 echo Don\'t forget to check .bash_profile for .bashrc call
183 [ -e $home/.profile ] && install_to_profile $home/.profile \
184 && install_to_profile $home/.profile \
185 && echo LabMaker is installed to $home/.profile
187 touch $home/.bashrc
188 [ -e $home/.bashrc ] && install_to_bashrc $home/.bashrc \
189 && install_to_bashrc $home/.bashrc \
190 && echo LabMaker is installed to $home/.bashrc
191 done
193 for editor in $editors_to_install
194 do
195 [ -e $editor ] \
196 && install_editor $editor \
197 && echo LabMaker is installed to $editor
198 done
199 else
200 # UNINSTALLING LM
201 shift
202 users_to_install="$*"
203 for user in $users_to_install
204 do
205 home=$user
206 mkdir -p $home/.labmaker
207 echo $first_lab > $home/.labmaker/lab
208 chown -R ${user##*/} $home/.labmaker
210 #if [ ! -e $home/.bash_profile ]
211 #then
212 # echo '. ~/.bashrc' >> ~/.bash_profile
213 #fi
214 #[ -e $home/.bash_profile ] \
215 # && uninstall_from_profile $home/.bash_profile \
216 # && echo LabMaker is uninstalled from $home/.bash_profile
218 [ -e $home/.profile ] && uninstall_from_profile $home/.profile \
219 && uninstall_from_profile $home/.profile \
220 && echo LabMaker is uninstalled from $home/.profile
222 touch $home/.bashrc
223 [ -e $home/.bashrc ] && uninstall_from_bashrc $home/.bashrc \
224 && uninstall_from_bashrc $home/.bashrc \
225 && echo LabMaker is uninstalled from $home/.bashrc
226 done
228 for editor in $editors_to_install
229 do
230 [ -e $editor ] \
231 && uninstall_editor $editor \
232 && echo LabMaker is uninstalled from $editor
233 done
234 fi