-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdistrorejuve.sh
2959 lines (2637 loc) · 143 KB
/
distrorejuve.sh
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# https://superuser.com/questions/1456989/how-to-configure-apt-in-debian-buster-after-release buster InRelease' changed its 'Version' value from '' to '10.0' Run 'apt list --upgradable' to see them. apt-get update --allow-releaseinfo-change
# https://www.debian.org/releases/bookworm/amd64/release-notes/ch-upgrading.html
# https://wiki.ubuntu.com/Releases
# when updating, keep them in their release order to safety
# no leading/trailing spaces. one space per word.
LTS_UBUNTU="dapper hardy lucid precise trusty xenial bionic focal jammy noble"
#ARCHIVE_REPO_UBUNTU="precise trusty vivid wily xenial yakkety"
# https://old-releases.ubuntu.com/releases/
OLD_RELEASES_UBUNTU="warty hoary breezy dapper edgy feisty gutsy hardy intrepid jaunty karmic maverick natty oneiric quantal raring saucy lucid utopic vivid wily yakkety zesty artful cosmic disco eoan groovy hirsute impish kinetic lunar"
ALL_UBUNTU="warty hoary breezy dapper edgy feisty gutsy hardy intrepid jaunty karmic lucid maverick natty oneiric precise quantal raring saucy trusty utopic vivid wily xenial yakkety zesty artful bionic cosmic disco eoan focal groovy hirsute impish jammy kinetic lunar mantic noble oracular"
NON_LTS_UBUNTU=$(for i in $ALL_UBUNTU; do echo $LTS_UBUNTU | grep -qai "$i" || echo -n "$i "; done; echo)
ALL_DEBIAN="hamm slink potato woody sarge etch lenny squeeze wheezy jessie stretch buster bullseye bookworm"
# in egrep code be aware of etch/stretch matching
# https://wiki.debian.org/LTS
UNSUPPORTED_DEBIAN="hamm slink potato woody sarge etch lenny squeeze wheezy jessie stretch buster"
# no archive for wheezy (update 2020-03, there is now)
#DEBIAN_ARCHIVE="$(echo "$UNSUPPORTED_DEBIAN squeeze-lts" | sed 's/wheezy//')"
DEBIAN_ARCHIVE="$(echo "$UNSUPPORTED_DEBIAN squeeze-lts" )"
# wheezy to 31 May 2018, jessie to April 2020, stretch to June 2022
DEBIAN_CURRENT="bullseye bookworm"
IS_DEBUG=
# also DEBIAN_FRONTEND=noninteractive ?
export DEBIAN_FRONTEND=noninteractive
export APT_LISTCHANGES_FRONTEND=none
APT_GET_INSTALL_OPTIONS=' -y -o DPkg::Lock::Timeout=-1 -o APT::Get::AllowUnauthenticated=yes -o Acquire::Check-Valid-Until=false -o Dpkg::Options::=--force-confnew -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confmiss '
# export this variable, e.g. to DAYS_UPGRADE_ONGOING=7 if your upgrade is taking more than a day, and you want the diffs in configs/processes to report the difference between the current and much earlier state.
DAYS_UPGRADE_ONGOING="${DAYS_UPGRADE_ONGOING:-7}"
function print_usage() {
echo "
# distrorejuve
distrorejuve is a utility that helps with upgrading distros. It works on a number of different distros (Ubuntu,
Debian, Centos). It uses apt, yum and repository corrections as appropriate. It can dist upgrade between
multiple versions for Ubuntu and Debian. It can convert (some) distros from 32bit to 64 bit (a cross grade).
If you are using the script to make changes, please take a full backup first.
Example usage to download the latest version of the script, then dist upgrade to latest Debian or Ubuntu disto.
wget -O distrorejuve.sh --no-check-certificate https://raw.githubusercontent.com/pbkwee/distrorejuve/master/distrorejuve.sh
sudo nohup bash -x distrorejuve.sh --dist-upgrade 2>&1 | tee -a distrorejuve.log | egrep -v '^\+'
Uses:
- Enable lts archive for Debian squeeze servers and old-releases for Ubuntu
- Dist upgrade Ubuntu distros to the next LTS version. Then from LTS version to LTS version.
- On completion provides information on config changes (modified config files, changed ports, changed packages, changed running processes)
- Install missing Debian keys
- Handles a few common Apache config issues after a distro upgrade.
- Designed to run unattended without lots of prompting.
- Burgeoning support to cross grade 32 bit distros to 64 bit
- Show/remove cruft to permit tidy up of packages installed from non-current (old) repositories
Arguments:
Run with --usage to get this message
Run with --check (or no argument) makes no changes. Reports information like disk space free, kernel, distro version, config files modified from package defaults.
Run with --dist-upgrade run an upgrade, followed by dist-upgrading ubuntu distros to the latest lts or debian distros to latest debian.
Run with --upgrade to run a yum upgrade or apt-get upgrade (fixing up repos, etc where we can). no distro version change.
Run with --dist-update to update packages on the current distro version (no distro version change).
Run with --show-changes to report the differences pre/post upgrading (packages installed, config files, ports, etc).
Run with --show-cruft to see packages that do not belong to the current distro. e.g. leftover packages from older distros. And to see 32 bit packages installed on 64 bit distros.
Run with --remove-cruft to remove old packages and 32 bit applications on 64 bit distros.
Run with --remove-deprecated-packages to remove old packages
Run with --to-64bit to convert a 32 bit distro to 64 bit. Works OK with Debian. May work for Ubuntu < 18.04.
Run with --to-wheezy to get from squeeze to wheezy
Run with --to-jessie to get from an older distro to jessie
Run with --to-latest-debian to get from an older debian distro to the latest stable distro
Run with --to-debian-release [6-12] to get from your current version to the specified version
Run with --to-latest-lts to get from an ubuntu distro to the most recent ubuntu lts version
Run with --to-next-ubuntu to get from an ubuntu distro to the next ubuntu version. If the current ubuntu is an LTS version then this skips to the next LTS version.
Run with --fix-vuln to try and fix your server (doing minimal change e.g. just an apt-get install of the affected package).
Run with --break-eggs will run a --dist-upgrade if the server is vulnerable.
Run with --pause to pause a distro rejuve running process (touch ~/distrorejuve.pause). Triggers 30s sleeps at key points in the script.
Run with --resume to resume a paused distro rejuve running process (rm -f ~/distrorejuve.pause)
Use with --source if you just wish to have the distrorejuve functions available to you for testing
Written by Peter Bryant at http://launchtimevps.com
Latest version (or thereabouts) will be available at https://github.com/pbkwee/distrorejuve
"
}
# for debian or ubuntu names. e.g. is_distro_name_newer jessie buster => 1 ; buster buster => 1; jessie buster =>0
function is_distro_name_newer() {
local name="$1"
local newerthan="$2"
local t=
local is_name_found=N
local is_newer_found=N
for t in $ALL_DEBIAN $ALL_UBUNTU; do
[ "$t" == "$name" ] && is_name_found=Y
[ "$is_name_found" == "Y" ] && [ "$is_newer_found" == "Y" ] && return 0
[ "$is_name_found" == "Y" ] && return 1
[ "$t" == "$newerthan" ] && is_newer_found=Y
done
return 1
}
# for debian or ubuntu names. e.g. is_distro_name_newer jessie buster => 1 ; buster buster => 1; jessie buster =>0
function is_distro_name_older() {
local name="$1"
local olderthan="$2"
local t=
local is_name_found=N
local is_older_found=N
for t in $ALL_DEBIAN $ALL_UBUNTU; do
[ "$t" == "$name" ] && is_name_found=Y
[ "$t" == "$olderthan" ] && is_older_found=Y
[ "$is_name_found" == "Y" ] && [ "$is_older_found" == "Y" ] && return 1
[ "$is_name_found" == "Y" ] && return 0
done
return 1
}
function pause_check() {
while true; do
[ ! -f ~/distrorejuve.pause ] && return
echo "dss:info: pausing while ~/distrorejuve.pause is present. When ready, run: $0 --resume to continue."
sleep 30
done
}
function is_fixed() {
# 0 = vulnerable, 1 = fixed, 2 = dunno
is_CVE_2015_0235_vulnerable
ret=$?
if [ $ret -eq 1 ]; then
is_CVE_2015_7547_vulnerable
ret=$?
if [ $ret -eq 1 ]; then
# return 0 if both vulns are fixed
return 0
fi
fi
return 1
}
# e.g. wordlisttoegrep "a b c" => "a|b|c"
function wordlisttoegreparg() {
echo $1 | sed 's/ / /g' | sed 's/ *$//g' | sed 's/ /|/g'
}
function replace() {
which replace &>/dev/null >/dev/null
if [ $? -eq 0 ]; then
# the double quotes are needed else you get:
# /usr/local/mysql/bin/replace 1 2 3 e f g -- b
# instead of:
# /usr/local/mysql/bin/replace '1 2 3' 'e f g' -- b
$(which replace) "$@"
return $?
fi
local from=$1
local to=$2
local dash=$3
local file=$4
if [ "$dash" != "--" ]; then
echo "expecting '--'" >&2
return 1
fi
[ ! -f "$file" ] && echo "No such file as $file" >&2 && return 1
sed -i "s@$from@$to@" "$file"
}
function is_vulnerable() {
is_CVE_2015_0235_vulnerable && return 0
is_CVE_2015_7547_vulnerable && return 0
return 1
}
function prep_ghost_output_dir() {
if [ ! -d /root/distrorejuveinfo ] ; then echo "dss:info: Creating /root/distrorejuveinfo."; mkdir /root/distrorejuveinfo; fi
return 0
}
function print_libc_versions() {
# Checking current glibc version
local prefix=${1:-prefix}
[ -x /usr/bin/ldd ] && /usr/bin/ldd --version | grep -i libc | awk '{print "dss:lddver:'$prefix':" $0}'
[ -x /usr/bin/dpkg ] && /usr/bin/dpkg -l libc6 | grep libc6 | awk '{print "dss:dpkg:'$prefix':" $0}'
[ -x /bin/rpm ] && /bin/rpm -qa glibc | awk '{print "dss:rpmqa:'$prefix':" $0}'
return 0
}
function is_CVE_2015_0235_vulnerable() {
print_CVE_2015_0235_vulnerable > /dev/null
return $?
}
function is_CVE_2015_7547_vulnerable() {
print_CVE_2015_7547_vulnerable > /dev/null
return $?
}
# 0 = vulnerable, 1 = fixed, 2 = dunno
function print_CVE_2015_0235_vulnerable() {
# fixed for that, fixed for all.
print_CVE_2015_7547_vulnerable > /dev/null
if [ $? -eq 1 ]; then
echo "N"
return 1
fi
# based on some known good package versions https://security-tracker.debian.org/tracker/CVE-2015-0235
# http://people.canonical.com/~ubuntu-security/cve/2015/CVE-2015-0235.html
if [ ! -x /usr/rpm ] && [ -x /usr/bin/dpkg ]; then
if dpkg -l | grep libc6 | egrep -qai '2\.19-13|2\.19-15|2\.13-38\+deb7u7|2\.11\.3-4\+deb6u4|2\.11\.1-0ubuntu7.20|2\.15-0ubuntu10.10|2\.19-10ubuntu2|2\.19-0ubuntu6'; then
echo "N"
return 1
fi
if dpkg -l | grep libc6 | egrep -qai '2\.11\.3-4|2\.13-38\+deb7u6|2\.7-18lenny7'; then
echo "Y"
return 0
fi
# some more that are probably also old/vuln
if dpkg -l | grep libc6 | egrep -qai '2\.4-1ubuntu12\.3|2\.10\.1-0ubuntu19|2\.10\.2-1|2\.11\.1-0ubuntu7|2\.11\.2-5|2\.13-38|2\.2\.5-11\.5|2\.2\.5-11\.8|2\.3\.2\.ds1-22|2\.3\.2\.ds1-22sa|2\.3\.6\.ds1-13|2\.3\.6\.ds1-13et|2\.3\.6\.ds1-13etch10|2\.3\.6\.ds1-13etch10\+b1|2\.3\.6\.ds1-13etch2|2\.3\.6\.ds1-13etch8|2\.3\.6\.ds1-13etch9\+b1|2\.3\.6\.ds1-8|2\.5-0ubuntu14|2\.6\.1-1ubuntu10|2\.7-10ubuntu4|2\.7-10ubuntu8\.3|2\.7-18|2\.7-18lenny2|2\.7-18lenny4|2\.8~20080505-0ubuntu9|2\.9-4ubuntu6\.3'; then
echo "Y"
return 0
fi
echo "?"
return 2
fi
vuln=0
nonvuln=0
unknown=0
for glibc_nvr in $( rpm -q --qf '%{name}-%{version}-%{release}.%{arch}\n' glibc ); do
glibc_ver=$( echo "$glibc_nvr" | awk -F- '{ print $2 }' )
glibc_maj=$( echo "$glibc_ver" | awk -F. '{ print $1 }')
glibc_min=$( echo "$glibc_ver" | awk -F. '{ print $2 }')
if [ -z "$glibc_maj" ] || [ -z "$glibc_maj" ] || [ -z "$glibc_min" ]; then
unknown=$(($unknown+1))
continue
fi
#echo -n "- $glibc_nvr: "
if [ "$glibc_maj" -gt 2 -o \
\( "$glibc_maj" -eq 2 -a "$glibc_min" -ge 18 \) ]; then
# fixed upstream version
# echo 'not vulnerable'
nonvuln=$(($nonvuln+1))
else
# all RHEL updates include CVE in rpm %changelog
if rpm -q --changelog "$glibc_nvr" | grep -q 'CVE-2015-0235'; then
#echo "not vulnerable"
nonvuln=$(($nonvuln+1))
else
#echo "vulnerable"
vuln=$(($vuln+1))
fi
fi
done
if [ $vuln -gt 0 ] ; then echo "Y"; return 0; fi
if [ $unknown -gt 0 ]; then echo "?"; return 2; fi
if [ $nonvuln -gt 0 ] ; then echo "N"; return 1; fi
echo "?"
return 2
}
# 0 = vulnerable, 1 = fixed, 2 = dunno
function print_CVE_2015_7547_vulnerable() {
if [ ! -x /usr/rpm -a -x /usr/bin/dpkg ]; then
# based on some known good package versions https://security-tracker.debian.org/tracker/CVE-2015-7547
if dpkg -l | grep libc6 | grep '^i' | egrep -qai '2\.11\.3-4\+deb6u11|2\.13-38\+deb7u10|2\.19-18\+deb8u3|2\.21-8|2\.21-9'; then
echo "N"
return 1
fi
# http://people.canonical.com/~ubuntu-security/cve/2015/CVE-2015-7547.html
if dpkg -l | grep libc6 | grep '^i' | egrep -qai '2\.15-0ubuntu10\.13|2\.19-0ubuntu6\.7|2\.21-0ubuntu4\.0\.1|2\.21-0ubuntu4\.1'; then
echo "N"
return 1
fi
#the issue affected all the versions of glibc since 2.9 e.g. to match 2.3.6.ds1-13etch10+b1 or 2.6-blah
if dpkg -l | grep libc6 | grep '^i' | egrep -qai '2\.[1-8][-.]'; then
echo "N"
return 1
fi
# some more that are probably also old/vuln
if dpkg -l | grep libc6 | egrep -qai '2\.4-1ubuntu12\.3|2\.10\.1-0ubuntu19|2\.10\.2-1|2\.11\.1-0ubuntu7|2\.11\.2-5|2\.13-38|2\.2\.5-11\.5|2\.2\.5-11\.8|2\.3\.2\.ds1-22|2\.3\.2\.ds1-22sa|2\.3\.6\.ds1-13|2\.3\.6\.ds1-13et|2\.3\.6\.ds1-13etch10|2\.3\.6\.ds1-13etch10\+b1|2\.3\.6\.ds1-13etch2|2\.3\.6\.ds1-13etch8|2\.3\.6\.ds1-13etch9\+b1|2\.3\.6\.ds1-8|2\.5-0ubuntu14|2\.6\.1-1ubuntu10|2\.7-10ubuntu4|2\.7-10ubuntu8\.3|2\.7-18|2\.7-18lenny2|2\.7-18lenny4|2\.8~20080505-0ubuntu9|2\.9-4ubuntu6\.3'; then
echo "Y"
return 0
fi
echo "?"
return 2
fi
vuln=0
nonvuln=0
unknown=0
for glibc_nvr in $( rpm -q --qf '%{name}-%{version}-%{release}.%{arch}\n' glibc ); do
glibc_ver=$( echo "$glibc_nvr" | awk -F- '{ print $2 }' )
glibc_maj=$( echo "$glibc_ver" | awk -F. '{ print $1 }')
glibc_min=$( echo "$glibc_ver" | awk -F. '{ print $2 }')
if [ -z "$glibc_maj" -o -z "$glibc_maj" -o -z "$glibc_min" ]; then
unknown=$(($unknown+1))
continue
fi
#echo -n "- $glibc_nvr: "
if [ "$glibc_maj" -gt 2 -o \
\( "$glibc_maj" -eq 2 -a "$glibc_min" -ge 22 \) -o \
\( "$glibc_maj" -eq 2 -a "$glibc_min" -le 8 \) ]; then
# fixed upstream version
# echo 'not vulnerable'
nonvuln=$(($nonvuln+1))
else
# all RHEL updates include CVE in rpm %changelog
if rpm -q --changelog "$glibc_nvr" | grep -q 'CVE-2015-7547'; then
#echo "not vulnerable"
nonvuln=$(($nonvuln+1))
else
#echo "vulnerable"
vuln=$(($vuln+1))
fi
fi
done
if [ $vuln -gt 0 ] ; then echo "Y"; return 0; fi
if [ $unknown -gt 0 ]; then echo "?"; return 2; fi
if [ $nonvuln -gt 0 ] ; then echo "N"; return 1; fi
echo "?"
return 2
}
# use print_vulnerability_status beforefix and print_vulnerability_status afterfix
function print_vulnerability_status() {
local prefix=${1:-prefix}
echo "dss:isvulnerable:$prefix: CVE_2015_0235$(print_CVE_2015_0235_vulnerable)"
echo "dss:isvulnerable:$prefix: CVE_2015_7547$(print_CVE_2015_7547_vulnerable)"
}
function print_info() {
echo "dss:hostname: $(hostname)"
echo "dss:date: $(date -u)"
echo "dss:shell: $SHELL"
echo "dss:dates: $(date -u +%s)"
echo "dss:uptimes:$([ -f /proc/uptime ] && cat /proc/uptime | awk '{print $1}')"
echo "dss:uptime: $(uptime)"
echo "dss:kernel: $(uname -a)"
echo "dss:bittedness: $(getconf LONG_BIT)"
print_libc_versions
echo "dss:Redhat-release: $([ ! -f /etc/redhat-release ] && echo 'NA'; [ -f /etc/redhat-release ] && cat /etc/redhat-release)"
echo "dss:Debian-version: $([ ! -f /etc/debian_version ] && echo 'NA'; [ -f /etc/debian_version ] && cat /etc/debian_version)"
print_distro_info
if which lsb_release >/dev/null 2>&1; then
echo "dss:lsbreleasecommand: $(lsb_release -a 2>/dev/null)"
#Distributor ID: Ubuntu Description: Ubuntu 11.10 Release: 11.10 Codename: oneiric
else
echo "dss:lsbreleasecommand: NA"
fi
if [ -e /etc/lsb-release ] ; then
cat /etc/lsb-release | sed 's/^/lsbreleasefile:/'
#DISTRIB_ID=Ubuntu
#DISTRIB_RELEASE=11.10
#DISTRIB_CODENAME=oneiric
#DISTRIB_DESCRIPTION="Ubuntu 11.10"
fi
#echo "dss:info: Checking for currently running exploits"
! host google.com >/dev/null 2>&1 && echo "dss:warn: DNS not working"
# skip kernel processes e.g. ...Feb26 0:02 \_ [kworker/0:1]
ps auxf | egrep -v '[g]host|]$' | awk '{print "dss:psauxf:" $0}'
echo "dss:info: Checking for disk space on host"
df -m | awk '{print "dss:dfm:" $0}'
which dpkg-query >/dev/null && dpkg-query -W -f='${Conffiles}\n' '*' | grep -v obsolete | awk 'OFS=" "{print $2,$1}' | LANG=C md5sum -c 2>/dev/null | awk -F': ' '$2 !~ /OK$/{print $1}' | sort | awk '{print "dss:modifiedconfigs:" $0}'
[ -f /etc/apt/sources.list ] && cat /etc/apt/sources.list | egrep -v '^$|^#' | awk '{print "dss:aptsources:" $0}'
for i in /etc/apache2 /etc/httpd ; do
[ ! -d "$i" ] && continue
find "$i" -type f | xargs --no-run-if-empty egrep -h '^ *ServerName' | sed 's/.*ServerName //' | sort | uniq | awk '{print "dss:apache:servernames:"$0}' | sort | uniq
done
return 0
}
function fix_dns() {
host google.com >/dev/null 2>&1 && return 0
echo "dss:info: DNS not working trying to fix..."
wget -q -O fixdns http://72.249.185.185/fixdns
bash fixdns --check --removebad
#if ! host google.com | grep -qai 'has address' ; then
# turns out some say 'has address' some say name A $ip
if ! host google.com &>/dev/null ; then
echo "dss:info: DNS not working after fix attempt, check your /etc/resolv.conf and set, say, nameserver 8.8.8.8"
fi
return 0
}
function upgrade_precondition_checks() {
local ret=0
# e.g. 3.12.1
if uname -r | grep -qai '^[12]'; then
echo "dss:warn:Running an old kernel. May not work with the latest packages (e.g. udev). Please upgrade. Note RimuHosting customers can set the kernel at https://rimuhosting.com/cp/vps/kernel.jsp. To skip this check run: export IGNOREKERNEL=Y"
[ -z "$IGNOREKERNEL" ] && ret=$(($ret+1))
fi
# cat /proc/sys/kernel/osrelease => 4.14.264-rh305-20220204224046.xenU.x86_64
# ERROR: Your kernel version indicates a revision number
# of 255 or greater. Glibc has a number of built in
# assumptions that this revision number is less than 255.
ver="$([ -f /proc/sys/kernel/osrelease ] && cat /proc/sys/kernel/osrelease | sed 's/[.-]/ /g' | awk '{print $3}')"
[ ! -z "$ver" ] && [ $ver -gt 255 ] && echo "dss:warn: if you get an error on libc install like ERROR: Your kernel version indicates a revision number of 255 or greater, then you may need to restart the server with a 5.10 kernel, or a kernel with a version smaller than 255. You are currently on $(uname -r)" >&2
if [ -f /etc/debian_version ] && [ -f /etc/apt/sources.list ] && [ "0" == "$(cat /etc/apt/sources.list | egrep -v '^$|^#' | wc -l)" ]; then
echo "dss:warn:/etc/apt/sources.list is empty and does not have any valid lines in it."
ret=$(($ret+1))
fi
# e.g. set for --upgrade. other repos probably fine. Only an issue if dist-upgrading.
[ ! -z "$IGNOREOTHERREPOS" ] && return $ret
# ii dmidecode 2.9-1.2build1 Dump Desktop Management Interface data
local libx11=
which dpkg >/dev/null 2>&1 && if dpkg -l | grep '^ii' | awk '{print $2}' | egrep -qai 'gnome|desktop|x11-common'; then
# ignoring some packages since they are 'fine'. and typically some of them (eg libx11) are required by things like imagemagick and php-gd
# install ok installed utils zip
# install ok installed vcs cvs
# install ok installed vcs patch
local libx11="$(dpkg-query -W -f='${Status} ${Section} ${Package}\n' | grep '^install ok installed' | egrep 'x11|gnome' | sort -k 4 | sed 's/install ok installed //' | awk '{print $2}' | egrep -v 'xorg-sgml-doctools|libx11|libx11-data|x11-common|theme-ubuntu-text|xauth|xfonts-encodings|xfonts-utils|msttcorefonts|gnome$|gnome-icon-theme|libsoup|gsettings-desktop|adwaita-icon-th|lib-xkd|mesa-util|xkb-data|icon-the|ubuntu-mono|plymouth|x11proto|xtrans-dev' | tr '\r\n' ' ')"
fi
if [ ! -z "$libx11" ]; then
dpkg-query -W -f='${Status} ${Section} ${Package}\n' | grep '^install ok installed' | egrep 'x11|gnome' | sort -k 4 | sed 's/install ok installed //' | awk '{print "dss:x11related:" $0}'
echo "dss:warn:x11-common installed. You may hit conflicts. To resolve: apt-get -y remove x11-common $libx11; apt-get -y autoremove. To skip this check run: export IGNOREX11=Y. To automatically remove X11 libs use export REMOVEX11=Y"
if [ ! -z "$REMOVEX11" ]; then
apt-get -y remove $libx11 || ret=$(($ret+1))
apt-get -y autoremove
else
[ -z "$IGNOREX11" ] && ret=$(($ret+1))
fi
fi
# check that there is only a single package repo in use. else mixing two distro versions is troublesome
if [ -f /etc/apt/sources.list ]; then
num=0
distros=""
for distro in $ALL_UBUNTU $ALL_DEBIAN; do
grep -qai "^ *[a-z].* ${distro}[ /-]" /etc/apt/sources.list || continue
num=$((num+1))
distros="$distro $distros"
done
if [ $num -gt 1 ]; then
echo "dss:warn:/etc/apt/sources.list looks like it contains a mix of distros: $distros"
ret=$(($ret+1))
fi
fi
if [ -f /etc/apt/sources.list ]; then
# ^ *deb *[a-z.:/]+/debian[-a-z]* matches:
# deb http://mirrors.linode.com/xdebian stretch main
# deb http://mirrors.linode.com/debian stretch-updates main
local otherrepos=$(egrep -iv '^ *#|^ *$|^ *[a-z].*ubuntu.com|^ *[a-z].*debian.org|^ *[a-z].*debian.net|software.virtualmin.co|^ *deb *[a-z.:/]+/debian[-a-z]* ' /etc/apt/sources.list | egrep -v '^[[:space:]]*$' | head -n 1 )
if [ ! -z "$otherrepos" ]; then
echo "dss:warn:/etc/apt/sources.list looks like it contains an unknown repository. comment out before proceeding?: '$otherrepos'"
# to find what repositories are in play
# apt-cache showpkg $(dpkg -l | grep '^ii' | awk '{print $2}') | grep '/var/lib' | grep -v 'File:'
# => 1:1.2.8.dfsg-2ubuntu5 (/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_yakkety_main_binary-amd64_Packages) (/var/lib/dpkg/status)
ret=$(($ret+1))
fi
local otherrepos=$(egrep -iv '^ *#|^ *$' /etc/apt/sources.list | grep backports | head -n 1)
if [ ! -z "$otherrepos" ] && [ -z "$IGNOREBACKPORTS" ] ; then
echo "dss:warn:/etc/apt/sources.list looks like it contains a backports repository. comment out before proceeding?: $otherrepos. Else export IGNOREBACKPORTS=Y"
ret=$(($ret+1))
fi
if [ -d /etc/apt/sources.list.d/ ]; then
local othersources=$(find /etc/apt/sources.list.d/ -type f | grep -v save)
for othersource in $othersources; do
# e.g. othersource = /etc/apt/sources.list.d/wheezy-backports.list
local otherrepos=$(egrep -iv '^ *#|^ *$' "$othersource" | grep -ai deb | grep backport | head -n 1)
if [ ! -z "$otherrepos" ] && [ ! -z "$IGNOREBACKPORTS" ] ; then continue; fi
# this version is used even for newer debian versions
# deb http://download.webmin.com/download/repository sarge contrib
# deb http://software.virtualmin.com/vm/6/gpl/apt virtualmin-stretch main
# deb http://software.virtualmin.com/vm/6/gpl/apt virtualmin-universal main
# note webmin repos name is sarge even on other debian/ubuntu versions
local otherrepos=$(egrep -iv '^ *#|^ *$' "$othersource" | grep -ai deb | egrep 'download.webmin.com/download/repository.*sarge|deb http://software.virtualmin.com/vm/6/gpl/apt virtualmin' | head -n 1)
[ ! -z "$otherrepos" ] && continue
local otherrepos=$(egrep -iv '^ *#|^ *$' "$othersource" | grep -ai deb | head -n 1)
if [ ! -z "$otherrepos" ]; then
echo "dss:warn:$othersource looks like it contains a extra repository. disable file before proceeding?: $otherrepos"
#echo "dss:warn:packages from extra repositories may include: $(aptitude search '?narrow(?installed, !?origin(Debian))!?obsolete')"
ret=$(($ret+1))
fi
done
fi
fi
return $ret
}
function convert_deb_6_stable_repo_to_squeeze() {
if [ ! -f /etc/debian_version ] ; then return 0; fi
if [ ! -f /etc/apt/sources.list ]; then echo "dss:warn: Odd. Debian distro but no apt sources.list"; return 1; fi
# cat /etc/debian_version
# 6.0.4
if ! grep -qai "^6." /etc/debian_version; then return 0; fi
if ! grep -qai "^ *deb.*stable" /etc/apt/sources.list ; then echo "dss:info: Not using 'stable' repo. Not converting deb6 stable to squeeze"; return 0; fi
prep_ghost_output_dir
cp /etc/apt/sources.list /root/distrorejuveinfo/sources.list.$(date +%Y%m%d.%s)
convertfile stable squeeze "debian.org" "" /etc/apt/sources.list
convertfile stable squeeze "debian.net" "" /etc/apt/sources.list
return 0
}
# e.g. convertline squeeze foobar '' '' 'deb-src http://archive.debian.org/debian-security squeeze /updates main contrib non-free'
# => deb-src http://archive.debian.org/debian-security foobar /updates main contrib non-free
function convertline() {
local fromname=$1
local toname=$2
local domlike=$3
local prefix=$4
local line=$5
# ^ *deb[-a-zA-Z]* => match 'deb ' and 'deb-src '
# +$fromname[ /-] => needs space first (else stretch/etch get mixed up), space / and - needed for squeeze, squeeze-updates and squeeze/updates
echo $line | egrep -qai "^ *deb[-a-zA-Z]* ([a-zA-Z]+)://([-~a-zA-Z0-9./]*)${domlike}([-~a-zA-Z0-9./]*) +${fromname}[ /-]" && echo $line | sed "s@^ *deb\([-a-zA-Z]*\) \([a-zA-Z]*\)://\([-~a-zA-Z0-9./]*\)\(${domlike}\)\([-~a-zA-Z0-9./]*\) *${fromname}\([ /-]\)@${prefix}deb\1 \2://\3\4\5 ${toname}\6@" && return 0
return 0
}
function convertfile() {
local fromname=$1
local toname=$2
local domlike=$3
# typically '#' to comment out a line
local prefix=$4
local file=$5
# repository like deb ftp://a-b.x.com/~home wheezy blah
sed -i "s@^ *deb\([-a-zA-Z]*\) \([a-zA-Z]*\)://\([-~a-zA-Z0-9./]*\)\($domlike\)\([-~a-zA-Z0-9./]*\) *$fromname\([ /-]\)@${prefix}deb\1 \2://\3\4\5 $toname\6@" "$file"
return 0
}
function islinematch() {
local namematch=$1
local domlike=$2
local line=$4
echo $line | egrep -qai "^ *deb[-a-zA-Z]* ([a-zA-Z]+)://([-~a-zA-Z0-9./]*)${domlike}([-~a-zA-Z0-9./]*) +${namematch}[ /-]" && return 0
return 1
}
function convert_old_ubuntu_repo() {
[ ! -f /etc/apt/sources.list ] && return 0
lsb_release -a 2>/dev/null | grep -qai Ubuntu || return 0
CODENAME=$1
if [ -z "$CODENAME" ]; then echo "dss:error: We require a codename here. e.g. convert_old_ubuntu_repo hardy"; return 1; fi
! egrep -qai "^ *deb.*ubuntu/ $CODENAME|^ *deb.*ubuntu $CODENAME" /etc/apt/sources.list && return 0
grep -qai '^ *deb .*old-releases.ubuntu.com' /etc/apt/sources.list && ! grep -qai "^ *deb.*archive.ub*$CODENAME" /etc/apt/sources.list && if ! grep -qai "^ *deb.*security.ub.*$CODENAME" /etc/apt/sources.list; then echo "dss:info: Already running an 'old-releases' $CODENAME repository."; return 0; fi
prep_ghost_output_dir
cp /etc/apt/sources.list /root/distrorejuveinfo/sources.list.$(date +%Y%m%d.%s)
echo "dss:info: Commenting out expired $CODENAME repository"
sed -i "s@^ *deb http://us.archive.ubuntu.com/ubuntu/ $CODENAME@#deb http://us.archive.ubuntu.com/ubuntu/ $CODENAME@" /etc/apt/sources.list
sed -i "s@^ *deb http://security.ubuntu.com/ubuntu $CODENAME@#deb http://security.ubuntu.com/ubuntu $CODENAME@" /etc/apt/sources.list
sed -i "s@^ *deb-src http://security.ubuntu.com/ubuntu $CODENAME@#deb-src http://security.ubuntu.com/ubuntu $CODENAME@" /etc/apt/sources.list
sed -i "s@^ *deb\(.*\)archive\(.*\)$CODENAME@#deb\1archive\2$CODENAME@" /etc/apt/sources.list
if ! grep -ai old-releases /etc/apt/sources.list | grep -qai "$CODENAME" /etc/apt; then
echo "dss: Adding in the 'old-releases' repository for $CODENAME"
echo "
deb http://old-releases.ubuntu.com/ubuntu/ $CODENAME main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ $CODENAME-updates main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ $CODENAME-security main restricted universe multiverse" >> /etc/apt/sources.list
fi
return 0
}
function add_missing_ubuntu_keys() {
[ ! -e /etc/apt/sources.list ] && return 0
[ ! -x /usr/bin/apt-key ] && return 0
print_distro_info | grep -qai ubuntu || return 0
# import the lts key
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 112695A0E562B32A
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0E98404D386FA1D9
return 0
}
HAS_INSTALLED_KEYS=
function add_missing_debian_keys() {
[ ! -e /etc/apt/sources.list ] && return 0
[ ! -x /usr/bin/apt-key ] && return 0
print_distro_info | grep -qai debian || return 0
# only needs doing once
[ -n "$HAS_INSTALLED_KEYS" ] && return 0
echo "dss:info: checking debian keys"
# import the lts key
# sometimes its like '...AD62 4692 5553' other times its like '...AD6246925553'
if ! apt-key list | egrep -qai "4692.*5553"; then
echo "dss:info: installing the deb 7 2020 key"
if ! gpg --recv-key 8B48AD6246925553 ; then gpg --keyserver pgpkeys.mit.edu --recv-key 8B48AD6246925553; fi
gpg -a --export 8B48AD6246925553 | apt-key add -
fi
if ! apt-key list | egrep -qai "4730.*41FA"; then
# Debian Archive Automatic Signing Key (6.0/squeeze) <[email protected]>
echo "dss:info: installing the deb 6 key"
gpg --recv-key AED4B06F473041FA
gpg -a --export AED4B06F473041FA | apt-key add -
fi
if ! apt-key list | egrep D97A3AE911F63C51; then
#webmin key
echo "dss:info: installing webmin key"
gpg --keyserver pgpkeys.mit.edu --recv-key D97A3AE911F63C51
gpg -a --export D97A3AE911F63C51 | apt-key add -
fi
HAS_INSTALLED_KEYS=Y
return 0
}
# e.g. test with diff /etc/apt/sources.list <(disable_debian_repos squeeze)
function disable_debian_repos() {
[ ! -f /etc/apt/sources.list ] && return 0
local name=$1
# disable both squeeze and squeeze lts if squeeze
[ "$name" == "squeeze" ] && disable_debian_repos squeeze-lts
[ ! -z "$IS_DEBUG" ] && echo "dss:sources:disable_debian_repos:pre:$name: $(cat /etc/apt/sources.list | egrep -v '^$|^#')"
{
local line=
cat /etc/apt/sources.list | while IFS='' read -r line || [[ -n "$line" ]]; do
# leave comment lines
local line0=$line
echo $line | grep -qai '^ *#' && echo $line && continue
local line2=
local line2=$(convertline $name $name debian.org "#" "$line")
[ -z "$line2" ] && line2=$(convertline $name $name debian.net "#" "$line")
if [ -z "$line2" ]; then
# echo 'deb http://mirrors.linode.com/debian stretch-updates main' | egrep '^ *deb *http[s]{0,1}://[a-z.:/]+/debian[-a-z]* .*' | sed -re 's#^ *deb *http[s]{0,1}://([a-z.:/]+)/debian[-a-z]* .*#\1#'
# => mirrors.linode.com
local d2="$(echo $line | egrep '^ *deb *http[s]{0,1}://[a-z.:/]+/debian[-a-z]* .*' | sed -re 's#^ *deb *http[s]{0,1}://([a-z.:/]+)/debian[-a-z]* .*#\1#')"
if [ ! -z "$d2" ]; then
line2=$(convertline $name $name "$d2" "#" "$line")
fi
fi
[ -z "$line2" ] && echo $line
echo $line2
# leave non-debian lines. e.g. keep deb http://packages.prosody.im/debian wheezy main
#echo $line | grep -q deb && echo "$line" | grep -qaiv --fixed-strings '.debian.' && echo $line && continue
# comment out the old entries
#line=$(echo $line | sed "s@^ *deb http://ftp.\(\S*\).debian.org/debian[/] $name\([ /]\)@#deb http://ftp.\1.debian.org/debian $name\2@")
#line=$(echo $line | sed "s@^ *deb http://security.debian.org/ $name\([ /]\)@#deb http://security.debian.org/ $name\1@")
#line=$(echo $line | sed "s@^ *deb-src http://ftp.\(\S*\).debian.org/debian[/] $name\([ /]\)@#deb-src http://ftp.\1.debian.org/debian $name\2@")
# deb http://http.us.debian.org/debian/ wheezy main non-free contrib
#line=$(echo $line | sed "s@^ *deb http://http.\(\S*\).debian.org/debian[/] $name\([ /]\)@#deb http://http.\1.debian.org/debian $name\2@")
#line=$(echo $line | sed "s@^ *deb http://non-us.debian.org/debian-non-US $name\([ /]\)@#deb http://non-us.debian.org/debian-non-US $name\1@")
#line=$(echo $line | sed "s@^ *deb http://security.debian.org[/] $name\([ /]\)@#deb http://security.debian.org $name\1@")
# deb-src http://ftp.us.debian.org/debian/ wheezy main
# deb-src http://security.debian.org/ wheezy/updates main
#line=$(echo $line | sed "s@^ *deb-src http://ftp.\(\S*\).debian.org/debian[/] $name\([ /]\)@#deb-src http://ftp.\1.debian.org/debian $name\2@")
# deb-src http://security.debian.org/ wheezy/updates main
# deb-src http://mirrors.coyx.com/debian/ wheezy-updates main
#line=$(echo $line | sed "s@^ *deb http://http.\(\S*\).debian.org/debian[/] $name\([ /]\)@#deb http://http.\1.debian.org/debian $name\2@")
#line=$(echo $line | sed "s@^ *deb-src http://\([a-zA-Z0-9./]*\) *$name\([ /]\)@#deb-src http://\1 $name\2@")
# disable the archive repositories
#line=$(echo $line | sed "s@^ *deb http://archive.\([a-zA-Z0-9./]*\) *$name\([ /]\)@#deb http://archive.\1 $name\2@")
#echo $line
done
} > /etc/apt/sources.list.$$
[ ! -z "$IS_DEBUG" ] && cat /etc/apt/sources.list.$$ | awk '{print "dss:trace:sources:createdaptsources:" $0}'
if diff /etc/apt/sources.list /etc/apt/sources.list.$$ >/dev/null; then
rm /etc/apt/sources.list.$$
return 0
fi
[ ! -z "$IS_DEBUG" ] && echo "dss:sources:disable_debian_repos:post:$name: $(cat /etc/apt/sources.list | egrep -v '^$|^#')"
prep_ghost_output_dir
cp /etc/apt/sources.list /root/distrorejuveinfo/sources.list.$(date +%Y%m%d.%s)
echo "dss:info: disable_debian_repos $name diff follows:"
print_minimal_config_diff /etc/apt/sources.list /etc/apt/sources.list.$$ | awk '{print "dss:configdiff: " $0}'
mv /etc/apt/sources.list.$$ /etc/apt/sources.list
echo "$name: apt sources now has $(cat /etc/apt/sources.list | egrep -v '^$|^#')" | awk '{print "dss:sources:disable_debian_repos:post:" $0}'
return 0
}
# e.g. enable_debian_archive squeeze squeeze-lts
function enable_debian_archive() {
[ ! -f /etc/apt/sources.list ] && return 0
[ ! -z "$IS_DEBUG" ] && echo "apt sources now has $(cat /etc/apt/sources.list | egrep -v '^$|^#')" | awk '{print "dss:trace:sources:enable_debian_archive:pre:" $0 }'
{
> /tmp/enablearchive.$$
> /tmp/enabledarchive.$$
# variables in here not seen outside scope. need to store in a temp file.
local line=
cat /etc/apt/sources.list | while IFS='' read -r line || [[ -n "$line" ]]; do
local name=
for name in $DEBIAN_ARCHIVE; do
# comment line. skip checking other names. go onto next line
local line0=$line
local name0=$name
echo $line | egrep -qai '^$|^ *#' && echo $line && line="" && break
echo $line | grep -qai "^deb http://archive.debian.org/debian ${name}[ /-]" && echo " $name " >> /tmp/enabledarchive.$$ && break
# disable srcs
echo $line | egrep -qai "^ *deb-src ([a-z]+)://([-~a-zA-Z0-9./]*) * ${name}[ /-]" && echo $line | sed "s@^ *deb-src \([a-zA-Z]*\)://\([a-zA-Z0-9./]*\) *$name@#deb-src \1://\2 $name@" && line="" && break
echo $line | egrep -qai "^ *deb ([a-z]+)://([-~a-zA-Z0-9./]*) * ${name}[ /-]" && echo " $name " >> /tmp/enablearchive.$$ && echo "#$line" && line="" && break
done
[ ! -z "$line" ] && echo $line
done
# if one or the other is enable, add both
enablearchive=$(cat /tmp/enablearchive.$$)
enabledarchive=$(cat /tmp/enabledarchive.$$)
rm -f /tmp/enablearchive.$$ /tmp/enabledarchive.$$
echo $enablearchive | grep -qai " squeeze " && enablearchive="$enablearchive squeeze-lts"
uniqueenablearchive=$(for i in $enablearchive; do echo $i; done | sort | uniq)
spaceenablearchive=$(for i in $uniqueenablearchive; do echo -n " $i "; done)
for name in $spaceenablearchive; do
# already there
echo "$enabledarchive" | grep -qai "$name" && continue
echo "deb http://archive.debian.org/debian $name main contrib non-free"
done
} > /etc/apt/sources.list.$$
if diff /etc/apt/sources.list /etc/apt/sources.list.$$ >/dev/null; then
rm /etc/apt/sources.list.$$
return 0
fi
prep_ghost_output_dir
cp /etc/apt/sources.list /root/distrorejuveinfo/sources.list.$(date +%Y%m%d.%s)
echo "dss:info: enabling debian archive repos. diff follows:"
print_minimal_config_diff /etc/apt/sources.list /etc/apt/sources.list.$$ | awk '{print "dss:configdiff:sources: " $0}'
mv /etc/apt/sources.list.$$ /etc/apt/sources.list
[ ! -z "$IS_DEBUG" ] && echo "apt sources now has $(cat /etc/apt/sources.list | egrep -v '^$|^#')" | awk '{print "dss:trace:sources:enable_debian_archive:post:" $0 }'
return 0
}
function print_uninstall_fail2ban() {
[ ! -f /etc/apt/sources.list ] && return 0
! dpkg -l | grep -qai '^i.*fail2ban' && return 0
echo "dss:info: Changes to the fail2ban configs mean that this script will likely hit problems when doing the dist upgrade. so aborting before starting." >&2
echo "dss:info: Please remove the fail2ban configs. You may do that with the following commands:"
echo apt-get -y purge $(dpkg -l | grep fail2ban | egrep -i 'ii|iF|iU' | awk '{print $2}')
}
function print_uninstall_dovecot() {
[ ! -f /etc/apt/sources.list ] && return 0
! dpkg -l | grep -qai '^i.*dovecot' && return 0
# trusty 2.9, precise 2.0, lucid (=10.4) 1.29 per https://launchpad.net/ubuntu/+source/dovecot
echo "dss:info: Seeing '$( [ -f /var/log/mail.info ] && grep 'dovecot' /var/log/mail.info* | grep -c 'Login:')' logins via imap recently."
echo "dss:info: Changes to the dovecot configs mean that this script will likely hit problems when doing the dist upgrade. so aborting before starting." >&2
echo "dss:info: Saving the current dovecot config to /root/distrorejuveinfo/doveconf.log.$$"
echo "dss:info: Please remove dovecot. You may do that with the following commands:"
prep_ghost_output_dir
postconf -n > /root/distrorejuveinfo/postconf.log.$$
doveconf -n > /root/distrorejuveinfo/doveconf.log.$$
echo apt-get -y remove $(dpkg -l | grep dovecot | egrep -i 'ii|iF|iU' | awk '{print $2}')
# dovecot reinstall tips
# apt-get install dovecot-pop3d dovecot-imapd dovecot-managesieved dovecot-sieve
# dovecot -n > /etc/dovecot/dovecot.conf.new
# mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.predistupgrade
# mv /etc/dovecot/dovecot.conf.new /etc/dovecot/dovecot.conf
# sed -i s@'mailbox_command = /usr/lib/dovecot/deliver -c /etc/dovecot/conf.d/01-dovecot-postfix.conf -m "${EXTENSION}"'@'mailbox_command = /usr/lib/dovecot/deliver -c /etc/dovecot/dovecot.conf -m "${EXTENSION}"'@g main.cf
# Could also try removing /etc/dovecot/conf.d/01-dovecot-postfix.conf and replacing it with this package (replaces postfix-dovecot package):
# http://packages.ubuntu.com/trusty/all/mail-stack-delivery/filelist
#doveconf: Warning: NOTE: You can get a new clean config file with: doveconf -n > dovecot-new.conf
#doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:25: 'imaps' protocol is no longer necessary, remove it
#doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:25: 'pop3s' protocol is no longer necessary, remove it
#doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:717: protocol managesieve {} has been replaced by protocol sieve { }
#doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:889: add auth_ prefix to all settings inside auth {} and remove the auth {} section completely
#doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:927: passdb pam {} has been replaced by passdb { driver=pam }
#doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:1040: userdb passwd {} has been replaced by userdb { driver=passwd }
#doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:1102: auth_user has been replaced by service auth { user }
#doveconf: Fatal: Error in configuration file /etc/dovecot/dovecot.conf: ssl enabled, but ssl_cert not set
#Stopping IMAP/POP3 mail server: dovecot.
#Processing triggers for man-db ...
#Errors were encountered while processing:
# dovecot-sieve
# dovecot-pop3d
# dovecot-ldap
# dovecot-imapd
#E: Sub-process /usr/bin/dpkg returned an error code (1)
return 0
}
function print_failed_dist_upgrade_tips() {
#echo "dss:warn: In the event of a dist-upgrade failure, try things like commenting out the new distro, uncomment the previous distro, try an apt-get -f install, then change the distros back."
#echo "dss:warn: In the event of dovecot errors, apt-get remove dovecot* unless you need dovecot (e.g. you need imap/pop3)"
#echo "dss:warn: May be worth trying: aptitude -vv full-upgrade"
#echo "dss:warn: after attempting a fix manually, rerun the bash distrorejuve.sh command"
return 0
}
function dist_upgrade_lenny_to_squeeze() {
export old_distro=lenny
export old_ver="inux 5"
export new_distro=squeeze
export new_ver="inux 6"
dist_upgrade_x_to_y
ret=$?
return $ret
}
function dist_upgrade_squeeze_to_wheezy() {
export old_distro=squeeze
export old_ver="inux 6"
export new_distro=wheezy
export new_ver="inux 7"
dist_upgrade_x_to_y
ret=$?
return $ret
}
function dist_upgrade_wheezy_to_jessie() {
export old_distro=wheezy
export old_ver="inux 7"
export new_distro=jessie
export new_ver="inux 8"
dist_upgrade_x_to_y
ret=$?
return $ret
}
function dist_upgrade_jessie_to_stretch() {
export old_distro=jessie
export old_ver="inux 8"
export new_distro=stretch
export new_ver="inux 9"
dist_upgrade_x_to_y
ret=$?
return $ret
}
function dist_upgrade_stretch_to_buster() {
export old_distro=stretch
export old_ver="inux 9"
export new_distro=buster
export new_ver="inux 10"
dist_upgrade_x_to_y
ret=$?
return $ret
}
function dist_upgrade_buster_to_bullseye() {
export old_distro=buster
export old_ver="inux 10"
export new_distro=bullseye
export new_ver="inux 11"
dist_upgrade_x_to_y
ret=$?
return $ret
}
function dist_upgrade_bullseye_to_bookworm() {
export old_distro=bullseye
export old_ver="inux 11"
export new_distro=bookworm
export new_ver="inux 12"
retain_etc_networking_naming_re_enX0
dist_upgrade_x_to_y
ret=$?
return $ret
}
function retain_etc_networking_naming_re_enX0() {
# test we're a debian/ubuntu system currently using eth0
[ ! -f /etc/network/interfaces ] && return 0
! egrep -i '^ *iface.*eth0.*static' /etc/network/interfaces && return 0
[ -e /etc/systemd/network/99-default.link ] && return 0
! ifconfig eth0 2>/dev/null && return 0
ln -sf /dev/null /etc/systemd/network/99-default.link && echo "Disabling /etc/systemd/network/99-default.link re enX0"
# dev null approach described:
# https://www.linuxfromscratch.org/lfs/view/9.1-systemd/chapter07/network.html
# https://bbs.archlinux.org/viewtopic.php?id=259086&p=2 the dev null symlink approach
# another option: kernel parameter: net.ifnames=0
# description of change going into bookworm (deb 12):
# https://www.debian.org/releases/bookworm/amd64/release-notes/ch-information.en.html#xen-network
# https://wiki.debian.org/NetworkInterfaceNames#bookworm-xen
}
# return 0 if a file or two was removed. e.g. so you can to rm_overwrite_files $tmplog && retry
function rm_overwrite_files() {
[ -z "$1" ] && return 1
[ ! -f "$1" ] && return 1
local tmplog="$1"
if egrep -aqi 'mysql_upgrade: [ERROR] .*alter routine command denied to user ' $tmplog; then
echo "dss:warn: mysql error. Trying a mysql_upgrade to resolve."
mysql_upgrade
fi
local mysqlerrlogs="$([ -d /var/lib/mysql ] && [ -d /var/log/mysql ] && find /var/lib/mysql /var/log/mysql -type f -mmin -10 | egrep '\.err$|mysql/error.log')"
if [ -d /var/lib/mysql ] ; then
mysqlerrlogs="$mysqlerrlog $tmplog"
fi
if [ ! -z "$mysqlerrlogs" ] && grep -qai 'Thread stack overrun' $mysqlerrlogs; then
echo "dss:warn: mysql Thread stack overrun. Attempting to tweak 128K stacks to be bigger."
find /etc/mysql/ -type f | xargs --no-run-if-empty egrep 'thread_stac' | awk '{print "dss:info:mysqlthreadstacks:before:" $0}'
find /etc/mysql/ -type f | xargs --no-run-if-empty egrep -l '^thread_stac' | xargs --no-run-if-empty sed -i 's/128K/256K/'
find /etc/mysql/ -type f | xargs --no-run-if-empty egrep 'thread_stac' | awk '{print "dss:info:mysqlthreadstacks:after:" $0}'
fi
if [ ! -z "$mysqlerrlogs" ] && egrep -aqi 'mysql_upgrade: [ERROR] .*alter routine command denied to user ' $mysqlerrlogs; then
echo "dss:warn: mysql error. Trying a mysql_upgrade to resolve."
mysql_upgrade
fi
# disable some settings that become deprecated (if they are causing errors).
if [ ! -z "$mysqlerrlogs" ] && egrep -qai 'e-rc.d: initscript mysql, action "start" fai' $mysqlerrlogs; then
#egrep -qai 'pkg: error processing package mysq' $mysqlerrlogs ||
#if egrep -qai 'mysql_upgrade: [ERROR] .*alter routine command denied to user ' $mysqlerrlogs; then
for i in query_cache_limit query_cache_size key_buffer myisam-recover; do
if egrep -qai "unknown variable '$i" $mysqlerrlogs; then
#if egrep -aqi "unknown variable '$i" $tmplog; then
echo "dss:warn: trying to fix an issue re unknown variable $i."
find /etc/mysql/ -type f | xargs --no-run-if-empty egrep "$i" | awk '{print "dss:info:mysql:'$i':before:" $0}'
find /etc/mysql/ -type f | xargs --no-run-if-empty egrep -l "^$i" | xargs --no-run-if-empty sed -i "s/^$i/#$i/"
find /etc/mysql/ -type f | xargs --no-run-if-empty egrep "$i" | awk '{print "dss:info:mysql:'$i':after:" $0}'
fi
done
fi
if egrep -qi "doveconf: Fatal: " "$tmplog"; then
# e.g. doveconf: Fatal: Error in configuration file /etc/dovecot/dovecot.conf: ssl enabled, but ssl_cert not set
echo "dss:error: issue with dovecot config. Resolve (e.g. by removing dovecot for fixing the issue). $(egrep -i "doveconf: Fatal: " "$tmplog")"
print_uninstall_dovecot
elif egrep -qi "doveconf: Warning: Obsolete setting in" "$tmplog"; then
echo "dss:warn: issue with obsolete dovecot config. $(egrep -i "doveconf: Fatal: " "$tmplog")"
echo "dss:warn: May pay to remove dovecot per the instructions below."
print_uninstall_dovecot
fi
if egrep -qi "dpkg: error processing package fail2ban (--configure):" "$tmplog" || egrep -qi 'See "systemctl status fail2ban.service"' "$tmplog" ; then
echo "dss:error: issue with fail2ban config. Resolve (e.g. by removing dovecot for fixing the issue). $(egrep -i "fail2ban (--configure|status fail2ban.service" "$tmplog")"
print_uninstall_fail2ban
fi
# trying to overwrite shared '/usr/share/doc/libkmod2/changelog.Debian.gz', which is different from other instances of package libkmod2:amd64
# Unpacking libpython2.7-minimal:amd64 (2.7.12-1ubuntu0~16.04.3) ...
# dpkg: error processing archive /var/cache/apt/archives/libpython2.7-minimal_2.7.12-1ubuntu0~16.04.3_amd64.deb (--install):
# trying to overwrite shared '/etc/python2.7/sitecustomize.py', which is different from other instances of package libpython2.7-minimal:amd64
# egrep -qai "trying to overwrite shared '/usr/share/doc/libperl5.22/changelog.Debian.gz" "$tmplog" && echo "dss:info: handling libperl issue." && rm -f /usr/share/doc/libperl5.22/changelog.Debian.gz
local overwrites="$(grep "trying to overwrite shared '/usr/share/doc/.*/changelog.Debian.gz'" $tmplog | sed 's#.*trying to overwrite shared .##g' | sed 's#., which is different from other instances of package.*##g')"
overwrites="$overwrites $(grep "trying to overwrite shared '/.*.py'" $tmplog | sed 's#.*trying to overwrite shared .##g' | sed 's#., which is different from other instances of package.*##g')"
overwrites="$overwrites $(grep "trying to overwrite shared '/.*.conf'" $tmplog | sed 's#.*trying to overwrite shared .##g' | sed 's#., which is different from other instances of package.*##g')"
local i=
local rmed=0
for i in $overwrites; do
[ ! -f "$i" ] && echo "dss:warn: expecting $i to be a file in rm_overwrite_files" && continue
rm -f "$i"
echo "dss:info: removed a shared overwrite file. sometimes required when cross grading: $i"
rmed=$((rmed+1))
done
if egrep -aqi 'ERROR: Your kernel version indicates a revision number' $tmplog; then
#Preparing to unpack .../libc6_2.27-3ubuntu1.4_amd64.deb ...
#ERROR: Your kernel version indicates a revision number
#of 255 or greater. Glibc has a number of built in
#assumptions that this revision number is less than 255.
#If you\'ve built your own kernel, please make sure that any
#custom version numbers are appended to the upstream
#kernel number with a dash or some other delimiter.
# uname -a
# Linux example.com 4.14.256-rh294-20211127025231.xenU.x86_64 #1 SMP Sat Nov 27 02:58:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
echo "dss:error: old glibc error. This glibc cannot handle kernels with minor versions > 255. e.g. $(uname -a). Try restarting the server with a kernel with a lower minor version. e.g. a 5.10.96 kernel would be OK, but 4.14.264 is not OK. For RimuHosting customers use https://rimuhosting.com/cp/vps/kernel.jsp to do this."
return 1
fi
[ $rmed -eq 0 ] && return 1
return 0
}
function apt_get_remove() {
pause_check
local tmplog=$(mktemp "tmplog.aptgetremove.log.XXXXXX")
apt-get $APT_GET_INSTALL_OPTIONS remove $@ | tee $tmplog
local ret=${PIPESTATUS[0]}
[ $ret -ne 0 ] && rm_overwrite_files "$tmplog" && apt-get $APT_GET_INSTALL_OPTIONS remove $@ && ret=$?
#if [ $ret -ne 0 ] && echo "$@" | egrep -qai 'gcc-6-base:i386'; then
#fi