lilalo

view lm-install @ 21:ab8d2a28fc86

Описан список атрибутов команды.

Хранение этих атрибутов должны быть
обеспечено в XML и SQL-форматах.
author devi
date Sat Oct 22 16:16:23 2005 +0300 (2005-10-22)
parents 37d701f903ec
children 098664cf339c
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 uname -a | grep -qi bsd && bsd=yes
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;}'`
82 LMHOME=~/.labmaker
83 mkdir -p ${LMHOME}
84 flush="-f" #linux
85 [ -n "$bsd" ] && flush="-t 0" #freebsd
86 export PS1='\[` a="$?";
87 HIDDEN=$([ "$a" = 0 ] || echo -n ^"$a")$(echo -n _${UID}_)$(echo -n _$$_)$(date\
88 +"%j$(cat ~/.labmaker/lab 2>/dev/null) %H:%M:%S");
89 echo $HIDDEN`\033[50D\033[K\][\u@\h:\W]\$ '
91 if [ -n "$this_term" ] && echo $this_term | grep -qv script
92 then
93 exec script $flush -q $LMHOME/${TTY##*/}-$$.script
94 fi
95 # LabMaker:END
96 LM_bash_profile
97 cat $temp_file > $profile
98 rm $temp_file
99 }
101 uninstall_from_bashrc()
102 {
103 profile=$1
104 cat $profile \
105 | sed '/LabMaker:START/,/LabMaker:END/ d' \
106 > $temp_file
107 cat $temp_file > $profile
108 rm $temp_file
109 }
111 install_editor()
112 {
113 editor=$1
114 [ -e $editor.orig ] && cp $editor.orig $editor
115 cp $editor $editor.orig
116 cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor
117 #!/bin/sh
119 LMHOME=~/.labmaker
120 if [ "${1#-}" = "$1" -a -d "$LMHOME" ]
121 then
122 LAB=`cat $LMHOME/lab`
123 TIME="`date +%j${LAB}_%H:%M:%S`"
124 DIR=""
125 [ "${1#/}" = "$1" ] && DIR=$PWD/
126 DIFFNAME=$PPID_${TIME}_`echo $DIR$1| sed s@_@__@ | sed 's@/@_@g'`.diff
127 tmp="/tmp/lm-saved-$$"
128 touch $1
129 cp -- "$1" $tmp 2> /dev/null
130 EDITOR.orig "$@" || ERR=1
131 diff $tmp $1 > $LMHOME/$DIFFNAME 2> /dev/null
132 rm $tmp 2> /dev/null
133 if [ "$ERR" = 1 ]
134 then
135 false
136 else
137 true
138 fi
139 else
140 exec EDITOR.orig "$@"
141 fi
142 editor_wrapper
144 }
147 uninstall_editor()
148 {
149 editor=$1
150 [ -e $editor.orig ] && mv $editor.orig $editor
151 }
153 if [ "$1" != "-d" ]
154 then
155 # INSTALLING LM
156 if [ $# -gt 0 ]
157 then
158 users_to_install="$*"
159 fi
161 if [ -z "$users_to_install" ]
162 then
163 show_usage
164 exit
165 fi
167 for home in $users_to_install
168 do
169 # fix this!
170 user=${home%/}
171 user=${user##*/}
172 mkdir -p $home/.labmaker
173 echo $first_lab > $home/.labmaker/lab
174 chown -R $user $home/.labmaker
176 #if [ ! -e $home/.bash_profile ]
177 #then
178 # echo '. ~/.bashrc' >> ~/.bash_profile
179 #fi
180 #[ -e $home/.bash_profile ] \
181 # && install_to_profile $home/.bash_profile \
182 # && echo LabMaker is installed to $home/.bash_profile
184 echo Don\'t forget to check .bash_profile for .bashrc call
186 [ -e $home/.profile ] && install_to_profile $home/.profile \
187 && install_to_profile $home/.profile \
188 && echo LabMaker is installed to $home/.profile
190 touch $home/.bashrc
191 [ -e $home/.bashrc ] && install_to_bashrc $home/.bashrc \
192 && install_to_bashrc $home/.bashrc \
193 && echo LabMaker is installed to $home/.bashrc
194 done
196 for editor in $editors_to_install
197 do
198 [ -e $editor ] \
199 && install_editor $editor \
200 && echo LabMaker is installed to $editor
201 done
202 else
203 # UNINSTALLING LM
204 shift
205 users_to_install="$*"
206 for user in $users_to_install
207 do
208 home=$user
209 mkdir -p $home/.labmaker
210 echo $first_lab > $home/.labmaker/lab
211 chown -R ${user##*/} $home/.labmaker
213 #if [ ! -e $home/.bash_profile ]
214 #then
215 # echo '. ~/.bashrc' >> ~/.bash_profile
216 #fi
217 #[ -e $home/.bash_profile ] \
218 # && uninstall_from_profile $home/.bash_profile \
219 # && echo LabMaker is uninstalled from $home/.bash_profile
221 [ -e $home/.profile ] && uninstall_from_profile $home/.profile \
222 && uninstall_from_profile $home/.profile \
223 && echo LabMaker is uninstalled from $home/.profile
225 touch $home/.bashrc
226 [ -e $home/.bashrc ] && uninstall_from_bashrc $home/.bashrc \
227 && uninstall_from_bashrc $home/.bashrc \
228 && echo LabMaker is uninstalled from $home/.bashrc
229 done
231 for editor in $editors_to_install
232 do
233 [ -e $editor ] \
234 && uninstall_editor $editor \
235 && echo LabMaker is uninstalled from $editor
236 done
237 fi