aboutsummaryrefslogtreecommitdiff
path: root/slackware-upgrade-system
blob: 89b2ccac444666f5a1b339caaf27a69f9e2f29c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/bin/sh

set -e

# Slackware root directory
rootdir=/root/slackware
# Log file name
logfile=
# 'y', if dry-run mode is requested
dry_run=
# If 'y', don't ask anything, assume "y" as answer to all quieries
assume_y=
# Output verbosity: '' - normal, 'v' - verbose, 'q' - quiet
verbosity=
# If 'y', install all packages
install_all=
# Names of the series that should be installed in addition to already installed
# packages.  Ignored, if install_all is set.
install_series=
# Name of the keep-list file.
keep_file=

function usage() {
    cat <<EOF
usage: $0 [-anqvy] [-d DIRECTORY] [-k FILE] [-s SERIES]
Upgrade Slackware installation

Options are:

  -a             install all series except kde*
  -d DIRECTORY   look for slackware distribution in DIRECTORY;
		 default is $rootdir
  -h             display this help list and exit
  -k FILE        preserve packages listed in FILE
  -n             dry-run mode: do nothing, print what would have been done
  -q             quiet mode: suppress all messages, except errors
  -s SERIES      additionally install all packages from SERIES;
		 incompatible with -a
  -v             display messages about individual packages
  -y             assume "yes" to all queries

EOF
}

function getyn() {
    if [ "$assume_y" = y ]; then
	/bin/true
    else
	local dfl=$1
	shift
	case "$dfl" in
	    [yY]) dfl_s=" [Y/n]";;
	    [nN]) dfl_s=" [y/N]";;
	    *)    dfl_s=""; dlf="";;
	esac

	printf "%s$dfl_s? " "$*"
	read REPLY </dev/tty
	case "${REPLY:-$dfl}" in
	    [yY]*)  /bin/true;;
	    *)	/bin/false;;
	esac
    fi
}

function upgrade_package() {
    if [ -n "$dry_run" ]; then
	echo "upgradepkg $@"
    elif [ "$verbosity" = 'v' ]; then
	upgradepkg "$@" | tee -a $logfile | sed -n -e '/^| Upgrading/s/^| //p'
    else
	upgradepkg "$@" >> $logfile
    fi
}

while getopts "ad:hknq:s:vy" OPTION
do
    case $OPTION in
	a) install_all=y;;
	d) rootdir=$OPTARG;;
	h) usage
	   exit 0;;
	k) keep_file=$OPTARG;;
	n) dry_run=y;;
	q) verbosity=q;;
	v) verbosity=v;;
	s) install_series="$install_series $OPTARG";;
	y) assume_y=y;;
	*) usage >&2
	   exit 1
    esac
done

