Guest User

Untitled

a guest
Oct 19th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 66.04 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import subprocess
  4. import sys
  5. import os
  6. import tempfile
  7. from os import environ
  8.  
  9. from PyQt5 import QtWidgets, QtGui
  10. from PyQt5 import QtCore
  11.  
  12. rc_file_name = environ.get('HOME') + '/.config/apt-notifierrc'
  13. message_status = "not displayed"
  14.  
  15. # ~~~ Localize 0 ~~~
  16.  
  17. # Use gettext and specify translation file locations
  18. import gettext
  19. gettext.bindtextdomain('apt-notifier', '/usr/share/locale')
  20. gettext.textdomain('apt-notifier')
  21. _ = gettext.gettext
  22. gettext.install('apt-notifier.py')
  23.  
  24. from string import Template # for simple string substitution (popup_msg...)
  25.  
  26. def set_translations():
  27. global tooltip_0_updates_available
  28. global tooltip_1_new_update_available
  29. global tooltip_multiple_new_updates_available
  30. global popup_title
  31. global popup_msg_1_new_update_available
  32. global popup_msg_multiple_new_updates_available
  33. global Upgrade_using_Synaptic
  34. global View_and_Upgrade
  35. global Hide_until_updates_available
  36. global Quit_Apt_Notifier
  37. global Apt_Notifier_Help
  38. global Synaptic_Help
  39. global Apt_Notifier_Preferences
  40. global Apt_History
  41. global Check_for_Updates
  42. global Check_for_Updates_by_User
  43. Check_for_Updates_by_User = 'false'
  44. global ignoreClick
  45. ignoreClick = '0'
  46. global RepoListsHashNow
  47. RepoListsHashNow = ''
  48. global RepoListsHashPrevious
  49. RepoListsHashPrevious= ''
  50. global AptConfsAndPrefsNow
  51. AptConfsAndPrefsNow = ''
  52. global AptConfsAndPrefsPrevious
  53. AptConfsAndPrefsPrevious = ''
  54. global AptPkgCacheHashNow
  55. AptPkgCacheHashNow = ''
  56. global AptPkgCacheHashPrevious
  57. AptPkgCacheHashPrevious = ''
  58. global text
  59. text = ''
  60.  
  61. # ~~~ Localize 1 ~~~
  62.  
  63. tooltip_0_updates_available = unicode (_("0 updates available") ,'utf-8')
  64. tooltip_1_new_update_available = unicode (_("1 new update available") ,'utf-8')
  65. tooltip_multiple_new_updates_available = unicode (_("$count new updates available") ,'utf-8')
  66. popup_title = unicode (_("Updates") ,'utf-8')
  67. popup_msg_1_new_update_available = unicode (_("You have 1 new update available") ,'utf-8')
  68. popup_msg_multiple_new_updates_available = unicode (_("You have $count new updates available") ,'utf-8')
  69. Upgrade_using_Synaptic = unicode (_("Upgrade using Synaptic") ,'utf-8')
  70. View_and_Upgrade = unicode (_("View and Upgrade") ,'utf-8')
  71. Hide_until_updates_available = unicode (_("Hide until updates available") ,'utf-8')
  72. Quit_Apt_Notifier = unicode (_("Quit") ,'utf-8')
  73. Apt_Notifier_Help = unicode (_("MX Updater Help") ,'utf-8')
  74. Synaptic_Help = unicode (_("Synaptic Help") ,'utf-8')
  75. Apt_Notifier_Preferences = unicode (_("Preferences") ,'utf-8')
  76. Apt_History = unicode (_("History") ,'utf-8')
  77. Check_for_Updates = unicode (_("Check for Updates") ,'utf-8')
  78.  
  79. # Check for updates, using subprocess.Popen
  80. def check_updates():
  81. global message_status
  82. global text
  83. global RepoListsHashNow
  84. global RepoListsHashPrevious
  85. global AptConfsAndPrefsNow
  86. global AptConfsAndPrefsPrevious
  87. global AptPkgCacheHashNow
  88. global AptPkgCacheHashPrevious
  89. global Check_for_Updates_by_User
  90.  
  91. """
  92. Don't bother checking for updates when /var/lib/apt/periodic/update-stamp
  93. isn't present. This should only happen in a Live session before the repository
  94. lists have been loaded for the first time.
  95. """
  96. command_string = "[ ! -e /var/lib/apt/periodic/update-stamp ] && [ ! -e /var/lib/apt/lists/lock ]"
  97. exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
  98. if exit_state == 0:
  99. if text == '':
  100. text = '0'
  101. message_status = "not displayed" # Resets flag once there are no more updates
  102. add_hide_action()
  103. if icon_config != "show":
  104. AptIcon.hide()
  105. else:
  106. AptIcon.setIcon(NoUpdatesIcon)
  107. command_string = "( [ -z $(apt-config shell U APT::Periodic::Unattended-Upgrade) ] )"
  108. exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
  109. if exit_state == 0:
  110. AptIcon.setToolTip(tooltip_0_updates_available)
  111. else:
  112. command_string = "( [ $(apt-config shell U APT::Periodic::Unattended-Upgrade | cut -c4) != 0 ] )"
  113. exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
  114. if exit_state == 0:
  115. AptIcon.setToolTip("")
  116. else:
  117. AptIcon.setToolTip(tooltip_0_updates_available)
  118. return
  119.  
  120. """
  121. Don't bother checking for updates if processes for other package management tools
  122. appear to be runninng.
  123. """
  124. command_string = "ps aux | grep -v grep | grep -E 'apt-get|aptitude|dpkg|gdebi|synaptic' -q"
  125. exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
  126. if exit_state == 0:
  127. return
  128.  
  129. """
  130. Get a hash of the /var/lib/apt/lists folder.
  131. """
  132. script = '''#!/bin/sh
  133. find /var/lib/apt/lists/* 2>/dev/null | xargs md5sum 2>/dev/null | md5sum
  134. '''
  135. script_file = tempfile.NamedTemporaryFile('wt')
  136. script_file.write(script)
  137. script_file.flush()
  138. run = subprocess.Popen(["echo -n `bash %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
  139. RepoListsHashNow = run.stdout.read(128)
  140. script_file.close()
  141.  
  142. """
  143. Get a hash of the /etc/apt/conf file and files in the .d folder,
  144. and /etc/apt/preferences file and files in the .d folder.
  145. """
  146. script = '''#!/bin/sh
  147. find /etc/apt/{apt.conf*,preferences*} 2>/dev/null | grep -v .d$ | xargs md5sum 2>/dev/null | md5sum
  148. '''
  149. script_file = tempfile.NamedTemporaryFile('wt')
  150. script_file.write(script)
  151. script_file.flush()
  152. run = subprocess.Popen(["echo -n `bash %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
  153. AptConfsAndPrefsNow = run.stdout.read(128)
  154. script_file.close()
  155.  
  156. """
  157. Get a hash of /var/cache/apt/pkgcache.bin.
  158. """
  159. script = '''#!/bin/sh
  160. md5sum /var/cache/apt/pkgcache.bin 2>/dev/null | md5sum
  161. '''
  162. script_file = tempfile.NamedTemporaryFile('wt')
  163. script_file.write(script)
  164. script_file.flush()
  165. run = subprocess.Popen(["echo -n `bash %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
  166. AptPkgCacheHashNow = run.stdout.read(128)
  167. script_file.close()
  168.  
  169. """
  170. If
  171. no changes in the Repo List hashes since last checked
  172. AND
  173. the Apt Conf & Apt Preferences hashes same since last checked
  174. AND
  175. pkgcache.bin same since last checked
  176. AND
  177. the call to check_updates wasn't initiated by user
  178. then don't bother checking for updates.
  179. """
  180. if RepoListsHashNow == RepoListsHashPrevious:
  181. if AptConfsAndPrefsNow == AptConfsAndPrefsPrevious:
  182. if AptPkgCacheHashNow == AptPkgCacheHashPrevious:
  183. if Check_for_Updates_by_User == 'false':
  184. if text == '':
  185. text = '0'
  186. return
  187.  
  188. RepoListsHashPrevious = RepoListsHashNow
  189. RepoListsHashNow = ''
  190.  
  191. AptConfsAndPrefsPrevious = AptConfsAndPrefsNow
  192. AptConfsAndPrefsNow = ''
  193.  
  194. AptPkgCacheHashPrevious = AptPkgCacheHashNow
  195. AptPkgCacheHashNow = ''
  196.  
  197. Check_for_Updates_by_User = 'false'
  198.  
  199. #Create an inline script (what used to be /usr/bin/apt-notifier-check-Updates) and then run it to get the number of updates.
  200. script = '''#!/bin/sh
  201.  
  202. #Create a temporary folder and redirect the apt-get upgrade and dist-upgrade output to them; doing this so only have to run the apt command 2 times.
  203. TMP=$(mktemp -d /tmp/apt-notifier.check_updates.XXXXXX)
  204.  
  205. LC_ALL=en_US apt-get -o Debug::NoLocking=true --trivial-only -V upgrade 2>/dev/null > "$TMP"/upgrade
  206. LC_ALL=en_US apt-get -o Debug::NoLocking=true --trivial-only -V dist-upgrade 2>/dev/null > "$TMP"/dist-upgrade
  207.  
  208. #Suppress 'updates available' notification if apt-get upgrade & dist-upgrade output are the same, and Unattended-Upgrades are enabled (>=1)
  209. diff "$TMP"/upgrade "$TMP"/dist-upgrade 1>/dev/null 2>/dev/null
  210. if [ $? -eq 0 ]
  211. then
  212. Unattended_Upgrade=0
  213. eval $(apt-config shell Unattended_Upgrade APT::Periodic::Unattended-Upgrade)
  214. if [ $Unattended_Upgrade != 0 ]
  215. then
  216. rm -rf "$TMP"
  217. echo 0
  218. exit
  219. fi
  220. fi
  221.  
  222. if [ $(grep ^UpgradeType ~/.config/apt-notifierrc | cut -f2 -d=) = upgrade ]
  223. then
  224. mv "$TMP"/upgrade "$TMP"/updates
  225. else
  226. mv "$TMP"/dist-upgrade "$TMP"/updates
  227. fi
  228.  
  229. #Suppress the 'updates available' notification if all of the updates are from a backports repo (jessie-backports, stretch-backports, etc.)
  230. if [ "$(grep " => " "$TMP"/updates | wc -l)" = "$(grep " => " "$TMP"/updates | grep -E ~bpo[0-9]+[+][0-9]+[\)]$ | wc -l)" ]
  231. then
  232. rm -rf "$TMP"
  233. echo 0
  234. exit
  235. fi
  236.  
  237. sorted_list_of_upgrades()
  238. {
  239. #Create a sorted list of the names of the packages that are upgradeable.
  240. cat "$TMP"/updates | sed -n '/upgraded:/,$p' | grep ^' ' | awk '{ print $1 }' | sort
  241. }
  242.  
  243. #suppress updates available indication if 2 or more Release.reverify entries found
  244. #if [ $(ls -1 /var/lib/apt/lists/partial/ | grep Release.reverify$ | wc -l) -ge 2 ]; then echo 0; exit; fi
  245.  
  246. if [ -s /var/lib/synaptic/preferences ];
  247. then
  248. #/var/lib/synaptic/preferences is a non-zero size file, which means there are packages pinned in Synaptic.
  249. #Remove from the sorted_list_of_upgrades, packages that are pinned in Synaptic, and then get a count of remaining.
  250.  
  251. sorted_list_of_upgrades | grep -vx $(grep 'Package:' /var/lib/synaptic/preferences 2>/dev/null | awk {'print "-e " $2'}) | wc -l
  252.  
  253. else
  254. #/var/lib/synaptic/preferences is either a zero byte file, meaning packages were pinned in Synaptic at some time in
  255. # the past but none are currently pinned. Or the file is not present, meaning packages have never been pinned using
  256. # Synaptic. In either case, just get a count of how many upgradeable packages are in the list.
  257.  
  258. sorted_list_of_upgrades | wc -l
  259. fi
  260. rm -rf "$TMP"
  261. '''
  262. script_file = tempfile.NamedTemporaryFile('wt')
  263. script_file.write(script)
  264. script_file.flush()
  265. run = subprocess.Popen(["echo -n `bash %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
  266. # Read the output into a text string
  267. text = run.stdout.read(128)
  268. script_file.close()
  269.  
  270. # Alter both Icon and Tooltip, depending on updates available or not
  271. if text == "0":
  272. message_status = "not displayed" # Resets flag once there are no more updates
  273. add_hide_action()
  274. if icon_config != "show":
  275. AptIcon.hide()
  276. else:
  277. AptIcon.setIcon(NoUpdatesIcon)
  278. command_string = "( [ $(apt-config shell U APT::Periodic::Unattended-Upgrade | cut -c4) != 0 ] && [ $(apt-config shell U APT::Periodic::Unattended-Upgrade | cut -c4) != '' ] )"
  279. exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
  280. if exit_state == 0:
  281. AptIcon.setToolTip("")
  282. else:
  283. AptIcon.setToolTip(tooltip_0_updates_available)
  284. else:
  285. if text == "1":
  286. AptIcon.setIcon(NewUpdatesIcon)
  287. AptIcon.show()
  288. AptIcon.setToolTip(tooltip_1_new_update_available)
  289. add_rightclick_actions()
  290. # Shows the pop up message only if not displayed before
  291. if message_status == "not displayed":
  292. def show_message():
  293. AptIcon.showMessage(popup_title, popup_msg_1_new_update_available)
  294. Timer.singleShot(1000, show_message)
  295. message_status = "displayed"
  296. else:
  297. AptIcon.setIcon(NewUpdatesIcon)
  298. AptIcon.show()
  299. tooltip_template=Template(tooltip_multiple_new_updates_available)
  300. tooltip_with_count=tooltip_template.substitute(count=text)
  301. AptIcon.setToolTip(tooltip_with_count)
  302. add_rightclick_actions()
  303. # Shows the pop up message only if not displayed before
  304. if message_status == "not displayed":
  305. # ~~~ Localize 1b ~~~
  306. # Use embedded count placeholder.
  307. popup_template=Template(popup_msg_multiple_new_updates_available)
  308. popup_with_count=popup_template.substitute(count=text)
  309. def show_message():
  310. #AptIcon.showMessage(popup_title, popup_msg_multiple_new_updates_available_begin + text + popup_msg_multiple_new_updates_available_end)
  311. AptIcon.showMessage(popup_title, popup_with_count)
  312. Timer.singleShot(1000, show_message)
  313. message_status = "displayed"
  314.  
  315. def start_synaptic():
  316. global Check_for_Updates_by_User
  317. run = subprocess.Popen(['/usr/bin/gksu synaptic'],shell=True).wait()
  318. Check_for_Updates_by_User = 'true'
  319. check_updates()
  320.  
  321. def viewandupgrade():
  322. global Check_for_Updates_by_User
  323. initialize_aptnotifier_prefs()
  324.  
  325. # ~~~ Localize 2 ~~~
  326.  
  327. # Accommodations for transformation from Python literals to Bash literals:
  328. # t10: \\n will convert to \n
  329. # t12: \\n will convert to \n
  330. # t16: '( and )' moved outside of translatable string to protect from potential translator's typo
  331. # t18: \\\"n\\\" will convert to \"n\" which will become "n" in shell (to avoid concatenating shell strings)
  332.  
  333. # t01 thru t12, Yad 'View and Upgrade' strings
  334. t01 = _("MX Updater--View and Upgrade, previewing: basic upgrade")
  335. t02 = _("MX Updater--View and Upgrade, previewing: full upgrade")
  336. #t03 = _("Automatically answer 'yes' to all prompts during full/basic upgrade")
  337. t03 = _("Automatically answer 'yes' to all prompts during upgrade")
  338. #t04 = _("automatically close terminal window when basic upgrade complete")
  339. t04 = _("automatically close terminal window when upgrade complete")
  340. #t05 = _("automatically close terminal window when full upgrade complete")
  341. t05 = _("automatically close terminal window when upgrade complete")
  342. t06 = _("basic upgrade")
  343. t07 = _("full upgrade")
  344. t08 = _("switch to basic upgrade")
  345. t09 = _("switch to full upgrade")
  346. t10 = _("Switches the type of Upgrade that will be performed, alternating back and forth between 'full upgrade' and 'basic upgrade'.")
  347. t11 = _("Reload")
  348. t12 = _("Reload the package information to become informed about new, removed or upgraded software packages. (apt-get update)")
  349.  
  350. # t13, gksu dialog
  351. t13 = _("The action you requested needs <b>root privileges</b>. Please enter <b>root's</b> password below.")
  352.  
  353. # t14 thru t19, strings for the upgrade (basic) / dist-upgrade (full) script that runs in the terminal window
  354. t14 = _("basic upgrade complete (or was canceled)")
  355. t15 = _("full upgrade complete (or was canceled)")
  356. t16 = _("this terminal window can now be closed")
  357. t17 = "'(" + _("press any key to close") + ")'"
  358. t18 = _("Unneeded packages are installed that can be removed.")
  359. t19 = _("Running apt-get autoremove, if you are unsure type 'n'.")
  360. t20 = _("upgrade")
  361. t21 = _("Using full upgrade")
  362. t22 = _("Using basic upgrade (not recommended)")
  363.  
  364. shellvar = (
  365. ' window_title_basic="' + t01 + '"\n'
  366. ' window_title_full="' + t02 + '"\n'
  367. ' use_apt_get_dash_dash_yes="' + t03 + '"\n'
  368. ' auto_close_window_basic="' + t04 + '"\n'
  369. ' auto_close_window_full="' + t05 + '"\n'
  370. ' basic_upgrade="' + t06 + '"\n'
  371. ' full_upgrade="' + t07 + '"\n'
  372. ' switch_to_basic_upgrade="' + t08 + '"\n'
  373. ' switch_to_full_upgrade="' + t09 + '"\n'
  374. ' switch_tooltip="' + t10 + '"\n'
  375. ' reload="' + t11 + '"\n'
  376. ' reload_tooltip="' + t12 + '"\n'
  377. ' rootPasswordRequestMsg="' + t13 + '"\n'
  378. ' done1basic="' + t14 + '"\n'
  379. ' done1full="' + t15 + '"\n'
  380. ' done2="' + t16 + '"\n'
  381. ' done3="' + t17 + '"\n'
  382. ' autoremovable_packages_msg1="' + t18 + '"\n'
  383. ' autoremovable_packages_msg2="' + t19 + '"\n'
  384. ' upgrade="' + t20 + '"\n'
  385. ' upgrade_tooltip_full="' + t21 + '"\n'
  386. ' upgrade_tooltip_basic="' + t22 + '"\n'
  387. )
  388.  
  389. script = '''#!/bin/bash
  390.  
  391. #cancel updates available indication if 2 or more Release.reverify entries found
  392. #if [ $(ls -1 /var/lib/apt/lists/partial/ | grep Release.reverify$ | wc -l) -ge 2 ]; then exit; fi
  393.  
  394. ''' + shellvar + '''
  395.  
  396. RunAptScriptInTerminal(){
  397. #for MEPIS remove "MX" branding from the $window_title string
  398. window_title_term=$window_title
  399. window_title_term=$(echo "$1"|sed 's/MX /'$(grep -o MX.*[1-9][0-9] /etc/issue|cut -c1-2)" "'/')
  400.  
  401. TermXOffset="$(xwininfo -root|awk '/Width/{print $2/4}')"
  402. TermYOffset="$(xwininfo -root|awk '/Height/{print $2/4}')"
  403. G=" --geometry=80x25+"$TermXOffset"+"$TermYOffset
  404. I=" --icon=mnotify-some-""$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)"
  405. if [ "$2" = "" ]
  406. then T=""; I=""
  407. else
  408. if [ "$2" != "update" ]
  409. then T=" --title='""$(grep -o MX.*[1-9][0-9] /etc/issue|cut -c1-2)"" Updater: "$2"'"
  410. else T=" --title='""$(grep -o MX.*[1-9][0-9] /etc/issue|cut -c1-2)"" Updater: "$reload"'"
  411. fi
  412. fi
  413.  
  414.  
  415. case $(readlink -e /usr/bin/x-terminal-emulator | xargs basename) in
  416.  
  417. roxterm) gksu "roxterm$G$T --separate -e $3"
  418. ;;
  419.  
  420. *) gksu "x-terminal-emulator -e $3"
  421. ;;
  422. esac
  423. }
  424.  
  425. DoUpgrade(){
  426. case $1 in
  427. 0)
  428. BP="1"
  429. chmod +x $TMP/upgradeScript
  430. RunAptScriptInTerminal "$window_title" "$UpgradeTypeUserFriendlyName" "$TMP/upgradeScript"
  431. ;;
  432.  
  433. 2)
  434. BP="1"
  435. ;;
  436.  
  437. 4)
  438. BP="0"
  439. sed -i 's/UpgradeType='$UpgradeType'/UpgradeType='$OtherUpgradeType'/' ~/.config/apt-notifierrc
  440. ;;
  441.  
  442. 8)
  443. BP="0"
  444. #chmod +x $TMP/upgradeScript
  445. RunAptScriptInTerminal "" "update" "'apt-get update'"
  446. sleep 1
  447. ;;
  448.  
  449. *)
  450. BP="1"
  451. ;;
  452.  
  453. esac
  454. }
  455.  
  456. BP="0"
  457. while [ $BP != "1" ]
  458. do
  459.  
  460. UpgradeType=$(grep ^UpgradeType ~/.config/apt-notifierrc | cut -f2 -d=)
  461. if [ "$UpgradeType" = "upgrade" ]; then
  462. UpgradeTypeUserFriendlyName=$basic_upgrade
  463. OtherUpgradeType="dist-upgrade"
  464. upgrade_tooltip=$upgrade_tooltip_basic
  465. fi
  466. if [ "$UpgradeType" = "dist-upgrade" ]; then
  467. UpgradeTypeUserFriendlyName=$full_upgrade
  468. OtherUpgradeType="upgrade"
  469. upgrade_tooltip=$upgrade_tooltip_full
  470. fi
  471.  
  472. UpgradeAssumeYes=$(grep ^UpgradeAssumeYes ~/.config/apt-notifierrc | cut -f2 -d=)
  473. UpgradeAutoClose=$(grep ^UpgradeAutoClose ~/.config/apt-notifierrc | cut -f2 -d=)
  474.  
  475. TMP=$(mktemp -d /tmp/apt-notifier.XXXXXX)
  476. echo "$UpgradeTypeUserFriendlyName" > "$TMP"/upgrades
  477.  
  478. #The following 40 or so lines (down to the "APT_CONFIG" line) create a temporary etc/apt folder and subfolders
  479. #that for the most part match the root owned /etc/apt folder and it's subfolders.
  480. #
  481. #A symlink to /var/synaptic/preferences symlink ("$TMP"/etc/apt/preferences.d/synaptic-pins) will be created
  482. #if there isn't one already (note: the non-root user wouldn't be able to create one in /etc/apt/preferences.d/).
  483. #
  484. #With a /var/synaptic/preferences symlink in place, no longer need to remove the lines with Synaptic pinned packages
  485. #from the "$TMP"/upgrades file to keep them from being displayed in the 'View and Upgrade' window, also no longer
  486. #need to correct the upgrades count after removing the lines with the pinned updates.
  487.  
  488. #create the etc/apt/*.d subdirectories in the temporary directory ("$TMP")
  489. for i in $(find /etc/apt -name *.d); do mkdir -p "$TMP"/$(echo $i | cut -f2- -d/); done
  490.  
  491. #create symlinks to the files in /etc/apt and it's subdirectories with exception of /etc/apt and /etc/apt/apt.conf
  492. 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
  493.  
  494. #in etc/preferences test to see if there's a symlink to /var/lib/synaptic/preferences
  495. ls -l /etc/apt/preferences* | grep ^l | grep -m1 /var/lib/synaptic/preferences$ -q
  496.  
  497. #if there isn't, create one if there are synaptic pinned packages
  498. if [ $? -eq 1 ]
  499. then
  500. if [ -s /var/lib/synaptic/preferences ]
  501. then ln -s /var/lib/synaptic/preferences "$TMP"/etc/apt/preferences.d/synaptic-pins 2>/dev/null
  502. fi
  503. fi
  504.  
  505. #create a apt.conf in the temp directory by copying existing /etc/apt/apt.conf to it
  506. [ ! -e /etc/apt/apt.conf ] || cp /etc/apt/apt.conf "$TMP"/apt.conf
  507.  
  508. #in apt.conf file set Dir to the path of the temp directory
  509. echo 'Dir "'"$TMP"'/";' >> "$TMP"/apt.conf
  510. #set Dir::State::* and Dir::Cache::* to the existing ones in /var/lib/apt, /var/lib/dpkg and /var/cache/apt
  511. echo 'Dir::State "/var/lib/apt/";' >> "$TMP"/apt.conf
  512. echo 'Dir::State::Lists "/var/lib/apt/lists/";' >> "$TMP"/apt.conf
  513. echo 'Dir::State::status "/var/lib/dpkg/status";' >> "$TMP"/apt.conf
  514. echo 'Dir::State::extended_states "/var/lib/apt/extended_states";' >> "$TMP"/apt.conf
  515. echo 'Dir::Cache "/var/cache/apt/";' >> "$TMP"/apt.conf
  516. echo 'Dir::Cache::Archives "/var/cache/apt/archives";' >> "$TMP"/apt.conf
  517. echo 'Dir::Cache::srcpkgcache "/var/cache/apt/srcpkgcache.bin";' >> "$TMP"/apt.conf
  518. echo 'Dir::Cache::pkgcache "/var/cache/apt/pkgcache.bin";' >> "$TMP"/apt.conf
  519.  
  520. APT_CONFIG="$TMP"/apt.conf apt-get -o Debug::NoLocking=true --trivial-only -V $UpgradeType 2>/dev/null >> "$TMP"/upgrades
  521.  
  522. #fix to display epochs
  523. #for i in $(grep [[:space:]]'=>'[[:space:]] "$TMP"/upgrades | awk '{print $1}')
  524. #do
  525. # withoutEpoch="$(grep [[:space:]]$i[[:space:]] "$TMP"/upgrades | awk '{print $2}')"
  526. # withEpoch="(""$(apt-cache policy $i | head -2 | tail -1 | awk '{print $NF}')"
  527. # sed -i 's/'"$withoutEpoch"'/'"$withEpoch"'/' "$TMP"/upgrades
  528. # withoutEpoch="$(grep [[:space:]]$i[[:space:]] "$TMP"/upgrades | awk '{print $4}')"
  529. # withEpoch="$(apt-cache policy $i | head -3 | tail -1 | awk '{print $NF}')"")"
  530. # sed -i 's/'"$withoutEpoch"'/'"$withEpoch"'/' "$TMP"/upgrades
  531. #done
  532.  
  533. # ~~~ Localize 2a ~~~
  534. # Format switch label. switch_to contains %s. eg "switch to %s" or "zu %s wechseln"
  535. # Result output to switch_label could be eg "switch to 'apt-get upgrade'"
  536. # or "zu 'apt-get dist-upgrade' wechseln'"
  537. # Should be able to use statement like:
  538. # printf -v switch_label "$switch_to" "$switch_type"
  539. # But fails, so use sed instead.
  540. # Format auto close message in same way.
  541.  
  542. switch_type="'""$OtherUpgradeType""'"
  543. switch_label=$(echo "$switch_to" | sed 's/%s/'"$switch_type"'/')
  544. auto_close_label=$(echo "$auto_close_window" | sed 's/%s/'"$UpgradeType"'/')
  545.  
  546. if [ "$UpgradeType" = "upgrade" ]
  547. then
  548. upgrade_label=$upgrade
  549. switch_label=$switch_to_full_upgrade
  550. auto_close_label=$auto_close_window_basic
  551. window_title="$window_title_basic"
  552. else
  553. upgrade_label=$upgrade
  554. switch_label=$switch_to_basic_upgrade
  555. auto_close_label=$auto_close_window_full
  556. window_title="$window_title_full"
  557. fi
  558.  
  559. yad \\
  560. --window-icon=/usr/share/icons/mnotify-some-"$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)".png \\
  561. --width=640 \\
  562. --height=480 \\
  563. --center \\
  564. --title "$(echo "$window_title"|sed 's/MX /'$(grep -o MX.*[1-9][0-9] /etc/issue|cut -c1-2)" "'/')" \\
  565. --form \\
  566. --field :TXT "$(sed 's/^/ /' "$TMP"/upgrades)" \\
  567. --field="$use_apt_get_dash_dash_yes":CHK $UpgradeAssumeYes \\
  568. --field="$auto_close_label":CHK $UpgradeAutoClose \\
  569. --button "$reload"!reload!"$reload_tooltip":8 \\
  570. --button ''"$upgrade_label"!mnotify-some-"$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)"!"$upgrade_tooltip":0 \\
  571. --button gtk-cancel:2 \\
  572. --buttons-layout=spread \\
  573. 2>/dev/null \\
  574. > "$TMP"/results
  575.  
  576. echo $?>>"$TMP"/results
  577.  
  578. # if the View and Upgrade yad window was closed by one of it's 4 buttons,
  579. # then update the UpgradeAssumeYes & UpgradeAutoClose flags in the
  580. # ~/.config/apt-notifierrc file to match the checkboxes
  581. if [ $(tail -n1 "$TMP"/results) -eq 0 ]||\\
  582. [ $(tail -n1 "$TMP"/results) -eq 2 ]||\\
  583. [ $(tail -n1 "$TMP"/results) -eq 4 ]||\\
  584. [ $(tail -n1 "$TMP"/results) -eq 8 ];
  585. then
  586. if [ "$(head -n1 "$TMP"/results | rev | awk -F \| '{ print $3}' | rev)" = "TRUE" ];
  587. then
  588. grep UpgradeAssumeYes=true ~/.config/apt-notifierrc -q || sed -i 's/UpgradeAssumeYes=false/UpgradeAssumeYes=true/' ~/.config/apt-notifierrc
  589. else
  590. grep UpgradeAssumeYes=false ~/.config/apt-notifierrc -q || sed -i 's/UpgradeAssumeYes=true/UpgradeAssumeYes=false/' ~/.config/apt-notifierrc
  591. fi
  592. if [ "$(head -n1 "$TMP"/results | rev | awk -F \| '{ print $2}' | rev)" = "TRUE" ];
  593. then
  594. grep UpgradeAutoClose=true ~/.config/apt-notifierrc -q || sed -i 's/UpgradeAutoClose=false/UpgradeAutoClose=true/' ~/.config/apt-notifierrc
  595. else
  596. grep UpgradeAutoClose=false ~/.config/apt-notifierrc -q || sed -i 's/UpgradeAutoClose=true/UpgradeAutoClose=false/' ~/.config/apt-notifierrc
  597. fi
  598. else
  599. :
  600. fi
  601.  
  602. # refresh UpgradeAssumeYes & UpgradeAutoClose
  603. UpgradeAssumeYes=$(grep ^UpgradeAssumeYes ~/.config/apt-notifierrc | cut -f2 -d=)
  604. UpgradeAutoClose=$(grep ^UpgradeAutoClose ~/.config/apt-notifierrc | cut -f2 -d=)
  605.  
  606. if [ $(tail -n1 "$TMP"/results) -eq 8 ];
  607. then
  608. # build a upgrade script to do a apt-get update
  609. echo "#!/bin/bash"> "$TMP"/upgradeScript
  610. echo "echo 'update'">> "$TMP"/upgradeScript
  611. echo "apt-get update">> "$TMP"/upgradeScript
  612.  
  613. else
  614. # build a upgrade script to do the apt-get upgrade (basic upgrade) or dist-upgrade (full upgrade)
  615. echo "#!/bin/bash"> "$TMP"/upgradeScript
  616. echo "echo ''"$UpgradeTypeUserFriendlyName>> "$TMP"/upgradeScript
  617. echo 'find /etc/apt/preferences.d | grep -E synaptic-[0-9a-zA-Z]{6}-pins | xargs rm -f'>> "$TMP"/upgradeScript
  618. echo 'if [ -f /var/lib/synaptic/preferences -a -s /var/lib/synaptic/preferences ]'>> "$TMP"/upgradeScript
  619. echo ' then '>> "$TMP"/upgradeScript
  620. echo ' SynapticPins=$(mktemp /etc/apt/preferences.d/synaptic-XXXXXX-pins)'>> "$TMP"/upgradeScript
  621. echo ' ln -sf /var/lib/synaptic/preferences "$SynapticPins" 2>/dev/null'>> "$TMP"/upgradeScript
  622. echo 'fi'>> "$TMP"/upgradeScript
  623. echo 'file "$SynapticPins" | cut -f2- -d" " | grep -e"broken symbolic link" -e"empty" -q '>> "$TMP"/upgradeScript
  624. 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
  625. if [ "$UpgradeAssumeYes" = "true" ];
  626. then
  627. echo "apt-get --assume-yes -V "$UpgradeType>> "$TMP"/upgradeScript
  628. else
  629. echo "apt-get -V "$UpgradeType>> "$TMP"/upgradeScript
  630. fi
  631. grep ^CheckForAutoRemoves=true ~/.config/apt-notifierrc -q
  632. if [ $? -eq 0 ]
  633. then
  634. echo "echo">> "$TMP"/upgradeScript
  635. echo 'apt-get autoremove -s | grep ^Remv -q'>> "$TMP"/upgradeScript
  636. echo 'if [ $? -eq 0 ]; '>> "$TMP"/upgradeScript
  637. echo ' then'>> "$TMP"/upgradeScript
  638. echo 'echo "'"$autoremovable_packages_msg1"'"'>> "$TMP"/upgradeScript
  639. echo 'echo "'"$autoremovable_packages_msg2"'"'>> "$TMP"/upgradeScript
  640. echo 'apt-get autoremove -qV'>> "$TMP"/upgradeScript
  641. echo ' else'>> "$TMP"/upgradeScript
  642. echo ' :'>> "$TMP"/upgradeScript
  643. echo 'fi'>> "$TMP"/upgradeScript
  644. else
  645. :
  646. fi
  647. echo "echo">> "$TMP"/upgradeScript
  648. echo 'find /etc/apt/preferences.d | grep -E synaptic-[0-9a-zA-Z]{6}-pins | xargs rm -f'>> "$TMP"/upgradeScript
  649.  
  650. # ~~~ Localize 2b ~~~
  651.  
  652. #donetype="$UpgradeType"
  653. #donetext=$(echo "$done1" | sed 's/%s/'"$donetype"'/')
  654. if [ "$UpgradeType" = "upgrade" ]
  655. then
  656. donetext="$done1basic"
  657. else
  658. donetext="$done1full"
  659. fi
  660. echo 'echo "'"$donetext"'"'>> "$TMP"/upgradeScript
  661. echo "echo">> "$TMP"/upgradeScript
  662.  
  663. if [ "$UpgradeAutoClose" = "true" ];
  664. then
  665. echo "sleep 1">> "$TMP"/upgradeScript
  666. echo "exit 0">> "$TMP"/upgradeScript
  667. else
  668. echo "echo -n $done2' '">> "$TMP"/upgradeScript
  669. echo "read -sn 1 -p $done3 -t 999999999">> "$TMP"/upgradeScript
  670. echo "echo">> "$TMP"/upgradeScript
  671. echo "exit 0">> "$TMP"/upgradeScript
  672. fi
  673. fi
  674.  
  675. DoUpgrade $(tail -n1 "$TMP"/results)
  676.  
  677. rm -rf "$TMP"
  678.  
  679. done
  680.  
  681. sleep 2
  682. PID=`pidof apt-get | cut -f 1 -d " "`
  683. if [ $PID ]; then
  684. while (ps -p $PID > /dev/null); do
  685. sleep 2
  686. done
  687. fi
  688. '''
  689. script_file = tempfile.NamedTemporaryFile('wt')
  690. script_file.write(script)
  691. script_file.flush()
  692. run = subprocess.Popen(['bash %s' % script_file.name],shell=True).wait()
  693. script_file.close()
  694. Check_for_Updates_by_User = 'true'
  695. check_updates()
  696.  
  697. def initialize_aptnotifier_prefs():
  698.  
  699. """Create/initialize preferences in the ~/.config/apt-notifierrc file """
  700. """if they don't already exist. Remove multiple entries and those that """
  701. """appear to be invalid. """
  702.  
  703. script = '''#! /bin/bash
  704.  
  705. #test if ~/.config/apt-notifierrc contains a UpgradeType=* line and that it's a valid entry
  706. grep -q -e ^"UpgradeType=upgrade" -e^"UpgradeType=dist-upgrade" ~/.config/apt-notifierrc
  707. if [ "$?" -eq 0 ]
  708. then
  709. #contains a valid entry so do nothing
  710. :
  711. else
  712. #
  713. #if a UpgradeType=* line not present,
  714. #or not equal to "upgrade" or "dist-upgrade"
  715. #initially set it to "UpgradeType=dist-upgrade"
  716. #also delete multiple entries or what appears to be invalid entries
  717. sed -i '/.*UpgradeType.*/Id' ~/.config/apt-notifierrc
  718. echo "UpgradeType=dist-upgrade">> ~/.config/apt-notifierrc
  719. fi
  720.  
  721. #test if ~/.config/apt-notifierrc contains a UpgradeAssumeYes=* line and that it's a valid entry
  722. grep -q -e ^"UpgradeAssumeYes=true" -e^"UpgradeAssumeYes=false" ~/.config/apt-notifierrc
  723. if [ "$?" -eq 0 ]
  724. then
  725. #contains a valid entry so do nothing
  726. :
  727. else
  728. #
  729. #if a UpgradeAssumeYes=* line not present,
  730. #or not equal to "true" or "false"
  731. #initially set it to "UpgradeAssumeYes=false"
  732. #also delete multiple entries or what appears to be invalid entries
  733. sed -i '/.*UpgradeAssumeYes.*/Id' ~/.config/apt-notifierrc
  734. echo "UpgradeAssumeYes=false">> ~/.config/apt-notifierrc
  735. fi
  736.  
  737. #test if ~/.config/apt-notifierrc contains a UpgradeAutoClose=* line and that it's a valid entry
  738. grep -q -e ^"UpgradeAutoClose=true" -e^"UpgradeAutoClose=false" ~/.config/apt-notifierrc
  739. if [ "$?" -eq 0 ]
  740. then
  741. #contains a valid entry so do nothing
  742. :
  743. else
  744. #
  745. #if a UpgradeAutoClose=* line not present,
  746. #or not equal to "true" or "false"
  747. #intially set it to "UpgradeAutoClose=false"
  748. #also delete multiple entries or what appears to be invalid entries
  749. sed -i '/.*UpgradeAutoClose.*/Id' ~/.config/apt-notifierrc
  750. echo "UpgradeAutoClose=false">> ~/.config/apt-notifierrc
  751. fi
  752.  
  753. #test if ~/.config/apt-notifierrc contains a LeftClick=* line and that it's a valid entry
  754. grep -q -e ^"LeftClick=ViewAndUpgrade" -e^"LeftClick=Synaptic" ~/.config/apt-notifierrc
  755. if [ "$?" -eq 0 ]
  756. then
  757. #contains a valid entry so do nothing
  758. :
  759. else
  760. #
  761. #if a LeftClick line not present,
  762. #or not equal to "ViewAndUpgrade" or "Synaptic"
  763. #initially set it to "LeftClick=ViewAndUpgrade"
  764. #also delete multiple entries or what appears to be invalid entries
  765. sed -i '/.*LeftClick.*/Id' ~/.config/apt-notifierrc
  766. echo "LeftClick=ViewAndUpgrade">> ~/.config/apt-notifierrc
  767. fi
  768.  
  769. #test if ~/.config/apt-notifierrc contains a CheckForAutoRemoves=* line and that it's a valid entry
  770. grep -q -e ^"CheckForAutoRemoves=true" -e^"CheckForAutoRemoves=false" ~/.config/apt-notifierrc
  771. if [ "$?" -eq 0 ]
  772. then
  773. #contains a valid entry so do nothing
  774. :
  775. else
  776. #
  777. #if a CheckForAutoRemoves=* line not present,
  778. #or not equal to "true" or "false"
  779. #intially set it to "CheckForAutoRemoves=false"
  780. #also delete multiple entries or what appears to be invalid entries
  781. sed -i '/.*CheckForAutoRemoves.*/Id' ~/.config/apt-notifierrc
  782. echo "CheckForAutoRemoves=false">> ~/.config/apt-notifierrc
  783. fi
  784.  
  785. #test if ~/.config/apt-notifierrc contains a IconLook=* line and that it's a valid entry
  786. grep -q -e ^"IconLook=wireframe" -e^"IconLook=classic" -e^"IconLook=pulse" ~/.config/apt-notifierrc
  787. if [ "$?" -eq 0 ]
  788. then
  789. #contains a valid entry so do nothing
  790. :
  791. else
  792. #
  793. #delete multiple entries or what appears to be invalid entries
  794. sed -i '/.*IconLook.*/Id' ~/.config/apt-notifierrc
  795. #
  796. #if a IconLook=* line not present,
  797. #or not equal to "wireframe" or "classic" or "pulse", then have default as follows for the various MX releases
  798. #
  799. case $(grep DISTRIB_RELEASE /etc/lsb-release | grep -Eo [0-9.]+ | head -n1) in
  800. 14 ) IconDefault="classic" ;;
  801. 15 ) IconDefault="classic" ;;
  802. 16 ) IconDefault="wireframe" ;;
  803. 16.1) IconDefault="wireframe" ;;
  804. 17 ) IconDefault="wireframe" ;;
  805. *) IconDefault="classic" ;;
  806. esac
  807. echo "IconLook=$IconDefault">> ~/.config/apt-notifierrc
  808. fi
  809.  
  810. #test to see if ~/.config/apt-notifierrc contains any blank lines or lines with only whitespace
  811. grep -q ^[[:space:]]*$ ~/.config/apt-notifierrc
  812. if [ "$?" = "0" ]
  813. then
  814. #cleanup any blank lines or lines with only whitespace
  815. sed -i '/^[[:space:]]*$/d' ~/.config/apt-notifierrc
  816. else
  817. #no blank lines or lines with only whitespace so do nothing
  818. :
  819. fi
  820.  
  821. #not really a preference, but remove obsolete *apt-notifier-menu.desktop files if present
  822. rm -f ~/.local/share/applications/apt-notifier-menu.desktop
  823. rm -f ~/.local/share/applications/mx-apt-notifier-menu.desktop
  824.  
  825. #also not a preference, but remove obsolete ~/.config/autostart/apt-notifier-autostart-xdg.desktop file if present
  826. rm -f ~/.config/autostart/apt-notifier-autostart-xdg.desktop
  827.  
  828. [ -e ~/.local/share/applications/mx-updater-menu-kde.desktop ] || cp /usr/share/applications/mx-updater-menu-kde.desktop ~/.local/share/applications/mx-updater-menu-kde.desktop
  829.  
  830. grep $(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=) ~/.local/share/applications/mx-updater-menu-kde.desktop -q
  831. [ $? -eq 0 ] || sed -i 's/mnotify-some.*/mnotify-some-'"$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)"'/' ~/.local/share/applications/mx-updater-menu-kde.desktop
  832.  
  833. [ -e ~/.local/share/applications/mx-updater-menu-non-kde.desktop ] || cp /usr/share/applications/mx-updater-menu-non-kde.desktop ~/.local/share/applications/mx-updater-menu-non-kde.desktop
  834.  
  835. grep $(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=) ~/.local/share/applications/mx-updater-menu-non-kde.desktop -q
  836. [ $? -eq 0 ] || sed -i 's/mnotify-some.*/mnotify-some-'"$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)"'/' ~/.local/share/applications/mx-updater-menu-non-kde.desktop
  837.  
  838. '''
  839.  
  840. script_file = tempfile.NamedTemporaryFile('wt')
  841. script_file.write(script)
  842. script_file.flush()
  843. run = subprocess.Popen(['bash %s' % script_file.name],shell=True).wait()
  844. script_file.close()
  845.  
  846.  
  847. def aptnotifier_prefs():
  848. global Check_for_Updates_by_User
  849. initialize_aptnotifier_prefs()
  850.  
  851. # ~~~ Localize 3 ~~~
  852.  
  853. t01 = _("MX Updater preferences")
  854. t02 = _("Upgrade mode")
  855. t03 = _("full upgrade (recommended)")
  856. t04 = _("basic upgrade")
  857. t05 = _("Left-click behaviour (when updates are available)")
  858. t06 = _("Other options")
  859. t07 = _("opens Synaptic")
  860. t08 = _("opens MX Updater 'View and Upgrade' window")
  861. t09 = _("Automatically answer 'yes' to all prompts during full/basic upgrade")
  862. t10 = _("automatically close terminal window when full/basic upgrade complete")
  863. t11 = _("check for autoremovable packages after full/basic upgrade")
  864. t12 = _("Icons")
  865. t13 = _("classic")
  866. t14 = _("pulse")
  867. t15 = _("wireframe")
  868. t16 = _("Auto-update")
  869. t17 = _("update automatically (will not add new or remove existing packages)")
  870. t18 = _("<b>Root privileges</b> are required to <b>enable</b> Auto Updates. Please enter <b>root's</b> password below.")
  871. t19 = _("<b>Root privileges</b> are required to <b>disable</b> Auto Updates. Please enter <b>root's</b> password below.")
  872.  
  873. shellvar = (
  874. ' window_title="' + t01 + '"\n'
  875. ' frame_upgrade_behaviour="' + t02 + '"\n'
  876. ' full_upgrade="' + t03 + '"\n'
  877. ' basic_upgrade="' + t04 + '"\n'
  878. ' frame_left_click_behaviour="' + t05 + '"\n'
  879. ' frame_other_options="' + t06 + '"\n'
  880. ' left_click_Synaptic="' + t07 + '"\n'
  881. ' left_click_ViewandUpgrade="' + t08 + '"\n'
  882. ' use_apt_get_dash_dash_yes="' + t09 + '"\n'
  883. ' auto_close_term_window_when_complete="' + t10 + '"\n'
  884. ' check_for_autoremoves="' + t11 + '"\n'
  885. ' frame_Icons="' + t12 + '"\n'
  886. ' label_classic="' + t13 + '"\n'
  887. ' label_pulse="' + t14 + '"\n'
  888. ' label_wireframe="' + t15 + '"\n'
  889. ' frame_Auto_update="' + t16 + '"\n'
  890. ' auto_update_checkbox_txt="' + t17 + '"\n'
  891. ' rootPasswordRequestMsgEnableAutoUpdates="' + t18 + '"\n'
  892. ' rootPasswordRequestMsgDisableAutoUpdates="' + t19 + '"\n'
  893. )
  894.  
  895. script = '''#! /bin/bash
  896. ''' + shellvar + '''
  897.  
  898. #for MEPIS remove "MX" branding from the $window_title and $left_click_ViewandUpgrade strings
  899. window_title=$(echo "$window_title"|sed 's/MX /'$(grep -o MX.*[1-9][0-9] /etc/issue|cut -c1-2)" "'/')
  900. left_click_ViewandUpgrade=$(echo "$left_click_ViewandUpgrade"|sed 's/MX /'$(grep -o MX.*[1-9][0-9] /etc/issue|cut -c1-2)" "'/')
  901. IconLookBegin=$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)
  902. TMP=$(mktemp -d /tmp/apt_notifier_preferences_dialog.XXXXXX)
  903. touch "$TMP"/output
  904. cat << EOF > "$TMP"/DIALOG
  905. <window title="@title@" icon-name="@mnotify-some@">
  906. <vbox>
  907. <frame @upgrade_behaviour@>
  908. <radiobutton active="@UpgradeBehaviourAptGetDistUpgrade@">
  909. <label>@full_upgrade@</label>
  910. <variable>UpgradeType_dist-upgrade</variable>
  911. <action>:</action>
  912. </radiobutton>
  913. <radiobutton active="@UpgradeBehaviourAptGetUpgrade@">
  914. <label>@basic_upgrade@</label>
  915. <variable>UpgradeType_upgrade</variable>
  916. <action>:</action>
  917. </radiobutton>
  918. </frame>
  919. <frame @leftclick_behaviour@>
  920. <radiobutton active="@LeftClickBehaviourSynaptic@">
  921. <label>@opens_Synaptic@</label>
  922. <variable>LeftClickSynaptic</variable>
  923. <action>:</action>
  924. </radiobutton>
  925. <radiobutton active="@LeftClickBehaviourViewAndUpgrade@">
  926. <label>@opens_View_and_Upgrade@</label>
  927. <variable>LeftClickViewAndUpgrade</variable>
  928. <action>:</action>
  929. </radiobutton>
  930. </frame>
  931. <frame @Other_options@>
  932. <checkbox active="@UpgradeAssumeYes@">
  933. <label>@use_apt_get_yes@</label>
  934. <variable>UpgradeAssumeYes</variable>
  935. <action>:</action>
  936. </checkbox>
  937. <checkbox active="@UpgradeAutoClose@">
  938. <label>@auto_close_term_window@</label>
  939. <variable>UpgradeAutoClose</variable>
  940. <action>:</action>
  941. </checkbox>
  942. <checkbox active="@CheckForAutoRemoves@">
  943. <label>@check_for_autoremoves@</label>
  944. <variable>CheckForAutoRemoves</variable>
  945. <action>:</action>
  946. </checkbox>
  947. </frame>
  948. <frame @Icons@>
  949. <hbox homogeneous="true">
  950. <vbox>
  951. <radiobutton active="@IconLookWireframe@">
  952. <label>@wireframe@</label>
  953. <variable>IconLook_wireframe</variable>
  954. <action>:</action>
  955. </radiobutton>
  956. <radiobutton active="@IconLookClassic@">
  957. <label>@classic@</label>
  958. <variable>IconLook_classic</variable>
  959. <action>:</action>
  960. </radiobutton>
  961. <radiobutton active="@IconLookPulse@">
  962. <label>@pulse@</label>
  963. <variable>IconLook_pulse</variable>
  964. <action>:</action>
  965. </radiobutton>
  966. </vbox>
  967. <vbox>
  968. <pixmap icon_size="2"><input file>"/usr/share/icons/mnotify-some-wireframe.png"</input></pixmap>
  969. <pixmap icon_size="2"><input file>"/usr/share/icons/mnotify-some-classic.png"</input></pixmap>
  970. <pixmap icon_size="2"><input file>"/usr/share/icons/mnotify-some-pulse.png"</input></pixmap>
  971. </vbox>
  972. <vbox>
  973. <pixmap icon_size="2"><input file>"/usr/share/icons/mnotify-none-wireframe.png"</input></pixmap>
  974. <pixmap icon_size="2"><input file>"/usr/share/icons/mnotify-none-classic.png"</input></pixmap>
  975. <pixmap icon_size="2"><input file>"/usr/share/icons/mnotify-none-pulse.png"</input></pixmap>
  976. </vbox>
  977. </hbox>
  978. </frame>
  979. <frame @Auto_update_label@>
  980. <checkbox active="@Auto_Update_setting@">
  981. <label>@autoupdate_checkboxtxt@</label>
  982. <variable>AutoUpdate</variable>
  983. <action>:</action>
  984. </checkbox>
  985. </frame>
  986. <hbox>
  987. <button ok></button>
  988. <button cancel></button>
  989. </hbox>
  990. </vbox>
  991. </window>
  992. EOF
  993.  
  994. cat << EOF > "$TMP"/enable_unattended_upgrades
  995. #!/bin/bash
  996. for i in @(grep 'APT::Periodic::Unattended-Upgrade "[0-9]+";' /etc/apt/apt.conf.d/* -E | cut -f1 -d: | grep -v ~$); \
  997. do sed -i 's/[ ]*APT::Periodic::Unattended-Upgrade.*"0".*;/ APT::Periodic::Unattended-Upgrade "1";/' @i; done
  998. exit 0
  999. EOF
  1000. sed -i 's/@/\$/g' "$TMP"/enable_unattended_upgrades
  1001.  
  1002. cat << EOF > "$TMP"/disable_unattended_upgrades
  1003. #!/bin/bash
  1004. for i in @(grep 'APT::Periodic::Unattended-Upgrade "[0-9]+*";' /etc/apt/apt.conf.d/* -E | cut -f1 -d: | grep -v ~$); \
  1005. do sed -i 's/[ ]*APT::Periodic::Unattended-Upgrade.*"1".*;/ APT::Periodic::Unattended-Upgrade "0";/' @i; done
  1006. exit 0
  1007. EOF
  1008. sed -i 's/@/\$/g' "$TMP"/disable_unattended_upgrades
  1009.  
  1010. # edit translateable strings placeholders in "$TMP"/DIALOG
  1011. sed -i 's/@title@/'"$window_title"'/' "$TMP"/DIALOG
  1012. sed -i 's/@upgrade_behaviour@/'"$frame_upgrade_behaviour"'/' "$TMP"/DIALOG
  1013. sed -i 's/@full_upgrade@/'"$full_upgrade"'/' "$TMP"/DIALOG
  1014. sed -i 's/@basic_upgrade@/'"$basic_upgrade"'/' "$TMP"/DIALOG
  1015. sed -i 's/@leftclick_behaviour@/'"$frame_left_click_behaviour"'/' "$TMP"/DIALOG
  1016. sed -i 's/@Other_options@/'"$frame_other_options"'/' "$TMP"/DIALOG
  1017. sed -i 's/@Icons@/'"$frame_Icons"'/' "$TMP"/DIALOG
  1018. sed -i 's/@opens_Synaptic@/"'"$left_click_Synaptic"'"/' "$TMP"/DIALOG
  1019. sed -i 's/@opens_View_and_Upgrade@/"'"$left_click_ViewandUpgrade"'"/' "$TMP"/DIALOG
  1020. sed -i 's|@use_apt_get_yes@|"'"$use_apt_get_dash_dash_yes"'"|' "$TMP"/DIALOG
  1021. sed -i 's|@auto_close_term_window@|"'"$auto_close_term_window_when_complete"'"|' "$TMP"/DIALOG
  1022. sed -i 's|@check_for_autoremoves@|"'"$check_for_autoremoves"'"|' "$TMP"/DIALOG
  1023. sed -i 's/@classic@/"'"$label_classic"'"/' "$TMP"/DIALOG
  1024. sed -i 's/@pulse@/"'"$label_pulse"'"/' "$TMP"/DIALOG
  1025. sed -i 's/@wireframe@/"'"$label_wireframe"'"/' "$TMP"/DIALOG
  1026.  
  1027. # edit placeholders in "$TMP"/DIALOG to set initial settings of the radiobuttons & checkboxes
  1028. sed -i 's/@UpgradeBehaviourAptGetUpgrade@/'$(if [ $(grep UpgradeType=upgrade ~/.config/apt-notifierrc) ]; then echo -n true; else echo -n false; fi)'/' "$TMP"/DIALOG
  1029. sed -i 's/@UpgradeBehaviourAptGetDistUpgrade@/'$(if [ $(grep UpgradeType=dist-upgrade ~/.config/apt-notifierrc) ]; then echo -n true; else echo -n false; fi)'/' "$TMP"/DIALOG
  1030. sed -i 's/@LeftClickBehaviourSynaptic@/'$(if [ $(grep LeftClick=Synaptic ~/.config/apt-notifierrc) ]; then echo -n true; else echo -n false; fi)'/' "$TMP"/DIALOG
  1031. sed -i 's/@LeftClickBehaviourViewAndUpgrade@/'$(if [ $(grep LeftClick=ViewAndUpgrade ~/.config/apt-notifierrc) ]; then echo -n true; else echo -n false; fi)'/' "$TMP"/DIALOG
  1032. sed -i 's/@UpgradeAssumeYes@/'$(grep UpgradeAssumeYes ~/.config/apt-notifierrc | cut -f2 -d=)'/' "$TMP"/DIALOG
  1033. sed -i 's/@UpgradeAutoClose@/'$(grep UpgradeAutoClose ~/.config/apt-notifierrc | cut -f2 -d=)'/' "$TMP"/DIALOG
  1034. sed -i 's/@CheckForAutoRemoves@/'$(grep CheckForAutoRemoves ~/.config/apt-notifierrc | cut -f2 -d=)'/' "$TMP"/DIALOG
  1035. sed -i 's/@IconLookWireframe@/'$(if [ $(grep IconLook=wireframe ~/.config/apt-notifierrc) ]; then echo -n true; else echo -n false; fi)'/' "$TMP"/DIALOG
  1036. sed -i 's/@IconLookClassic@/'$(if [ $(grep IconLook=classic ~/.config/apt-notifierrc) ]; then echo -n true; else echo -n false; fi)'/' "$TMP"/DIALOG
  1037. sed -i 's/@IconLookPulse@/'$(if [ $(grep IconLook=pulse ~/.config/apt-notifierrc) ]; then echo -n true; else echo -n false; fi)'/' "$TMP"/DIALOG
  1038.  
  1039. # edit placeholder for window icon placeholder in "$TMP"/DIALOG
  1040. sed -i 's/@mnotify-some@/mnotify-some-'$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d= | xargs echo -n)'/' "$TMP"/DIALOG
  1041.  
  1042. # edit AutoUpdate related translateable string placeholders in "$TMP"/DIALOG
  1043. sed -i 's/@Auto_update_label@/'"$frame_Auto_update"'/' "$TMP"/DIALOG
  1044. sed -i 's/@autoupdate_checkboxtxt@/'"$auto_update_checkbox_txt"'/' "$TMP"/DIALOG
  1045.  
  1046. # get what the Unattended-Upgrade status is before bringing up the preferences dialog
  1047. Unattended_Upgrade_before_pref_dialog=0
  1048. eval $(apt-config shell Unattended_Upgrade_before_pref_dialog APT::Periodic::Unattended-Upgrade)
  1049.  
  1050. # also use it to set the checkbox setting
  1051. if [ $Unattended_Upgrade_before_pref_dialog = "1" ]
  1052. then
  1053. sed -i 's/@Auto_Update_setting@/true/' "$TMP"/DIALOG
  1054. else
  1055. sed -i 's/@Auto_Update_setting@/false/' "$TMP"/DIALOG
  1056. fi
  1057.  
  1058. gtkdialog --file="$TMP"/DIALOG >> "$TMP"/output
  1059.  
  1060. grep -q EXIT=.*OK.* "$TMP"/output
  1061.  
  1062. if [ "$?" -eq 0 ];
  1063. then
  1064. if [ $(grep UpgradeType_upgrade=.*true.* "$TMP"/output) ]; then sed -i 's/UpgradeType=dist-upgrade/UpgradeType=upgrade/' ~/.config/apt-notifierrc; fi
  1065. if [ $(grep UpgradeType_dist-upgrade=.*true.* "$TMP"/output) ]; then sed -i 's/UpgradeType=upgrade/UpgradeType=dist-upgrade/' ~/.config/apt-notifierrc; fi
  1066. if [ $(grep LeftClickViewAndUpgrade=.*true.* "$TMP"/output) ]; then sed -i 's/LeftClick=Synaptic/LeftClick=ViewAndUpgrade/' ~/.config/apt-notifierrc; fi
  1067. if [ $(grep LeftClickSynaptic=.*true.* "$TMP"/output) ]; then sed -i 's/LeftClick=ViewAndUpgrade/LeftClick=Synaptic/' ~/.config/apt-notifierrc; fi
  1068. if [ $(grep UpgradeAssumeYes=.*false.* "$TMP"/output) ]; then sed -i 's/UpgradeAssumeYes=true/UpgradeAssumeYes=false/' ~/.config/apt-notifierrc; fi
  1069. if [ $(grep UpgradeAssumeYes=.*true.* "$TMP"/output) ]; then sed -i 's/UpgradeAssumeYes=false/UpgradeAssumeYes=true/' ~/.config/apt-notifierrc; fi
  1070. if [ $(grep UpgradeAutoClose=.*false.* "$TMP"/output) ]; then sed -i 's/UpgradeAutoClose=true/UpgradeAutoClose=false/' ~/.config/apt-notifierrc; fi
  1071. if [ $(grep UpgradeAutoClose=.*true.* "$TMP"/output) ]; then sed -i 's/UpgradeAutoClose=false/UpgradeAutoClose=true/' ~/.config/apt-notifierrc; fi
  1072. if [ $(grep CheckForAutoRemoves=.*false.* "$TMP"/output) ]; then sed -i 's/CheckForAutoRemoves=true/CheckForAutoRemoves=false/' ~/.config/apt-notifierrc; fi
  1073. if [ $(grep CheckForAutoRemoves=.*true.* "$TMP"/output) ]; then sed -i 's/CheckForAutoRemoves=false/CheckForAutoRemoves=true/' ~/.config/apt-notifierrc; fi
  1074. if [ $(grep IconLook_wireframe=.*true.* "$TMP"/output) ]; then sed -i 's/IconLook=classic/IconLook=wireframe/' ~/.config/apt-notifierrc; fi
  1075. if [ $(grep IconLook_wireframe=.*true.* "$TMP"/output) ]; then sed -i 's/IconLook=pulse/IconLook=wireframe/' ~/.config/apt-notifierrc; fi
  1076. if [ $(grep IconLook_classic=.*true.* "$TMP"/output) ]; then sed -i 's/IconLook=wireframe/IconLook=classic/' ~/.config/apt-notifierrc; fi
  1077. if [ $(grep IconLook_classic=.*true.* "$TMP"/output) ]; then sed -i 's/IconLook=pulse/IconLook=classic/' ~/.config/apt-notifierrc; fi
  1078. if [ $(grep IconLook_pulse=.*true.* "$TMP"/output) ]; then sed -i 's/IconLook=wireframe/IconLook=pulse/' ~/.config/apt-notifierrc; fi
  1079. if [ $(grep IconLook_pulse=.*true.* "$TMP"/output) ]; then sed -i 's/IconLook=classic/IconLook=pulse/' ~/.config/apt-notifierrc; fi
  1080. if [ $Unattended_Upgrade_before_pref_dialog = "0" ] && [ $(grep AutoUpdate=.*true.* "$TMP"/output) ]
  1081. then
  1082. gksu sh "$TMP"/enable_unattended_upgrades
  1083. fi
  1084. if [ $Unattended_Upgrade_before_pref_dialog = "1" ] && [ $(grep AutoUpdate=.*false.* "$TMP"/output) ]
  1085. then
  1086. gksu sh "$TMP"/disable_unattended_upgrades
  1087. fi
  1088. else
  1089. :
  1090. fi
  1091.  
  1092. rm -rf "$TMP"
  1093.  
  1094. #update Icon= line in .local mx-updater-menu-kde.desktop file if icon not same as IconLook config setting in ~/.config/apt-notifierrc file
  1095. grep $(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=) ~/.local/share/applications/mx-updater-menu-kde.desktop -q
  1096. [ $? -eq 0 ] || sed -i 's/mnotify-some.*/mnotify-some-'"$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)"'/' ~/.local/share/applications/mx-updater-menu-kde.desktop
  1097.  
  1098. #update Icon= line in .local mx-updater-menu-non-kde.desktop file if icon not same as IconLook config setting in ~/.config/apt-notifierrc file
  1099. grep $(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=) ~/.local/share/applications/mx-updater-menu-non-kde.desktop -q
  1100. [ $? -eq 0 ] || sed -i 's/mnotify-some.*/mnotify-some-'"$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)"'/' ~/.local/share/applications/mx-updater-menu-non-kde.desktop
  1101.  
  1102. #restart apt-notifier if IconLook setting has been changed
  1103. if [ "$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)" != "$IconLookBegin" ]
  1104. then
  1105. apt-notifier-unhide-Icon
  1106. fi
  1107.  
  1108. '''
  1109. script_file = tempfile.NamedTemporaryFile('wt')
  1110. script_file.write(script)
  1111. script_file.flush()
  1112. run = subprocess.Popen(['bash %s' % script_file.name],shell=True).wait()
  1113. script_file.close()
  1114. Check_for_Updates_by_User = 'true'
  1115. check_updates()
  1116.  
  1117. def apt_history():
  1118. global Check_for_Updates_by_User
  1119.  
  1120. # ~~~ Localize 5 ~~~
  1121.  
  1122. t01 = _("History")
  1123. shellvar = ' AptHistory="' + t01 + '"\n'
  1124.  
  1125. script = '''#! /bin/bash
  1126. ''' + shellvar + '''
  1127.  
  1128. TMP=$(mktemp -d /tmp/apt_history.XXXXXX)
  1129.  
  1130. apt-history | sed 's/:all/ all/;s/:i386/ i386/;s/:amd64/ amd64/' | column -t > "$TMP"/APT_HISTORY
  1131.  
  1132. yad --window-icon=/usr/share/icons/mnotify-some-"$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)".png \\
  1133. --width=$(xprop -root | grep _NET_DESKTOP_GEOMETRY\(CARDINAL\) | awk '{print $3*.75}' | cut -f1 -d.) \\
  1134. --height=480 \\
  1135. --center \\
  1136. --title "$AptHistory" \\
  1137. --text-info \\
  1138. --filename="$TMP"/APT_HISTORY \\
  1139. --fontname=mono \\
  1140. --button=gtk-close \\
  1141. --margins=7 \\
  1142. --borders=5
  1143.  
  1144. rm -rf "$TMP"
  1145.  
  1146. '''
  1147. script_file = tempfile.NamedTemporaryFile('wt')
  1148. script_file.write(script)
  1149. script_file.flush()
  1150. run = subprocess.Popen(['bash %s' % script_file.name],shell=True).wait()
  1151. script_file.close()
  1152. Check_for_Updates_by_User = 'true'
  1153. check_updates()
  1154.  
  1155. def apt_get_update():
  1156. global Check_for_Updates_by_User
  1157.  
  1158. # ~~~ Localize 4 ~~~
  1159.  
  1160. t01 = _("The action you requested needs <b>root privileges</b>. Please enter <b>root's</b> password below.")
  1161. t02 = _("Reload")
  1162. shellvar = ' rootPasswordRequestMsg="' + t01 + '"\n'
  1163. shellvar = ' reload="' + t02 + '"\n'
  1164.  
  1165. script = '''#! /bin/bash
  1166. ''' + shellvar + '''
  1167.  
  1168. #for MEPIS remove "MX" branding from the $window_title string
  1169. window_title=$(echo "$window_title"|sed 's/MX /'$(grep -o MX.*[1-9][0-9] /etc/issue|cut -c1-2)" "'/')
  1170.  
  1171. TermXOffset="$(xwininfo -root|awk '/Width/{print $2/4}')"
  1172. TermYOffset="$(xwininfo -root|awk '/Height/{print $2/4}')"
  1173. G=" --geometry=80x25+"$TermXOffset"+"$TermYOffset
  1174. I=" --icon=mnotify-some-""$(grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=)"
  1175. T=" --title='""$(grep -o MX.*[1-9][0-9] /etc/issue|cut -c1-2)"" Updater: $reload'"
  1176.  
  1177. case $(readlink -e /usr/bin/x-terminal-emulator | xargs basename) in
  1178.  
  1179. gnome-terminal.wrapper) gksu "gnome-terminal$G$T -e 'apt-get update'"
  1180. ;;
  1181.  
  1182. konsole) gksu "konsole -e apt-get update"
  1183. sleep 5
  1184. ;;
  1185.  
  1186. roxterm) gksu "roxterm$G$T --separate -e apt-get update"
  1187. ;;
  1188.  
  1189. xfce4-terminal.wrapper) gksu "xfce4-terminal$G$I$T -e 'apt-get update'"
  1190. ;;
  1191.  
  1192. xterm) gksu "xterm -e apt-get update"
  1193. ;;
  1194.  
  1195. *) gksu "x-terminal-emulator -e apt-get update"
  1196. ;;
  1197. esac
  1198.  
  1199.  
  1200. '''
  1201. script_file = tempfile.NamedTemporaryFile('wt')
  1202. script_file.write(script)
  1203. script_file.flush()
  1204. run = subprocess.Popen(['bash %s' % script_file.name],shell=True).wait()
  1205. script_file.close()
  1206. Check_for_Updates_by_User = 'true'
  1207. check_updates()
  1208.  
  1209. def re_enable_click():
  1210. global ignoreClick
  1211. ignoreClick = '0'
  1212.  
  1213. def start_synaptic0():
  1214. global ignoreClick
  1215. global Timer
  1216. if ignoreClick != '1':
  1217. start_synaptic()
  1218. ignoreClick = '1'
  1219. Timer.singleShot(50, re_enable_click)
  1220. else:
  1221. pass
  1222.  
  1223. def viewandupgrade0():
  1224. global ignoreClick
  1225. global Timer
  1226. if ignoreClick != '1':
  1227. viewandupgrade()
  1228. ignoreClick = '1'
  1229. Timer.singleShot(50, re_enable_click)
  1230. else:
  1231. pass
  1232.  
  1233. # Define the command to run when left clicking on the Tray Icon
  1234. def left_click():
  1235. if text.startswith( "0" ):
  1236. start_synaptic0()
  1237. else:
  1238. """Test ~/.config/apt-notifierrc for LeftClickViewAndUpgrade"""
  1239. command_string = "cat " + rc_file_name + " | grep -q LeftClick=ViewAndUpgrade"
  1240. exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
  1241. if exit_state == 0:
  1242. viewandupgrade0()
  1243. else:
  1244. start_synaptic0()
  1245.  
  1246. # Define the action when left clicking on Tray Icon
  1247. def left_click_activated(reason):
  1248. if reason == QtWidgets.QSystemTrayIcon.Trigger:
  1249. left_click()
  1250.  
  1251. def read_icon_config():
  1252. """Reads ~/.config/apt-notifierrc, returns 'show' if file doesn't exist or does not contain DontShowIcon"""
  1253. command_string = "cat " + rc_file_name + " | grep -q DontShowIcon"
  1254. exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
  1255. if exit_state != 0:
  1256. return "show"
  1257.  
  1258. def read_icon_look():
  1259. script = '''#! /bin/bash
  1260. grep IconLook ~/.config/apt-notifierrc | cut -f2 -d=
  1261. '''
  1262. script_file = tempfile.NamedTemporaryFile('wt')
  1263. script_file.write(script)
  1264. script_file.flush()
  1265. run = subprocess.Popen(["echo -n `bash %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
  1266. # Read the output into a text string
  1267. iconLook = run.stdout.read(128)
  1268. script_file.close()
  1269. return iconLook
  1270.  
  1271. def set_noicon():
  1272. """Reads ~/.config/apt-notifierrc. If "DontShowIcon blah blah blah" is already there, don't write it again"""
  1273. command_string = "cat " + rc_file_name + " | grep -q DontShowIcon"
  1274. exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
  1275. if exit_state != 0:
  1276. file = open(rc_file_name, 'a')
  1277. file.write ('[DontShowIcon] #Remove this entry if you want the apt-notify icon to show even when there are no upgrades available\n')
  1278. file.close()
  1279. subprocess.call(["/usr/bin/apt-notifier"], shell=True, stdout=subprocess.PIPE)
  1280. AptIcon.hide()
  1281. icon_config = "donot show"
  1282.  
  1283. def add_rightclick_actions():
  1284. ActionsMenu.clear()
  1285. """Test ~/.config/apt-notifierrc for LeftClickViewAndUpgrade"""
  1286. command_string = "cat " + rc_file_name + " | grep -q LeftClick=ViewAndUpgrade"
  1287. exit_state = subprocess.call([command_string], shell=True, stdout=subprocess.PIPE)
  1288. if exit_state == 0:
  1289. ActionsMenu.addAction(View_and_Upgrade).triggered.connect( viewandupgrade0 )
  1290. ActionsMenu.addSeparator()
  1291. ActionsMenu.addAction(Upgrade_using_Synaptic).triggered.connect( start_synaptic0 )
  1292. else:
  1293. ActionsMenu.addAction(Upgrade_using_Synaptic).triggered.connect( start_synaptic0)
  1294. ActionsMenu.addSeparator()
  1295. ActionsMenu.addAction(View_and_Upgrade).triggered.connect( viewandupgrade0 )
  1296. add_apt_history_action()
  1297. add_apt_get_update_action()
  1298. add_apt_notifier_help_action()
  1299. add_synaptic_help_action()
  1300. add_aptnotifier_prefs_action()
  1301. add_quit_action()
  1302.  
  1303. def add_hide_action():
  1304. ActionsMenu.clear()
  1305. if icon_config == "show":
  1306. hide_action = ActionsMenu.addAction(Hide_until_updates_available)
  1307. hide_action.triggered.connect( set_noicon )
  1308. ActionsMenu.addSeparator()
  1309. ActionsMenu.addAction(u"Synaptic").triggered.connect( start_synaptic0 )
  1310. add_apt_history_action()
  1311. add_apt_get_update_action()
  1312. add_apt_notifier_help_action()
  1313. add_synaptic_help_action()
  1314. add_aptnotifier_prefs_action()
  1315. add_quit_action()
  1316.  
  1317. def add_quit_action():
  1318. ActionsMenu.addSeparator()
  1319. quit_action = ActionsMenu.addAction(QuitIcon,Quit_Apt_Notifier)
  1320. quit_action.triggered.connect( exit )
  1321.  
  1322. def add_apt_notifier_help_action():
  1323. ActionsMenu.addSeparator()
  1324. apt_notifier_help_action = ActionsMenu.addAction(HelpIcon,Apt_Notifier_Help)
  1325. apt_notifier_help_action.triggered.connect(open_apt_notifier_help)
  1326.  
  1327. def open_apt_notifier_help():
  1328. script = '''#! /bin/bash
  1329. case $(echo $LANG | cut -f1 -d_) in
  1330. fr) HelpUrl="https://mxlinux.org/wiki/help-files/help-mx-apt-notifier-notificateur-dapt" ;;
  1331. *) HelpUrl="https://mxlinux.org/wiki/help-files/help-mx-apt-notifier" ;;
  1332. esac
  1333. test -e /usr/bin/mx-viewer
  1334. if [ $? -eq 0 ]
  1335. then
  1336. mx-viewer $HelpUrl
  1337. else
  1338. xdg-open $HelpUrl
  1339. fi
  1340. '''
  1341. script_file = tempfile.NamedTemporaryFile('wt')
  1342. script_file.write(script)
  1343. script_file.flush()
  1344. run = subprocess.Popen(["echo -n `bash %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
  1345. run.stdout.read(128)
  1346. script_file.close()
  1347.  
  1348. def add_synaptic_help_action():
  1349. ActionsMenu.addSeparator()
  1350. synaptic_help_action = ActionsMenu.addAction(HelpIcon,Synaptic_Help)
  1351. synaptic_help_action.triggered.connect(open_synaptic_help)
  1352.  
  1353. def open_synaptic_help():
  1354. script = '''#! /bin/bash
  1355. HelpUrlBase="https://mxlinux.org/wiki/help-files/help-synaptic"
  1356. #english HelpUrl = HelpUrlBase
  1357. #non-english HelpUrl = HelpUrlBase + "-" + "{2 character suffix - de, es, fr, it, etc.}"
  1358. case $(echo $LANG | cut -f1 -d_) in
  1359. en) HelpUrl="$HelpUrlBase" ;;
  1360. *) HelpUrl="$HelpUrlBase""-""$(echo $LANG | cut -f1 -d_)" ;;
  1361. esac
  1362. #test to see if HelpUrl page exists, if it doesn't change it to HelpUrlBase (english version)
  1363. wget $HelpUrl --spider -q
  1364. if [ $? -eq 0 ]
  1365. then :
  1366. else HelpUrl="$HelpUrlBase"
  1367. fi
  1368. #test to see if pdf or html (a 0 result = pdf)
  1369. echo $HelpUrl | grep \.pdf -q
  1370. if [ $? -eq 0 ]
  1371. then
  1372. TMP=$(mktemp -d /tmp/synaptic_help.XXXXXX)
  1373. curl $HelpUrl -o "$TMP"/$(basename $HelpUrl)
  1374. qpdfview "$TMP"/$(basename $HelpUrl)#$SynapticPage
  1375. rm -rf "$TMP"
  1376. else
  1377. test -e /usr/bin/mx-viewer
  1378. if [ $? -eq 0 ]
  1379. then
  1380. mx-viewer $HelpUrl
  1381. else
  1382. xdg-open $HelpUrl
  1383. fi
  1384. fi
  1385. '''
  1386. script_file = tempfile.NamedTemporaryFile('wt')
  1387. script_file.write(script)
  1388. script_file.flush()
  1389. run = subprocess.Popen(["echo -n `bash %s`" % script_file.name],shell=True, stdout=subprocess.PIPE)
  1390. run.stdout.read(128)
  1391. script_file.close()
  1392.  
  1393. def add_aptnotifier_prefs_action():
  1394. ActionsMenu.addSeparator()
  1395. aptnotifier_prefs_action = ActionsMenu.addAction(Apt_Notifier_Preferences)
  1396. aptnotifier_prefs_action.triggered.connect( aptnotifier_prefs )
  1397.  
  1398. def add_apt_history_action():
  1399. ActionsMenu.addSeparator()
  1400. apt_history_action = ActionsMenu.addAction(Apt_History)
  1401. apt_history_action.triggered.connect( apt_history )
  1402.  
  1403. def add_apt_get_update_action():
  1404. ActionsMenu.addSeparator()
  1405. apt_get_update_action = ActionsMenu.addAction(Check_for_Updates)
  1406. apt_get_update_action.triggered.connect( apt_get_update )
  1407.  
  1408. # General application code
  1409. def main():
  1410. # Define Core objects, Tray icon and QTimer
  1411. global AptNotify
  1412. global AptIcon
  1413. global QuitIcon
  1414. global icon_config
  1415. global quit_action
  1416. global Timer
  1417. global initialize_aptnotifier_prefs
  1418. global read_icon_look
  1419. global icon_set
  1420.  
  1421. set_translations()
  1422. initialize_aptnotifier_prefs()
  1423. AptNotify = QtWidgets.QApplication(sys.argv)
  1424. AptIcon = QtWidgets.QSystemTrayIcon()
  1425. Timer = QtCore.QTimer()
  1426. icon_config = read_icon_config()
  1427. # Define the icons:
  1428. global NoUpdatesIcon
  1429. global NewUpdatesIcon
  1430. global HelpIcon
  1431.  
  1432. # read in icon look into a variable
  1433. icon_set = read_icon_look()
  1434.  
  1435. NoUpdatesIcon = QtGui.QIcon("/usr/share/icons/mnotify-none-" + icon_set + ".png")
  1436. NewUpdatesIcon = QtGui.QIcon("/usr/share/icons/mnotify-some-" + icon_set + ".png")
  1437. HelpIcon = QtGui.QIcon("/usr/share/icons/oxygen/22x22/apps/help-browser.png")
  1438. QuitIcon = QtGui.QIcon("/usr/share/icons/oxygen/22x22/actions/system-shutdown.png")
  1439. # Create the right-click menu and add the Tooltip text
  1440. global ActionsMenu
  1441. ActionsMenu = QtWidgets.QMenu()
  1442. AptIcon.activated.connect( left_click_activated )
  1443. Timer.timeout.connect( check_updates )
  1444. # Integrate it together,apply checking of updated packages and set timer to every 1 minute(s) (1 second = 1000)
  1445. AptIcon.setIcon(NoUpdatesIcon)
  1446. AptIcon.setContextMenu(ActionsMenu)
  1447. if icon_config == "show":
  1448. AptIcon.show()
  1449. check_updates()
  1450. Timer.start(60000)
  1451. if AptNotify.isSessionRestored():
  1452. sys.exit(1)
  1453. sys.exit(AptNotify.exec_())
  1454.  
  1455. if __name__ == '__main__':
  1456. main()
Add Comment
Please, Sign In to add comment