|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +#********************************************************************************** |
| 5 | +#* * |
| 6 | +#* Google Chrome The Latest * |
| 7 | +#* ------------------------------------------------------------ * |
| 8 | +#* * |
| 9 | +#********************************************************************************** |
| 10 | +# Copyright 2022 Antonio Leal, Porto Salvo, Portugal |
| 11 | +# All rights reserved. |
| 12 | +# |
| 13 | +# Redistribution and use of this script, with or without modification, is |
| 14 | +# permitted provided that the following conditions are met: |
| 15 | +# |
| 16 | +# 1. Redistributions of this script must retain the above copyright |
| 17 | +# notice, this list of conditions and the following disclaimer. |
| 18 | +# |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED |
| 20 | +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 22 | +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 24 | +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 25 | +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 27 | +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 28 | +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | +# $Id:$ |
| 30 | + |
| 31 | +import os |
| 32 | +import time |
| 33 | +import sys |
| 34 | +import xml.etree.ElementTree as ET |
| 35 | +import tkinter as tk |
| 36 | +from tkinter import messagebox |
| 37 | + |
| 38 | +DOWNLOAD_LINK = 'https://dl.google.com/linux/direct' |
| 39 | +DOWNLOAD_FILE = 'google-chrome-stable_current_x86_64.rpm' |
| 40 | +TXZ_FILE = DOWNLOAD_FILE[:-3] + 'txz' |
| 41 | +LASTRUN = '/opt/google-chrome-the-latest/lastrun' |
| 42 | + |
| 43 | +# Check if you are root |
| 44 | +if os.geteuid() != 0: |
| 45 | + print('You must run this script as root.') |
| 46 | + exit(0) |
| 47 | + |
| 48 | +# Only run once a day, even though we set cron.hourly |
| 49 | +if os.path.exists(LASTRUN): |
| 50 | + ti_m = os.path.getmtime(LASTRUN) |
| 51 | + ti_n = time.time() |
| 52 | + if (ti_n - ti_m) < 86400: |
| 53 | + exit(0) |
| 54 | +os.system('touch %s' % LASTRUN) |
| 55 | + |
| 56 | +# Check the web for latest Chrome version. |
| 57 | +# We are expecting sometning like: |
| 58 | +# xmlstr = """ |
| 59 | +# <tr> |
| 60 | + # <td>Chrome on <strong>Linux</strong></td> |
| 61 | + # <td>107.0.5304.121</td> |
| 62 | + # <td>2022-11-25</td> |
| 63 | +# </tr> |
| 64 | +# """ |
| 65 | +xmlstr=os.popen('curl -s https://www.whatismybrowser.com/guides/the-latest-version/chrome | grep -B 1 -A 3 "<td>Chrome on <strong>Linux</strong></td>"').read() |
| 66 | +root = ET.fromstring(xmlstr) |
| 67 | +latest_version = root[1].text.strip() |
| 68 | + |
| 69 | +# Check the current installed version, if there is one... |
| 70 | +try: |
| 71 | + current_version = os.popen('google-chrome-stable --version').read().split()[2] |
| 72 | +except: |
| 73 | + current_version = 'not found' |
| 74 | + |
| 75 | +# And if these versions are different upgrade... |
| 76 | +if current_version != latest_version: |
| 77 | + dialog = tk.Tk() |
| 78 | + dialog.withdraw() |
| 79 | + msg = """Hey, there is a new Google Chrome release! |
| 80 | +
|
| 81 | +Your version: %s |
| 82 | +New version : %s |
| 83 | +
|
| 84 | +Do you want to install it?""" % (current_version, latest_version) |
| 85 | + silent = False |
| 86 | + if len(sys.argv) == 2: |
| 87 | + if sys.argv[1].upper() == 'SILENT': |
| 88 | + silent = True |
| 89 | + if not silent: |
| 90 | + yesno = messagebox.askyesno(title='Chrome, the latest', message=msg) |
| 91 | + dialog.destroy() |
| 92 | + else: |
| 93 | + yesno = True |
| 94 | + if yesno: |
| 95 | + INSTALL_FILE = 'google-chrome-%s-x86_64-1.txz' % latest_version |
| 96 | + os.chdir('/tmp') |
| 97 | + os.system('rm -rf %s %s %s' % (DOWNLOAD_FILE, TXZ_FILE, INSTALL_FILE)) |
| 98 | + os.system('/usr/bin/wget %s/%s' % (DOWNLOAD_LINK, DOWNLOAD_FILE)) |
| 99 | + os.system('/usr/bin/rpm2txz %s' % DOWNLOAD_FILE) |
| 100 | + os.system('mv %s %s' % (TXZ_FILE, INSTALL_FILE)) |
| 101 | + os.system('/sbin/upgradepkg --install-new %s' % INSTALL_FILE) |
| 102 | + os.system('rm -rf %s %s %s' % (DOWNLOAD_FILE, TXZ_FILE, INSTALL_FILE)) |
| 103 | + |
| 104 | + if not silent: |
| 105 | + dialog = tk.Tk() |
| 106 | + dialog.withdraw() |
| 107 | + messagebox.showinfo("Done","Google Chrome is now at version %s" % latest_version) |
0 commit comments