This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapt-notifier.py
executable file
·1799 lines (1600 loc) · 93.3 KB
/
apt-notifier.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess
import sys
import os
import tempfile
from os import environ
from PyQt4 import QtGui
from PyQt4 import QtCore
rc_file_name = environ.get('HOME') + '/.config/apt-notifierrc'
message_status = "not displayed"
def set_translations():
script = '''#!/bin/sh
locale|grep ^LANG=|cut -f2 -d=|cut -f1 -d_
'''
script_file = tempfile.NamedTemporaryFile('wt')
script_file.write(script)
script_file.flush()
run = subprocess.Popen(["echo -n `sh %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
locale = run.stdout.read(128)
script_file.close()
global tooltip_0_updates_available
global tooltip_1_new_update_available
global tooltip_multiple_new_updates_available
global popup_title
global popup_msg_1_new_update_available
global popup_msg_multiple_new_updates_available_begin
global popup_msg_multiple_new_updates_available_end
global Upgrade_using_Synaptic
global View_and_Upgrade
global Hide_until_updates_available
global Quit_Apt_Notifier
global Apt_Notifier_Help
global Synaptic_Help
global Apt_Notifier_Preferences
global Apt_History
global Check_for_Updates
global Check_for_Updates_by_User
Check_for_Updates_by_User = 'false'
global ignoreClick
ignoreClick = '0'
global RepoListsHashNow
RepoListsHashNow = ''
global RepoListsHashPrevious
RepoListsHashPrevious= ''
global AptConfsAndPrefsNow
AptConfsAndPrefsNow = ''
global AptConfsAndPrefsPrevious
AptConfsAndPrefsPrevious = ''
global AptPkgCacheHashNow
AptPkgCacheHashNow = ''
global AptPkgCacheHashPrevious
AptPkgCacheHashPrevious = ''
global text
text = ''
tooltip_0_updates_available = u"0 updates available"
tooltip_1_new_update_available = u"1 new update available"
tooltip_multiple_new_updates_available = u" new updates available"
popup_title = u"Updates"
popup_msg_1_new_update_available = u"You have 1 new update available"
popup_msg_multiple_new_updates_available_begin = u"You have "
popup_msg_multiple_new_updates_available_end = u" new updates available"
Upgrade_using_Synaptic = u"Upgrade using Synaptic"
View_and_Upgrade = u"View and Upgrade"
Hide_until_updates_available = u"Hide until updates available"
Quit_Apt_Notifier = u"Quit Apt-Notifier"
Apt_Notifier_Help = u"Apt-Notifier Help"
Synaptic_Help = u"Synaptic Help"
Apt_Notifier_Preferences = u"Apt Notifier Preferences"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
if locale == "ca":
tooltip_0_updates_available = u"No hi ha actualitzacions disponibles"
tooltip_1_new_update_available = u"1 actualització disponible"
tooltip_multiple_new_updates_available = u" noves actualitzacions disponibles"
popup_title = u"Actualitzacions"
popup_msg_1_new_update_available = u"Teniu 1 actualització disponible"
popup_msg_multiple_new_updates_available_begin = u"Teniu "
popup_msg_multiple_new_updates_available_end = u" noves actualitzacions disponibles"
Upgrade_using_Synaptic = u"Actualitza usant Synaptic"
View_and_Upgrade = u"Veure i actualitzar"
Hide_until_updates_available = u"Amagar fins que hi hagi actualitzacions disponibles"
Quit_Apt_Notifier = u"Surt d'Apt-Notifier"
Apt_Notifier_Help = u"Ajuda d'Apt-Notifier"
Synaptic_Help = u"Ajuda de Synaptic"
Apt_Notifier_Preferences = u"Preferències d'Apt Notifier"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
elif locale == "de":
tooltip_0_updates_available = u"0 Updates verfügbar"
tooltip_1_new_update_available = u"1 neues Update verfügbar"
tooltip_multiple_new_updates_available = u" neue Updates verfügbar"
popup_title = u"Updates"
popup_msg_1_new_update_available = u"Sie haben ein neues Update verfügbar"
popup_msg_multiple_new_updates_available_begin = u"Sie haben "
popup_msg_multiple_new_updates_available_end = u" neue Updates verfügbar"
Upgrade_using_Synaptic = u"Durch Synaptic aufrüsten"
View_and_Upgrade = u"Anschauen and aufrüsten"
Hide_until_updates_available = u"Verstercken bis Updates verfügbar"
Quit_Apt_Notifier = u"Apt-Notifier abbrechen "
Apt_Notifier_Help = u"Apt-Notifier Hilfe"
Synaptic_Help = u"Synaptic Hilfe"
Apt_Notifier_Preferences = u"Apt Notifier Einstellungen"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
elif locale == "el":
tooltip_0_updates_available = u"0 διαθέσιμες ενημερώσεις"
tooltip_1_new_update_available = u"0 διαθέσιμες ενημερώσεις"
tooltip_multiple_new_updates_available = u" νέες διαθέσιμες ενημερώσεις"
popup_title = u"Ενημερώσεις"
popup_msg_1_new_update_available = u"Έχετε 1 νέα διαθέσιμη ενημέρωση"
popup_msg_multiple_new_updates_available_begin = u"Έχετε "
popup_msg_multiple_new_updates_available_end = u" νέες διαθέσιμες ενημερώσεις"
Upgrade_using_Synaptic = u"Αναβάθμιση χρησιμοποιώντας το Synaptic"
View_and_Upgrade = u"Προβολή και Αναβάθμιση"
Hide_until_updates_available = u"Απόκρυψη μέχρι διαθέσιμες ενημερώσεις"
Quit_Apt_Notifier = u"Κλείστε το Apt-Notifier"
Apt_Notifier_Help = u"Apt-Notifier Βοήθεια"
Synaptic_Help = u"Synaptic Βοήθεια"
Apt_Notifier_Preferences = u"Apt Notifier Προτιμήσεις"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
elif locale == "es":
tooltip_0_updates_available = u"0 actualizaciones disponibles"
tooltip_1_new_update_available = u"1 nueva actualización disponible"
tooltip_multiple_new_updates_available = u" nuevas actualizaciones disponibles"
popup_title = u"Updates"
popup_msg_1_new_update_available = u"Tiene 1 nueva actualización disponible"
popup_msg_multiple_new_updates_available_begin = u"Tiene "
popup_msg_multiple_new_updates_available_end = u" nuevas actualizaciones disponibles"
Upgrade_using_Synaptic = u"Actualizar usando Synaptic"
View_and_Upgrade = u"Ver y Actualizar"
Hide_until_updates_available = u"Ocultar hasta que haya actualizaciones"
Quit_Apt_Notifier = u"Salir de Apt-Notifier"
Apt_Notifier_Help = u"Ayuda de Apt-Notifier"
Synaptic_Help = u"Ayuda de Synaptic"
Apt_Notifier_Preferences = u"Preferencias de Apt Notifier"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
elif locale == "fr":
tooltip_0_updates_available = u"0 mises à jour disponibles"
tooltip_1_new_update_available = u"1 nouvelle mise à jour disponible"
tooltip_multiple_new_updates_available = u" nouvelles mises à jour disponibles"
popup_title = u"Mises à jour"
popup_msg_1_new_update_available = u"Vous avez une nouvelle mise à jour disponible"
popup_msg_multiple_new_updates_available_begin = u"Vous avez "
popup_msg_multiple_new_updates_available_end = u" nouvelles mises à jour disponibles"
Upgrade_using_Synaptic = u"Mettre à niveau avec Synaptic"
View_and_Upgrade = u"Voir et mettre à niveau"
Hide_until_updates_available = u"Cacher jusqu'à ce que des mises à niveau soient disponibles"
Quit_Apt_Notifier = u"Annuler Apt-Notifier"
Apt_Notifier_Help = u"Aide sur Apt-Notifier"
Synaptic_Help = u"Aide sur Synaptic"
Apt_Notifier_Preferences = u"Préferences pour Apt Notifier"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
elif locale == "it":
tooltip_0_updates_available = u"0 aggiornamenti disponibili"
tooltip_1_new_update_available = u"1 nuovo aggiornamento disponibile"
tooltip_multiple_new_updates_available = u" nuovi aggiornamenti disponibili"
popup_title = u"Aggiornamenti"
popup_msg_1_new_update_available = u"Hai 1 nuovo aggiornamento disponibile"
popup_msg_multiple_new_updates_available_begin = u"Hai "
popup_msg_multiple_new_updates_available_end = u" nuovi aggiornamenti disponibili"
Upgrade_using_Synaptic = u"Aggiornare tramite Synaptic"
View_and_Upgrade = u"Mostra e aggiorna"
Hide_until_updates_available = u"Nascondi finchè non hai aggiornamenti disponibili"
Quit_Apt_Notifier = u"Chiudi Apt-Notifier"
Apt_Notifier_Help = u"Aiuto su Apt-Notifier"
Synaptic_Help = u"Aiuto su Synaptic"
Apt_Notifier_Preferences = u"Preferenze per Apt Notifier"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
elif locale == "ja":
tooltip_0_updates_available = u"0 新たな更新はありません"
tooltip_1_new_update_available = u"1 つの新たな更新が入手可能です"
tooltip_multiple_new_updates_available = u"つの新たな更新が入手可能です"
popup_title = u"更新"
popup_msg_1_new_update_available = u"1 つの新たな更新が入手可能です"
popup_msg_multiple_new_updates_available_begin = u""
popup_msg_multiple_new_updates_available_end = u"つの新たな更新が入手可能です"
Upgrade_using_Synaptic = u"更新に Synaptic を使用する"
View_and_Upgrade = u"表示・更新"
Hide_until_updates_available = u"入手可能な更新の非表示"
Quit_Apt_Notifier = u"Apt-Notifier を終了"
Apt_Notifier_Help = u"Apt-Notifier ヘルプ"
Synaptic_Help = u"Synaptic ヘルプ"
Apt_Notifier_Preferences = u"Apt Notifier 設定"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
elif locale == "nl":
tooltip_0_updates_available = u"0 updates beschikbaar"
tooltip_1_new_update_available = u"1 nieuwe update beschikbaar"
tooltip_multiple_new_updates_available = u" nieuwe updates beschikbaar"
popup_title = u"Updates"
popup_msg_1_new_update_available = u"U heeft 1 nieuwe update beschikbaar"
popup_msg_multiple_new_updates_available_begin = u"U heeft "
popup_msg_multiple_new_updates_available_end = u" nieuwe updates beschikbaar"
Upgrade_using_Synaptic = u"Upgrade met gebruik van Synaptic"
View_and_Upgrade = u"Bekijk en Upgrade"
Hide_until_updates_available = u"Verberg totdat updates beschikbaar zijn"
Quit_Apt_Notifier = u"Beëindig Apt-Notifier"
Apt_Notifier_Help = u"Apt-Notifier Help"
Synaptic_Help = u"Synaptic Help"
Apt_Notifier_Preferences = u"Apt Notifier Voorkeuren"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
elif locale == "pl":
tooltip_0_updates_available = u"0 Aktualizacje są dostępne"
tooltip_1_new_update_available = u"1 Aktualizacja dostępna"
tooltip_multiple_new_updates_available = u" Dostępne nowe aktualizacje"
popup_title = u"Aktualizacje"
popup_msg_1_new_update_available = u"Dostępna jest nowa aktualizacja"
popup_msg_multiple_new_updates_available_begin = u"Masz dostępnych "
popup_msg_multiple_new_updates_available_end = u" nowych aktualizacji"
Upgrade_using_Synaptic = u"Aktualizuj korzystając z Synaptic"
View_and_Upgrade = u"Przeglądaj i Aktualizować"
Hide_until_updates_available = u"Ukryj aż będą dostępne aktualizacje"
Quit_Apt_Notifier = u"Wyjdź z Apt-Notifier"
Apt_Notifier_Help = u"Pomoc Apt-Notifier"
Synaptic_Help = u"Pomoc Synaptic"
Apt_Notifier_Preferences = u"Apt Notifier Ustawienia"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
elif locale == "ru":
tooltip_0_updates_available = u"Нет доступных обновлений"
tooltip_1_new_update_available = u"1 обновление доступно"
tooltip_multiple_new_updates_available = u" обновлений доступно"
popup_title = u"Обновления"
popup_msg_1_new_update_available = u"Имеется одно доступное обновление"
popup_msg_multiple_new_updates_available_begin = u"Имеется "
popup_msg_multiple_new_updates_available_end = u" доступных обновлений"
Upgrade_using_Synaptic = u"Обновить, используя Synaptic"
View_and_Upgrade = u"Просмотр и обновление"
Hide_until_updates_available = u"Не показывать, если нет обновлений"
Quit_Apt_Notifier = u"Выйти из Apt-Notifier"
Apt_Notifier_Help = u"Apt Notifier Помощь"
Synaptic_Help = u"Synaptic Помощь"
Apt_Notifier_Preferences = u"Настройки Apt Notifier"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
elif locale == "sv":
tooltip_0_updates_available = u"0 uppdateringar tillgängliga"
tooltip_1_new_update_available = u"1 ny updatering tillgänglig"
tooltip_multiple_new_updates_available = u" nya uppdateringar tillgängliga"
popup_title = u"Updateringar"
popup_msg_1_new_update_available = u"Du har 1 ny uppdatering tillgänglig"
popup_msg_multiple_new_updates_available_begin = u"Du har "
popup_msg_multiple_new_updates_available_end = u" nya uppdatering tillgänglig"
Upgrade_using_Synaptic = u"Uppgradera med Synaptic"
View_and_Upgrade = u"Granska och Uppgradera"
Hide_until_updates_available = u"Göm tills uppdateringar är tillgängliga"
Quit_Apt_Notifier = u"Avsluta Apt-Notifier"
Apt_Notifier_Help = u"Apt-Notifier Hjälp"
Synaptic_Help = u"Synaptic Hjälp"
Apt_Notifier_Preferences = u"Apt Notifier Inställningar"
Apt_History = u"Apt History"
Check_for_Updates = u"Check for Updates (apt-get update)"
else:
pass
# Check for updates, using subprocess.Popen
def check_updates():
global message_status
global text
global RepoListsHashNow
global RepoListsHashPrevious
global AptConfsAndPrefsNow
global AptConfsAndPrefsPrevious
global AptPkgCacheHashNow
global AptPkgCacheHashPrevious
global Check_for_Updates_by_User
"""
Don't bother checking for updates when /var/lib/apt/periodic/update-stamp
isn't present. This should only happen in a Live session before the repository
lists have been loaded for the first time.
"""
command_string = "[ ! -e /var/lib/apt/periodic/update-stamp ]"
exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
if exit_state == 0:
if text == '':
text = '0'
message_status = "not displayed" # Resets flag once there are no more updates
add_hide_action()
if icon_config != "show":
AptIcon.hide()
else:
AptIcon.setIcon(NoUpdatesIcon)
AptIcon.setToolTip(tooltip_0_updates_available)
return
"""
Don't bother checking for updates if processes for other package management tools
appear to be runninng.
"""
command_string = "ps aux | grep -v grep | grep -E 'apt-get|aptitude|dpkg|gdebi|synaptic' -q"
exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
if exit_state == 0:
return
"""
Get a hash of the /var/lib/apt/lists folder.
"""
script = '''#!/bin/sh
find /var/lib/apt/lists/* 2>/dev/null | xargs md5sum 2>/dev/null | md5sum
'''
script_file = tempfile.NamedTemporaryFile('wt')
script_file.write(script)
script_file.flush()
run = subprocess.Popen(["echo -n `bash %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
RepoListsHashNow = run.stdout.read(128)
script_file.close()
"""
Get a hash of the /etc/apt/conf file and files in the .d folder,
and /etc/apt/preferences file and files in the .d folder.
"""
script = '''#!/bin/sh
find /etc/apt/{apt.conf*,preferences*} 2>/dev/null | grep -v .d$ | xargs md5sum 2>/dev/null | md5sum
'''
script_file = tempfile.NamedTemporaryFile('wt')
script_file.write(script)
script_file.flush()
run = subprocess.Popen(["echo -n `bash %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
AptConfsAndPrefsNow = run.stdout.read(128)
script_file.close()
"""
Get a hash of /var/cache/apt/pkgcache.bin.
"""
script = '''#!/bin/sh
md5sum /var/cache/apt/pkgcache.bin 2>/dev/null | md5sum
'''
script_file = tempfile.NamedTemporaryFile('wt')
script_file.write(script)
script_file.flush()
run = subprocess.Popen(["echo -n `bash %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
AptPkgCacheHashNow = run.stdout.read(128)
script_file.close()
"""
If
no changes in the Repo List hashes since last checked
AND
the Apt Conf & Apt Preferences hashes same since last checked
AND
pkgcache.bin same since last checked
AND
the call to check_updates wasn't initiated by user
then don't bother checking for updates.
"""
if RepoListsHashNow == RepoListsHashPrevious:
if AptConfsAndPrefsNow == AptConfsAndPrefsPrevious:
if AptPkgCacheHashNow == AptPkgCacheHashPrevious:
if Check_for_Updates_by_User == 'false':
if text == '':
text = '0'
return
RepoListsHashPrevious = RepoListsHashNow
RepoListsHashNow = ''
AptConfsAndPrefsPrevious = AptConfsAndPrefsNow
AptConfsAndPrefsNow = ''
AptPkgCacheHashPrevious = AptPkgCacheHashNow
AptPkgCacheHashNow = ''
Check_for_Updates_by_User = 'false'
#Create an inline script (what used to be /usr/bin/apt-notifier-check-Updates) and then run it to get the number of updates.
script = '''#!/bin/sh
sorted_list_of_upgrades()
{
#Create a sorted list of the names of the packages that are upgradeable.
LC_ALL=en_US apt-get -o 'Debug::NoLocking=true' --trivial-only -V $(grep ^UpgradeType ~/.config/apt-notifierrc | cut -f2 -d=) 2>/dev/null \
| sed -n '/upgraded:/,$p' | grep ^' ' | awk '{ print $1 }' | sort
}
#suppress updates available indication if 2 or more Release.reverify entries found
#if [ $(ls -1 /var/lib/apt/lists/partial/ | grep Release.reverify$ | wc -l) -ge 2 ]; then echo 0; exit; fi
if [ -s /var/lib/synaptic/preferences ];
then
#/var/lib/synaptic/preferences is a non-zero size file, which means there are packages pinned in Synaptic.
#Remove from the sorted_list_of_upgrades, packages that are pinned in Synaptic, and then get a count of remaining.
sorted_list_of_upgrades | grep -vx $(grep 'Package:' /var/lib/synaptic/preferences 2>/dev/null | awk {'print "-e " $2'}) | wc -l
else
#/var/lib/synaptic/preferences is either a zero byte file, meaning packages were pinned in Synaptic at some time in
# the past but none are currently pinned. Or the file is not present, meaning packages have never been pinned using
# Synaptic. In either case, just get a count of how many upgradeable packages are in the list.
sorted_list_of_upgrades | wc -l
fi
'''
script_file = tempfile.NamedTemporaryFile('wt')
script_file.write(script)
script_file.flush()
run = subprocess.Popen(["echo -n `sh %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
# Read the output into a text string
text = run.stdout.read(128)
script_file.close()
# Alter both Icon and Tooltip, depending on updates available or not
if text == "0":
message_status = "not displayed" # Resets flag once there are no more updates
add_hide_action()
if icon_config != "show":
AptIcon.hide()
else:
AptIcon.setIcon(NoUpdatesIcon)
AptIcon.setToolTip(tooltip_0_updates_available)
else:
if text == "1":
AptIcon.setIcon(NewUpdatesIcon)
AptIcon.show()
AptIcon.setToolTip(tooltip_1_new_update_available)
add_rightclick_actions()
# Shows the pop up message only if not displayed before
if message_status == "not displayed":
def show_message():
AptIcon.showMessage(popup_title, popup_msg_1_new_update_available)
Timer.singleShot(1000, show_message)
message_status = "displayed"
else:
AptIcon.setIcon(NewUpdatesIcon)
AptIcon.show()
AptIcon.setToolTip(text + tooltip_multiple_new_updates_available)
add_rightclick_actions()
# Shows the pop up message only if not displayed before
if message_status == "not displayed":
def show_message():
AptIcon.showMessage(popup_title, popup_msg_multiple_new_updates_available_begin + text + popup_msg_multiple_new_updates_available_end)
Timer.singleShot(1000, show_message)
message_status = "displayed"
def start_synaptic():
global Check_for_Updates_by_User
run = subprocess.Popen(['/usr/bin/su-to-root -X -c synaptic'],shell=True).wait()
Check_for_Updates_by_User = 'true'
check_updates()
def viewandupgrade():
global Check_for_Updates_by_User
initialize_aptnotifier_prefs()
script = '''#!/bin/bash
#cancel updates available indication if 2 or more Release.reverify entries found
#if [ $(ls -1 /var/lib/apt/lists/partial/ | grep Release.reverify$ | wc -l) -ge 2 ]; then exit; fi
window_title="MX Apt Notifier--View and Upgrade, previewing: apt-get "
use_apt_get_dash_dash_yes="use apt-get's --yes option for "
auto_close_term_window1="automatically close terminal window when apt-get "
auto_close_term_window2=" complete"
switch_to1="switch to 'apt-get "
switch_to2=""
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Reload"
reload_tooltip="Reload the package information to become informed about new, removed or upgraded software packages. \n(apt-get update)"
rootPasswordRequestMsg="The action you requested needs <b>root privileges</b>. Please enter <b>root's</b> password below."
done0=""
done1=' complete (or was canceled)"'
done2="'this terminal window can now be closed '"
done3="'(press any key to close)'"
autoremovable_packages_msg1="Unneeded packages are installed that can be removed."
autoremovable_packages_msg2="'Running apt-get autoremove, if you are unsure type "'"'"n"'"'".'"
case $(locale|grep ^LANG=|cut -f2 -d=|cut -f1 -d_) in
ca) window_title="MX Apt Notifier--Veure i actualitzar, vista prèvia: apt-get "
use_apt_get_dash_dash_yes="usa l'opció d'apt-get --yes per a "
auto_close_term_window1="tanca automàticament la finestra del terminal quan s'ha completat apt-get "
auto_close_term_window2=""
switch_to1="canvia a 'apt-get "
switch_to2=""
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Refresca"
reload_tooltip="Refresqueu la informació dels paquets per a informar-vos de paquets de programari nous, eliminats o actualitzats. \n(apt-get update)"
rootPasswordRequestMsg="A l'acció que heu demanat li calen <b>privilegis de root</b>. Si us plau, introduïu la contrasenya de <b>root</b> tot seguit."
done0="s'ha completat (o cancel·lat) "
done1='"'
done2="'ara podeu tancar la finestra '"
done3="'(prement qualsevol tecla)'"
autoremovable_packages_msg1="Unneeded packages are installed that can be removed."
autoremovable_packages_msg2="'Running apt-get autoremove, if you are unsure type "'"'"n"'"'".'"
;;
de) window_title="MX Apt Notifier--Anschauen and aufrüsten, vorprüfend: apt-get "
use_apt_get_dash_dash_yes="Option --yes von apt-get's benutzen bei "
auto_close_term_window1="Shellfenster automatiisch schliessen nach Ende von apt-get "
auto_close_term_window2=""
switch_to1="Zu 'apt-get "
switch_to2=" wechseln"
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Neu laden"
reload_tooltip="Die Paketinformationen neu laden, um über neue, entfernte oder aktualisierte Softwarepakete informiert zu werden. \n(apt-get update)"
rootPasswordRequestMsg="Die Aktion benötigt <b>Systemverwalterrechte</b>. Bitte geben Sie das Passwort des Benutzers <b>root</b> ein."
done0=""
done1=' fertig (oder beendet)"'
done2="'Dieses Shellfenster darf jetzt geschlossen werden '"
done3="'(drücken Sie eine beliebige Taste zu schliessen)'"
autoremovable_packages_msg1="Unnötige Pakete sind installiert, die entfernt werden können"
autoremovable_packages_msg2="'Apt-get autoremove wird ausgeführt, tippen Sie "'"'"n"'"'" wenn unsicher.'"
;;
el) window_title="MX Apt Notifier--Προβολή και Αναβάθμιση, προεπισκόπηση: apt-get "
use_apt_get_dash_dash_yes="χρησιμοποιήσετε την επιλογή του apt-get --yes option για την "
auto_close_term_window1="Να κλείσει αυτόματα το παράθυρο τερματικού όταν το apt-get "
auto_close_term_window2=" έχει ολοκληρωθεί"
switch_to1="αλλαγή σε 'apt-get "
switch_to2=""
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Ανανέωση"
reload_tooltip="Ανανέωση των πληροφοριών του πακέτου ώστε να γίνει ενημέρωση για νέα, αναβαθμισμένα ή απομακρυθέντα πακέτα λογισμικού. \n(apt-get update)"
rootPasswordRequestMsg="Η ενέργεια που ζητήσατε απαιτεί <b>προνόμια root</b>. Παρακαλώ εισάγετε τον κωδικό πρόσβασης του <b>root</b> παρακάτω."
done0=""
done1=' ολοκληρώθηκε (ή ακυρώθηκε)"'
done2="'Αυτό το παράθυρο τερματικού μπορεί να κλείσει '"
done3="'(πατήστε οποιοδήποτε πλήκτρο να κλείσει)'"
autoremovable_packages_msg1="Περιττά εγκαταστημένα πακέτα που μπορεί να αφαιρεθούν"
autoremovable_packages_msg2="'Εκτέλεση του apt-get autoremove, αν δεν είστε σίγουροι, πληκτρολογήστε "'"'"ο"'"'".'"
;;
es) window_title="MX Apt Notifier--Ver y Actualizar, vista previa: apt-get "
use_apt_get_dash_dash_yes="usar la opción --yes de apt-get para "
auto_close_term_window1="Cerrar automáticamente la terminal cuando se completa apt-get "
auto_close_term_window2=""
switch_to1="cambiar a 'apt-get "
switch_to2=""
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Recargar"
reload_tooltip="Recargar la información de los paquetes para informarse acerca de los paquetes de software nuevos, eliminados o actualizados. \n(apt-get update)"
rootPasswordRequestMsg="La acción que solicitó necesita <b>privilegios de superusuario</b> («root»). Introduzca la contraseña del <b>superusuario</b>."
done0="se completó "
done1=' (o se canceló)"'
done2="'esta ventana de terminal ya puede cerrarse '"
done3="'(oprima cualquier tecla para cerrarla)'"
autoremovable_packages_msg1="Los paquetes instalados pero no necesitados pueden ser removidos."
autoremovable_packages_msg2="'Ejecutando apt-get autoremove; si no está seguro, ingrese "'"'"n"'"'".'"
;;
fr) window_title="MX Apt Notifier--Voir et mettre à niveau, survol du programme apt-get "
use_apt_get_dash_dash_yes="utiliser l'option --yes de apt-get pour "
auto_close_term_window1="fermer automatiquement la fenêtre de terminal quand apt-get "
auto_close_term_window2=" se termine"
switch_to1="passer à apt-get "
switch_to2=""
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Recharger"
reload_tooltip="Recharger les informations des paquets pour être informé des nouveaux paquets, des suppressions de paquets ou des paquets mis à jour. \n(apt-get update)"
rootPasswordRequestMsg="L'action requise nécessite <b>les droits du superutilisateur</b>. Veuillez saisir ci-dessous le mot de passe du <b>superutilisateur</b>."
done0=""
done1=" s'est terminé (ou a été annulé)"'"'
done2="'vous pouvez maintenant fermer cette fenêtre de terminal '"
done3='"(appuyez sur n'"'"'importe quelle touche pour fermer)"'
autoremovable_packages_msg1="Il existe des paquets installés superflus; on peut les mettre au rebut."
autoremovable_packages_msg2="'On lancera apt-get autoremove; si vous n'êtes pas certain, tapez le "'"'"n"'"'".'"
;;
it) window_title="MX Apt Notifier--Mostra e Aggiorna, presentazione di: apt-get "
use_apt_get_dash_dash_yes="usare l'opzione --yes di apt-get per l' "
auto_close_term_window1="chiudere automaticamente la finestra del terminale quando apt-get "
auto_close_term_window2=" ha terminato"
switch_to1="passare a 'apt-get upgrade"
switch_to2=""
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Aggiorna"
reload_tooltip="Aggiorna le informazioni sui pacchetti per informare di pacchetti nuovi, rimossi o aggiornati. \n(apt-get update)"
rootPasswordRequestMsg="L'azione che hai richiesto richiede i <b>privilegi di root</b>. Per piacere, inserisci la password di <b>root</b>."
done0=""
done1=' ha terminato (o è stato annullato)"'
done2="'Ora è possibile chiudere questa finestra del terminale '"
done3="'(premi un tasto qualsiasi per chiudere)'"
autoremovable_packages_msg1="I pacchetti installati non necessari possono essere rimossi."
autoremovable_packages_msg2="'Si sta per avviare apt-get autoremove, se non sei sicuro digita "'"'"n"'"'".'"
;;
ja) window_title="MX Apt Notifier--表示・更新 これを試す: apt-get "
use_apt_get_dash_dash_yes="で apt-get's --yes オプションを使用する "
auto_close_term_window1="apt-get "
auto_close_term_window2=" が完了した後自動的に端末ウインドウを閉じる"
switch_to1="'apt-get "
switch_to2=" へ切り替える"
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="再読込"
reload_tooltip="新規、削除あるいはアップグレードされたパッケージについて情報が得られるように、パッケージ情報を再読込してください。 \n(apt-get update)"
rootPasswordRequestMsg="実行には <b>root</b> 権限が必要です。下に <b>root</b> のパスワードを入力してください。"
done0=""
done1=' 完了 (またはキャンセル)時に"'
done2="'この端末ウインドウを閉じる '"
done3="'(何かキーを押して閉じる)'"
autoremovable_packages_msg1="Unneeded packages are installed that can be removed."
autoremovable_packages_msg2="'Running apt-get autoremove, if you are unsure type "'"'"n"'"'".'"
;;
nl) window_title="MX Apt Notifier--Bekijk en Upgrade, voorbeeld: apt-get "
use_apt_get_dash_dash_yes="gebruik apt-get's --yes optie voor "
auto_close_term_window1="automatisch terminal scherm sluiten wanneer apt-get "
auto_close_term_window2=" klaar is"
switch_to1="wijzig naar 'apt-get "
switch_to2=""
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Herladen"
reload_tooltip="Ververs de pakketinformatie om ingelicht te worden over nieuwe, verwijderde of opgewaardeerde pakketten. \n(apt-get update)"
rootPasswordRequestMsg="Voor de handeling die u wilt verrichten hebt u <b>root-privileges</b> nodig. Voer hieronder het <b>root-wachtwoord</b> in."
done0=""
done1=' klaar (of was geannuleerd)"'
done2="'dit terminal scherm kan nu gesloten worden '"
done3="'(druk op een toets om te sluiten)'"
autoremovable_packages_msg1="Onnodige pakketten die zijn geïnstalleerd en kunnen worden verwijderd."
autoremovable_packages_msg2="'Uitvoeren apt-get autoremove, als je niet zeker bent tik "'"'"n"'"'".'"
;;
pl) window_title="MX Apt Notifier--Przeglądaj i Aktualizować, podglądu: apt-get "
use_apt_get_dash_dash_yes="stosować apt-get --yes opcję dla "
auto_close_term_window1="zostały automatycznie zamknięte okno terminalu przy apt-get "
auto_close_term_window2=" gotowy"
switch_to1="Przełącz na 'apt-get "
switch_to2=""
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Odśwież"
reload_tooltip="Odświeża bazę informacji o pakietach, aby otrzymać informacje o nowych, usuniętych, zaktualizowanych pakietach oprogramowania. \n(apt-get update)"
rootPasswordRequestMsg="Polecenie, które chcesz wykonać, wymaga <b>uprawnień administratora</b>. Wpisz poniżej <b>hasło administratora</b>."
done0="Komenda "
done1=' została wykonana (lub przerwana)"'
done2="'Okno to można zamknąć teraz '"
done3="'(naciśnij dowolny klawisz, aby zamknąć)'"
autoremovable_packages_msg1="Unneeded packages are installed that can be removed."
autoremovable_packages_msg2="'Running apt-get autoremove, if you are unsure type "'"'"n"'"'".'"
;;
ru) window_title="MX Apt Notifier--Просмотр и обновление, предпросмотр: apt-get "
use_apt_get_dash_dash_yes="Использовать опцию apt-get's --yes для "
auto_close_term_window1="Автоматически закрыть окно терминала после выполнения apt-get "
auto_close_term_window2=""
switch_to1="Перейти к 'apt-get "
switch_to2=""
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Обновить"
reload_tooltip="Обновление сведений о пакетах информирует о новых, удалённых или обновлённых пакетах программ \n(apt-get update)"
rootPasswordRequestMsg="Для выполнения данного действия необходимы <b>привилегии пользователя «root»</b>. Введите его пароль."
done0=""
done1=' Выполнено (или было отменено)"'
done2="'Это окно терминала теперь может быть закрыто '"
done3="'(нажмите любую клавишу, чтобы закрыть)'"
autoremovable_packages_msg1="Более ненужные установленные пакеты могут быть удалены."
autoremovable_packages_msg2="'Запуск apt-get autoremove, если вы не уверены, нажмите "'"'"n"'"'".'"
;;
sv) window_title="MX Apt Notifier--Granska och Uppgradera, förhandsgranskning: apt-get "
use_apt_get_dash_dash_yes="använd apt-get's --yes möjlighet för "
auto_close_term_window1="stäng automatiskt terminalfönstret när apt-get "
auto_close_term_window2=" är slutförd"
switch_to1="byt till 'apt-get "
switch_to2=""
switch_tooltip="Switches the type of Upgrade that will be performed, alternating back and forth between \n'apt-get upgrade' and 'apt-get dist-upgrade'"
reload="Läs om"
reload_tooltip="Läs om paketinformationen för att få information om nya, borttagna eller uppgraderade programpaket. \n(apt-get update)"
rootPasswordRequestMsg="Åtgärden du har begärt kräver <b>administratörsbehörighet</b>. Ange lösenordet för <b>root</b>nedan."
done0=""
done1=' färdig (eller stoppades)"'
done2="'detta terminalfönster kan nu stängas '"
done3="'(tryck på valfri tangent för att stänga)'"
autoremovable_packages_msg1="Onödiga paket som är installerade och kan tas bort."
autoremovable_packages_msg2="'Kör apt-get autoremove, om du är osäker skriv "'"'"n"'"'".'"
;;
*) : ;;
esac
RunAptScriptInTerminal(){
#for MEPIS remove "MX" branding from the $window_title string
window_title=$(echo "$1"|sed 's/MX /'$(grep -o MX-[1-9][0-9] /etc/issue|cut -c1-2)" "'/')
TermXOffset="$(xwininfo -root|awk '/Width/{print $2/4}')"
TermYOffset="$(xwininfo -root|awk '/Height/{print $2/4}')"
G=" --geometry=80x25+"$TermXOffset"+"$TermYOffset
I=" --icon=mnotify-some"
if [ "$2" = "" ]; then T=""; I=""; else T=" --title='""$(grep -o MX-[1-9][0-9] /etc/issue|cut -c1-2)"" apt-notifier: apt-get "$2"'"; fi
if (xprop -root | grep -q -i kde)
then
# Running KDE
#
# Can't get su-to-root to work in newer KDE's, so use kdesu for
# authentication.
#
# If x-terminal-emulator is set to xfce4-terminal.wrapper, use
# xfce4-terminal instead because the --hold option doesn't work with
# the wrapper. Also need to enclose the apt-get command in single
# quotes.
#
# If x-terminal-emulator is set to xterm, use konsole instead, if
# it's available (it should be).
case $(readlink -e /usr/bin/x-terminal-emulator | xargs basename) in
gnome-terminal.wrapper) if [ -e /usr/bin/konsole ]
then
$(kde4-config --path libexec)kdesu -c "konsole -e $3"
sleep 5
while [ "$(ps aux | grep [0-9]' konsole -e apt-get update')" != "" ]
do
sleep 1
done
sleep 1
else
:
fi
;;
konsole) $(kde4-config --path libexec)kdesu -c "konsole -e $3"
sleep 5
while [ "$(ps aux | grep [0-9]' konsole -e apt-get update')" != "" ]
do
sleep 1
done
sleep 1
;;
roxterm) $(kde4-config --path libexec)kdesu -c "roxterm$G$T --separate -e $3"
;;
xfce4-terminal.wrapper) $(kde4-config --path libexec)kdesu -n --noignorebutton -d -c "xfce4-terminal$G$I$T -e $3"
;;
xterm) if [ -e /usr/bin/konsole ]
then
$(kde4-config --path libexec)kdesu -c "konsole -e $3"
sleep 5
while [ "$(ps aux | grep [0-9]' konsole -e apt-get update')" != "" ]
do
sleep 1
done
sleep 1
else
$(kde4-config --path libexec)kdesu -c "xterm -e $3"
fi
;;
*) $(kde4-config --path libexec)kdesu -c "x-terminal-emulator -e $3"
sleep 5
while [ "$(ps aux | grep [0-9]' konsole -e apt-get update')" != "" ]
do
sleep 1
done
sleep 1
;;
esac
else
# Running a non KDE desktop
#
# Use su-to-root for authentication, it should end up using gksu.
#
# If x-terminal-emulator is set to xfce4-terminal.wrapper, use
# xfce4-terminal instead because the --hold option doesn't work
# with the wrapper. Also need to enclose the apt-get command in
# single quotes.
#
# If x-terminal-emulator is set to xterm, use xfce4-terminal
# instead, if it's available (it is in MX)
case $(readlink -e /usr/bin/x-terminal-emulator | xargs basename) in
gnome-terminal.wrapper) su-to-root -X -c "gnome-terminal$G$T -e $3"
;;
konsole) su-to-root -X -c "konsole -e $3"
sleep 5
while [ "$(ps aux | grep [0-9]' konsole -e apt-get update')" != "" ]
do
sleep 1
done
sleep 1
;;
roxterm) su-to-root -X -c "roxterm$G$T --separate -e $3"
;;
xfce4-terminal.wrapper) if [ -x $(whereis gksu | awk '{print $2}') ]
then
gksu -m "$rootPasswordRequestMsg""\n\n'apt-get $2'" "xfce4-terminal$G$I$T -e $3"
else
su-to-root -X -c "xfce4-terminal$G$I$T -e $3"
fi
;;
xterm) if [ -e /usr/bin/xfce4-terminal ]
then
su-to-root -X -c "xfce4-terminal$G$I$T -e $3"
else
su-to-root -X -c "xterm -e $3"
fi
;;
*) su-to-root -X -c "x-terminal-emulator -e $3"
;;
esac
fi
}
DoUpgrade(){
case $1 in
0)
BP="1"
chmod +x $TMP/upgradeScript
RunAptScriptInTerminal "$window_title" "$UpgradeType" "$TMP/upgradeScript"
;;
2)
BP="1"
;;
4)
BP="0"
sed -i 's/UpgradeType='$UpgradeType'/UpgradeType='$OtherUpgradeType'/' ~/.config/apt-notifierrc
;;
8)
BP="0"
#chmod +x $TMP/upgradeScript
RunAptScriptInTerminal "" "update" "'apt-get update'"
sleep 1
;;
*)
BP="1"
;;
esac
}
BP="0"
while [ $BP != "1" ]
do
UpgradeType=$(grep ^UpgradeType ~/.config/apt-notifierrc | cut -f2 -d=)
if [ "$UpgradeType" = "upgrade" ]; then
OtherUpgradeType="dist-upgrade"
fi
if [ "$UpgradeType" = "dist-upgrade" ]; then
OtherUpgradeType="upgrade"
fi
UpgradeAssumeYes=$(grep ^UpgradeAssumeYes ~/.config/apt-notifierrc | cut -f2 -d=)
UpgradeAutoClose=$(grep ^UpgradeAutoClose ~/.config/apt-notifierrc | cut -f2 -d=)
TMP=$(mktemp -d /tmp/apt-notifier.XXXXXX)
echo "apt-get $UpgradeType" > "$TMP"/upgrades
#The following 40 or so lines (down to the "APT_CONFIG" line) create a temporary etc/apt folder and subfolders
#that for the most part match the root owned /etc/apt folder and it's subfolders.
#
#A symlink to /var/synaptic/preferences symlink ("$TMP"/etc/apt/preferences.d/synaptic-pins) will be created
#if there isn't one already (note: the non-root user wouldn't be able to create one in /etc/apt/preferences.d/).
#
#With a /var/synaptic/preferences symlink in place, no longer need to remove the lines with Synaptic pinned packages
#from the "$TMP"/upgrades file to keep them from being displayed in the 'View and Upgrade' window, also no longer
#need to correct the upgrades count after removing the lines with the pinned updates.
#create the etc/apt/*.d subdirectories in the temporary directory ("$TMP")
for i in $(find /etc/apt -name *.d); do mkdir -p "$TMP"/$(echo $i | cut -f2- -d/); done
#create symlinks to the files in /etc/apt and it's subdirectories with exception of /etc/apt and /etc/apt/apt.conf
for i in $(find /etc/apt | grep -v -e .d$ -e apt.conf$ -e apt$); do ln -s $i "$TMP"/$(echo $i | cut -f2- -d/) 2>/dev/null; done
#in etc/preferences test to see if there's a symlink to /var/lib/synaptic/preferences
ls -l /etc/apt/preferences* | grep ^l | grep -m1 /var/lib/synaptic/preferences$ -q
#if there isn't, create one if there are synaptic pinned packages
if [ $? -eq 1 ]
then
if [ -s /var/lib/synaptic/preferences ]
then ln -s /var/lib/synaptic/preferences "$TMP"/etc/apt/preferences.d/synaptic-pins 2>/dev/null
fi
fi
#create a apt.conf in the temp directory by copying existing /etc/apt/apt.conf to it
[ ! -e /etc/apt/apt.conf ] || cp /etc/apt/apt.conf "$TMP"/apt.conf
#in apt.conf file set Dir to the path of the temp directory
echo 'Dir "'"$TMP"'/";' >> "$TMP"/apt.conf
#set Dir::State::* and Dir::Cache::* to the existing ones in /var/lib/apt, /var/lib/dpkg and /var/cache/apt
echo 'Dir::State "/var/lib/apt/";' >> "$TMP"/apt.conf
echo 'Dir::State::Lists "/var/lib/apt/lists/";' >> "$TMP"/apt.conf
echo 'Dir::State::status "/var/lib/dpkg/status";' >> "$TMP"/apt.conf
echo 'Dir::State::extended_states "/var/lib/apt/extended_states";' >> "$TMP"/apt.conf
echo 'Dir::Cache "/var/cache/apt/";' >> "$TMP"/apt.conf
echo 'Dir::Cache::Archives "/var/cache/apt/archives";' >> "$TMP"/apt.conf
echo 'Dir::Cache::srcpkgcache "/var/cache/apt/srcpkgcache.bin";' >> "$TMP"/apt.conf
echo 'Dir::Cache::pkgcache "/var/cache/apt/pkgcache.bin";' >> "$TMP"/apt.conf
APT_CONFIG="$TMP"/apt.conf apt-get -o Debug::NoLocking=true --trivial-only -V $UpgradeType 2>/dev/null >> "$TMP"/upgrades
#fix to display epochs
#for i in $(grep [[:space:]]'=>'[[:space:]] "$TMP"/upgrades | awk '{print $1}')
#do
# withoutEpoch="$(grep [[:space:]]$i[[:space:]] "$TMP"/upgrades | awk '{print $2}')"
# withEpoch="(""$(apt-cache policy $i | head -2 | tail -1 | awk '{print $NF}')"
# sed -i 's/'"$withoutEpoch"'/'"$withEpoch"'/' "$TMP"/upgrades
# withoutEpoch="$(grep [[:space:]]$i[[:space:]] "$TMP"/upgrades | awk '{print $4}')"
# withEpoch="$(apt-cache policy $i | head -3 | tail -1 | awk '{print $NF}')"")"
# sed -i 's/'"$withoutEpoch"'/'"$withEpoch"'/' "$TMP"/upgrades
#done
yad \
--window-icon=/usr/share/icons/mnotify-some.png \
--width=640 \
--height=480 \
--center \
--title "$window_title$UpgradeType" \
--form \
--field :TXT "$(sed 's/^/ /' "$TMP"/upgrades)" \
--field="$use_apt_get_dash_dash_yes$UpgradeType":CHK $UpgradeAssumeYes \
--field="$auto_close_term_window1$UpgradeType$auto_close_term_window2":CHK $UpgradeAutoClose \
--button "$switch_to1$OtherUpgradeType'$switch_to2"!!"$switch_tooltip":4 \
--button 'apt-get '"$UpgradeType"!mnotify-some!:0 \
--button "$reload"!reload!"$reload_tooltip":8 \
--button gtk-cancel:2 \
--buttons-layout=spread \
2>/dev/null \
> "$TMP"/results
echo $?>>"$TMP"/results
# if the View and Upgrade yad window was closed by one of it's 4 buttons,
# then update the UpgradeAssumeYes & UpgradeAutoClose flags in the
# ~/.config/apt-notifierrc file to match the checkboxes
if [ $(tail -n1 "$TMP"/results) -eq 0 ]||\
[ $(tail -n1 "$TMP"/results) -eq 2 ]||\
[ $(tail -n1 "$TMP"/results) -eq 4 ]||\
[ $(tail -n1 "$TMP"/results) -eq 8 ];
then
if [ "$(head -n1 "$TMP"/results | rev | awk -F \| '{ print $3}' | rev)" = "TRUE" ];
then
grep UpgradeAssumeYes=true ~/.config/apt-notifierrc -q || sed -i 's/UpgradeAssumeYes=false/UpgradeAssumeYes=true/' ~/.config/apt-notifierrc
else
grep UpgradeAssumeYes=false ~/.config/apt-notifierrc -q || sed -i 's/UpgradeAssumeYes=true/UpgradeAssumeYes=false/' ~/.config/apt-notifierrc
fi
if [ "$(head -n1 "$TMP"/results | rev | awk -F \| '{ print $2}' | rev)" = "TRUE" ];
then
grep UpgradeAutoClose=true ~/.config/apt-notifierrc -q || sed -i 's/UpgradeAutoClose=false/UpgradeAutoClose=true/' ~/.config/apt-notifierrc
else
grep UpgradeAutoClose=false ~/.config/apt-notifierrc -q || sed -i 's/UpgradeAutoClose=true/UpgradeAutoClose=false/' ~/.config/apt-notifierrc
fi
else
:
fi
# refresh UpgradeAssumeYes & UpgradeAutoClose
UpgradeAssumeYes=$(grep ^UpgradeAssumeYes ~/.config/apt-notifierrc | cut -f2 -d=)
UpgradeAutoClose=$(grep ^UpgradeAutoClose ~/.config/apt-notifierrc | cut -f2 -d=)
if [ $(tail -n1 "$TMP"/results) -eq 8 ];
then
# build a upgrade script to do a apt-get update
echo "#!/bin/bash"> "$TMP"/upgradeScript
echo "echo 'apt-get update'">> "$TMP"/upgradeScript
echo "apt-get update">> "$TMP"/upgradeScript
else
# build a upgrade script to do the apt-get upgrade (or dist-upgrade)
echo "#!/bin/bash"> "$TMP"/upgradeScript
echo "echo 'apt-get '"$UpgradeType>> "$TMP"/upgradeScript
echo 'find /etc/apt/preferences.d | grep -E synaptic-[0-9a-zA-Z]{6}-pins | xargs rm -f'>> "$TMP"/upgradeScript
echo 'if [ -f /var/lib/synaptic/preferences -a -s /var/lib/synaptic/preferences ]'>> "$TMP"/upgradeScript
echo ' then '>> "$TMP"/upgradeScript
echo ' SynapticPins=$(mktemp /etc/apt/preferences.d/synaptic-XXXXXX-pins)'>> "$TMP"/upgradeScript
echo ' ln -sf /var/lib/synaptic/preferences "$SynapticPins" 2>/dev/null'>> "$TMP"/upgradeScript
echo 'fi'>> "$TMP"/upgradeScript
echo 'file "$SynapticPins" | cut -f2- -d" " | grep -e"broken symbolic link" -e"empty" -q '>> "$TMP"/upgradeScript
echo 'if [ $? -eq 0 ]; then find /etc/apt/preferences.d | grep -E synaptic-[0-9a-zA-Z]{6}-pins | xargs rm -f; fi'>> "$TMP"/upgradeScript
if [ "$UpgradeAssumeYes" = "true" ];
then
echo "apt-get --assume-yes -V "$UpgradeType>> "$TMP"/upgradeScript