source: projects/vutils/trunk/vupgrade @ 4197

Revision 4197, 6.8 KB checked in by daisuke, 11 years ago (diff)

fix vupgrade bug

Line 
1#!/bin/bash
2# script to upgrade user files to adapt the newest version of the Vine Linux
3# by Jun Nishii <jun@vinelinux.org>
4
5VER=6.0
6LOG=$HOME/upgrade-log
7STAMP=${HOME}/.vine/VineLinux${VER}
8
9chkAndCpFile(){
10if [ ! -f $1 ] ;then
11   install -m 644 /etc/skel/$1 ${HOME}
12   echo "added new config file $1" >> ${LOG}
13fi
14}
15
16chkAndCpDir(){
17if [ ! -d $1 ]; then
18   cp -r /etc/skel/$1 ${HOME}
19   echo "added new config directory $1" >> ${LOG}
20fi
21}
22
23Update(){ # checkstr, oldstr, newstr, target
24if [ -f $4 ]; then
25   TEST=`grep "$1" $4 2>/dev/null`
26   if [ -n "${TEST}" ]; then
27      echo "replace $2 as $3 in $4" >> ${LOG}
28      cp $4 $4.new
29      sed -e 's|'"$2"'|'"$3"'|' $4.new > $4
30      rm $4.new
31      return 0
32   fi
33fi
34return 1
35}
36
37chkSame(){ # target newguy
38if diff $1 $2 >/dev/null 2>&1; then
39    return 0
40else
41    return 1
42fi
43}
44
45chkMD5Update(){ # target md5sum newguy
46[ ! -f $1 ] && return 1
47
48CHECK=`md5sum $1 | cut -f 1 -d " "`
49if [ "${CHECK}" = "$2" ]; then
50    cp $3 ${HOME}
51    echo "$1 was replaced to new one for Vine Linux ${VER}" >>${LOG}
52    return 0
53else
54    return 1
55fi
56}
57
58chkMD5Remove(){ # target md5sum
59[ ! -f $1 ] && return 1
60
61CHECK=`md5sum $1 | cut -f 1 -d " "`
62if [ "${CHECK}" = "$2" ]; then
63    mv $1 $1.rpmsave
64    echo "$1 was removed(backup as .rpmsave) for Vine Linux ${VER}" >>${LOG}
65    return 0
66else
67    return 1
68fi
69}
70
71###########################################################################3
72
73#[ -f ${LOG} ] && rm ${LOG}
74[ -f ${STAMP} ] && return 0
75
76###########################################################################3
77
78##### Xresources
79TARGET=${HOME}/.Xresources
80NEW=/etc/skel/.Xresources
81chkSame $TARGET $NEW || (
82# from 5.x
83MD5SUM="663f4824d786af718954f301af301c84"
84chkMD5Update $TARGET $MD5SUM $NEW
85# from 4.0 4.1 4.2
86MD5SUM="d5651f30e2e4fabbaafe3aee60f6bda2"
87chkMD5Update $TARGET $MD5SUM $NEW
88# from 3.x
89MD5SUM="3347c5d3eb5cbb90255b3dc46bd25728"
90chkMD5Update $TARGET $MD5SUM $NEW
91# from 2.6
92MD5SUM="2ba8631e24045a2d76603b91a4aed6c0"
93chkMD5Update $TARGET $MD5SUM $NEW
94# from 2.6CR
95MD5SUM="6958944eb43282ef3cb5f09f0323296f"
96chkMD5Update $TARGET $MD5SUM $NEW
97)
98
99##### bash_logout
100TARGET=${HOME}/.bash_logout
101NEW=/etc/skel/.bash_logout
102chkSame $TARGET $NEW || (
103# from 2.5, 2.6, 3.x, 4.x, 5.x
104MD5SUM="d19bbbed9d713f97f487b9ed9ec3f62f"
105chkMD5Update $TARGET $MD5SUM $NEW
106)
107
108##### bash_profile
109TARGET=${HOME}/.bash_profile
110NEW=/etc/skel/.bash_profile
111chkSame $TARGET $NEW || (
112# from 2.5, 2.6, 3.x, 4.x, 5.x
113MD5SUM="68fa45c9d56046c8f6ce3c3ea2e8376b"
114chkMD5Update $TARGET $MD5SUM $NEW
115# from 2.1.5 and before
116MD5SUM="7feed2b53dad06634b2bc32d63f634e4"
117chkMD5Update $TARGET $MD5SUM $NEW
118)
119
120##### bashrc
121TARGET=${HOME}/.bashrc
122NEW=/etc/skel/.bashrc
123chkSame $TARGET $NEW || (
124# from 3.x & 4.x, 5.x
125MD5SUM="6d43294e457bb568957d2fb2b43b0355"
126chkMD5Update $TARGET $MD5SUM $NEW
127# from 2.5 & 2.6
128MD5SUM="e31a08d3af08bed5e4f246a3dacc36d8"
129chkMD5Update $TARGET $MD5SUM $NEW
130# from 2.1 & 2.1.5
131MD5SUM="6ad96798a72f420d409095ca0ed538f1"
132chkMD5Update $TARGET $MD5SUM $NEW
133# from 2.0
134MD5SUM="a1d1b54732257d96b9219af0c7f1fc7a"
135chkMD5Update $TARGET $MD5SUM $NEW
136)
137
138##### cshrc
139TARGET=${HOME}/.cshrc
140NEW=/etc/skel/.cshrc
141chkSame $TARGET $NEW || (
142# from 2.6 & 3.x & 4.x, 5.x
143MD5SUM="d72dab0210938146b5c4ffe01d874e3a"
144chkMD5Update $TARGET $MD5SUM $NEW
145# from 2.1 & 2.1.5
146MD5SUM="9ccfb8703e6ae18b627b46aeb84a05b1"
147chkMD5Update $TARGET $MD5SUM $NEW
148# from 2.0
149MD5SUM="e353c9ee3971539acdfb4a8769f34c66"
150chkMD5Update $TARGET $MD5SUM $NEW
151)
152
153################################
154##### removed since Vine Linux 6
155##### emacs
156TARGET=${HOME}/.emacs
157# from 5.x
158MD5SUM="e09878a9eb8bf120e97d8684cb1d7b3a"
159# from 2.6 & 3.x & 4.0, 4.1
160MD5SUM+=" 3c866b2dafd2a7ba7ea2b41faf24f523"
161# from 2.1 & 2.1.5 & 2.5
162MD5SUM+=" 289ba7d687f770983b143ea0e424c722"
163for i in $MD5SUM ; do
164  chkMD5Remove $TARGET $i
165done
166
167################################
168##### removed since Vine Linux 6
169##### .emacs.el
170TARGET=${HOME}/.emacs.el
171MD5SUM="bd4f9e933abc2db52c02715d71fe6c94"
172# from 4.1+
173MD5SUM+=" c2876e464b4e2572fcfa1e95ec111a6c"
174# from 4.1
175MD5SUM+=" 6305d80793bd17761e9b054d1c71094e"
176# from 4.0
177MD5SUM+=" 233bd3d3636ac04d7ec1223280f01ce1"
178# from 3.2
179MD5SUM+=" cc1a41f2dbc775fccfa0d07cbfe48b8b"
180# from 3.1
181MD5SUM+=" d2b98e579143983a39a6639120e8579a"
182# from 3.0
183MD5SUM+=" a0bbf086255f0751583520e7fd47326c"
184# from 2.6
185MD5SUM+=" 76785a2498f22f430583cbd649d8cfc3"
186# from 2.6CR
187MD5SUM+=" 00ae4ed293d418a43f6018941173ff7a"
188# from 2.5
189MD5SUM+=" 6718c077a33f729c0f3340ff362d53f6"
190# from 2.1 & 2.1.5
191MD5SUM+=" e5d037ca2ea00619dc72ad5c59baca3a"
192# from 2.0
193MD5SUM+=" ecb3dec80763a8fdb0888d8980c49286"
194for i in $MD5SUM ; do
195  chkMD5Remove $TARGET $i
196done
197
198### rpmmacros
199TARGET=${HOME}/.rpmmacros
200NEW=/etc/skel/.rpmmacros
201chkSame $TARGET $NEW || (
202# from 5.x
203MD5SUM="375fcff760b2121d13982b929af16a6c"
204chkMD5Update $TARGET $MD5SUM $NEW
205# from 4.x
206MD5SUM="aeffd267d61af5ca4718cee9bb2cb2de"
207chkMD5Update $TARGET $MD5SUM $NEW
208# from 3.x
209MD5SUM="ba738a926ffb0e5752ef440ba915634d"
210chkMD5Update $TARGET $MD5SUM $NEW
211# from 2.6
212# MD5SUM="ba738a926ffb0e5752ef440ba915634d"
213# chkMD5Update $TARGET $MD5SUM $NEW
214# from 2.1.5
215# MD5SUM="ba738a926ffb0e5752ef440ba915634d"
216# chkMD5Update $TARGET $MD5SUM $NEW
217# from 2.1
218MD5SUM="2b2a0f4e2d7ec077db33f031f66cac9c"
219chkMD5Update $TARGET $MD5SUM $NEW
220)
221
222################################
223##### removed since Vine Linux 6
224##### xemacs.el
225TARGET=${HOME}/.xemacs.el
226# from 5.x
227MD5SUM="8c521ded7399113a2acc44cd7d15c6f7"
228# from 4.0
229MD5SUM+=" 05c1705daa7769a65efa6045206c574b"
230# from 3.x
231MD5SUM+=" 4b459e779adb38fabb461a27d0cfa76e"
232# from 2.6
233MD5SUM+=" a48ed6df7d52422455713a1d61b69d64"
234# from 2.6
235MD5SUM+=" 4764be822a419a7f620fc082ced8d6ac"
236# from 2.1 & 2.1.5
237MD5SUM+=" ea9b58406676c6f586cb80e63d37bffe"
238# from 2.0
239MD5SUM+=" 81982a524f9ab581a017dbfaa77f2d34"
240for i in $MD5SUM ; do
241  chkMD5Remove $TARGET $i
242done
243
244##### xemacs.el
245TARGET=${HOME}/.xemacs/init.el
246#from 5.x
247MD5SUM="0f65ac976270dddd236f437ca46782f9"
248# from 4.1+
249MD5SUM+=" a19da2801c7287a89f92e63f9ba335cd"
250# from 4.1
251MD5SUM+=" 42554ea7b5738e5519e4b22b5dab5a73"
252for i in $MD5SUM ; do
253  chkMD5Remove $TARGET $i
254done
255
256# imelib -> vinelib (from 2.0)
257TARGET=${HOME}/.bashrc
258Update "imelib" \
259        "imelib" \
260        "vinelib" \
261       $TARGET && (
262       echo "Your ~/.bashrc seems to be old." >> ${LOG}
263       echo "Please compare it with /etc/skel/.bashrc and update it!" >> ${LOG}
264)
265
266# CANNA_SEVER=localhost -> unix (Vine Linux 3.0)
267if [ -f ${HOME}/.vine/system/ime ]; then
268    if (grep -q "CANNA_SERVER=localhost" ${HOME}/.vine/system/ime) ; then
269        cp -f ${HOME}/.vine/system/ime ${HOME}/.vine/system/ime.vinesave
270        sed "s/CANNA_SERVER=localhost/CANNA_SERVER=unix/" ${HOME}/.vine/system/ime.vinesave > ${HOME}/.vine/system/ime
271        echo "upgraded ~/.vine/system/ime to use unix domain socket for Canna." >> ${LOG}
272    fi
273fi
274
275# new files (Vine Linux 2.1)
276chkAndCpFile .rpmmacros
277chkAndCpDir rpm
278
279# new files (Vine Linux 6)
280chkAndCpDir .emacs.d
281
282####################
283touch ${STAMP}
284####################
285unset TARGET NEW MD5SUM VER LOG STAMP
286
Note: See TracBrowser for help on using the repository browser.