shift $(($OPTIND - 1))
if [ $# -gt 0 ]; then
    echo >&2 "$0: unexpected arguments"
    usage >&2
    exit 1
fi

if [ $(id -u) != "0" ]; then
    echo >&2 "$0: must be root"
    exit 1
fi

# Sanity check
if [ ! -s /etc/os-release ]; then
    echo >&2 "$0: /etc/os-release doesn't exist"
    exit 1
fi

. /etc/os-release

if [ "$ID" != "slackware" ]; then
    echo >&2 "$0: this doesn't seem to be a Slackware installation"
    exit 1
fi

# Check if rootdir exists and contains the necessary files and directories
if [ ! -d $rootdir ]; then
    echo >&2 "$0: $rootdir does not exist"
    exit 1
fi

newversion=$(ls $rootdir/ANNOUNCE.* |\
	     sed -e 's|.*/||' -e 's/ANNOUNCE\.//' -e 's/_/./g')
if [ -z "$newversion" ]; then
    echo >&2 "$0: cannot determine new version"
    exit 1
fi

logfile=/var/log/slackware-upgrade-system-$VERSION-$newversion.log

# Check if pkgdir exists and contains the necessary files and directories
pkgdir=$rootdir/slackware64

if [ ! -d $pkgdir ]; then
    echo >&2 "$0: $pkgdir does not exist"
    exit 1
fi

tmplist=/tmp/$$
cat > $tmplist <<EOF
CHECKSUMS.md5
CHECKSUMS.md5.asc
FILE_LIST
MANIFEST.bz2
EOF

missing=$(find $pkgdir -depth -mindepth 1 -maxdepth 1 \
		       -type f -printf '%f\n' | \
	   sort | \
	   comm -1 -3 - $tmplist)
rm $tmplist
if [ -n "$missing" ]; then
    echo >&2 "$0: The following required files are missing in $pkgdir:"
    echo >&2 "$missing"
    exit 1
fi

cat > $tmplist <<EOF
a
ap
d
e
f
k
l
n
t
tcl
x
xap
xfce
y
EOF

missing=$(find $pkgdir -depth -mindepth 1 -maxdepth 1 \
		       -type d -printf '%f\n' | \
	   sort | \
	   comm -1 -3 - $tmplist)
rm $tmplist
if [ -n "$missing" ]; then
    echo >&2 "$0: The following required directories are missing in $pkgdir:"
    echo >&2 "$missing"
    exit 1
fi

# Prepare a list of packages that should be removed after install
installed_list=/tmp/installed.list.$$
avail_list=/tmp/avail.list.$$
candidates=
remove_list=/tmp/remove.list

ls /var/log/packages |\
 sed -r -e 's/-[^-]+-(i386|x86(_64)?|arm|noarch|fw)-[[:digit:]]+(_.*)?//' |\
 sort > $installed_list

find $pkgdir \
    -depth \
    -mindepth 2 -maxdepth 2 \
    -type f \
    -name '*.t?z' | \
 grep -v '/kde*/' | \
 sed -r \
     -e 's|.*/||' \
     -e 's/-[^-]+-(i386|x86(_64)?|arm|noarch|fw)-[[:digit:]]+((_.*)?\.t.z)?//' | \
 sort > $avail_list

comm -2 -3 $installed_list $avail_list > $remove_list.$$
if [ -s "$keep_file" ]; then
    grep -v '^#' $keep_file | \
	tr -s '\n' | sort | comm -2 -3 $remove_list.$$ - > $remove_list
    rm $remove_list.$$
else
    mv $remove_list.$$ $remove_list
fi

if [ -z "$install_all" ]; then
    candidates=$(comm -1 -2 $installed_list $avail_list)
fi
rm -f $installed_list $avail_list

# Disable interrupts during critical section
trap '' HUP INT QUIT ABRT

if [ -s $remove_list -a "$verbosity" != 'q' ]; then
    (cat <<EOF
INFO: The following packages will be removed.  You will have to manually
restore them after the upgrade.  The package names are preserved for you
in the file $remove_list:

EOF
cat $remove_list) | ${PAGER:-more}
fi

if ! getyn n "Ready for upgrade from $VERSION to $newversion. Continue"; then
    echo "Exiting"
    exit 0
fi

cd $pkgdir

# Upgrade the glibc shared libraries.
echo "$0: Upgrading shared libraries"
upgrade_package a/glibc-solibs-*.t?z

# Upgrade the package utilities and related tools.
echo "$0: Upgrading package utilities"
upgrade_package a/pkgtools-*.tgz
upgrade_package a/tar-*.tgz
upgrade_package a/xz-*.tgz
upgrade_package a/findutils-*.txz

if [ -n "$candidates" ]; then
    for name in $candidates
    do
	ls */$name*.t?z | \
	    sed -r -n "/$name"'-[^-]+-(i386|x86(_64)?|arm|noarch|fw)-[[:digit:]]+(_.*)?\.t.z$/p'
    done | \
    sort | \
    while read pkg
    do
	s=$(basename ${pkg%/*})
	if [ "$prev" != "$s" ]; then
	    echo "$0: installing selected files from series $s"
	    prev=$s
	fi
	upgrade_package --install-new $pkg
    done
    for s in $install_series
    do
	if [ -d $s ]; then
	    echo "$0: installing additional series $s"
	    upgrade_package --install-new $s/*.t?z
	else
	    echo >&2 "$0: no such series: $s"
	fi
    done
else
    find . -depth -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort |
    while read dir
    do
	case $dir in
	kde*) ;;
	*)    echo "$0: installing packages from series $dir"
	      upgrade_package --install-new $dir/*.t?z
	      ;;
	esac
    done
fi

if [ -s $remove_list ]; then
    echo "$0: removing packages"
    if [ -n "$dry_run" ]; then
	:
    elif [ "$verbosity" = 'v' ]; then
	removepkg $(cat $remove_list) | tee -a $logfile | grep '^Removing package'
    else
	removepkg $(cat $remove_list) >> $logfile
    fi
    echo "$0: see $remove_list for the list of packages that have been removed"
fi

echo "$0: upgrade finished; see $logfile for details"

conffiles=/var/log/slackware-upgrade-system-$VERSION-$newversion.conffiles
find /etc /usr/lib*/ /usr/share/vim -name "*.new" 2>/dev/null | \
    sort > $conffiles
if [ ! -s "$conffiles" ]; then
    rm $conffiles
fi

if [ "$verbosity" != 'q' ]; then
    echo "IMPORTANT!"
    if [ -s "$conffiles" ]; then
	cat <<EOF
Some of your config files may need fixing.  Please check the files from this
list and compare them with their counterparts without the ".new" suffix.
Remove the "*.new" files when finished.  The list of files follows:

EOF
	cat $conffiles
	cat <<EOF

For your convenience, this list is preserved in the file $conffiles.

EOF
    fi
    cat <<EOF
*Before* attempting to reboot your system, please make sure that the
bootloader has been updated for the new kernel!

Good luck!
EOF
fi

Return to:

Send suggestions and report system problems to the System administrator.