Created
August 19, 2024 07:21
-
-
Save Avaray/d918f6d46e73f6b2b23f3ba8e0b00f9f to your computer and use it in GitHub Desktop.
Nano Editor Updater for RaspberryPi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # WORKS ON PYTHON 3.7.3 | |
| # DOESN'T WORK ON PYTHON 3.10.2 BECAUSE OF SSL IN URLLIB LIBRARY | |
| # IT SEEMS PYTHON MUST BE COMPILED WITH OPENSSL (?) | |
| import os | |
| import re | |
| import urllib.request | |
| from datetime import datetime | |
| CWD = os.path.dirname(os.path.abspath(__file__)) | |
| LOG = CWD + '/' + os.path.basename(__file__).replace(".py", ".log") | |
| os.chdir(CWD) | |
| response = re.search(r"(?<=href=\")\/dist\/.+?(?=\">)", str(urllib.request.urlopen('https://www.nano-editor.org/download.php').read()))[0] | |
| REMOTE_DOWNLOAD = 'https://www.nano-editor.org' + response | |
| REMOTE_FILENAME = REMOTE_DOWNLOAD.split('/')[-1] | |
| REMOTE_VERSION = re.search(r"(?<=nano-)[\d.]+(?=\.tar\.xz)", REMOTE_DOWNLOAD)[0] | |
| LOCAL_VERSION = re.search(r"(?<=version\s)[\d.]+(?=\n?)", os.popen('/usr/local/bin/nano -V').read())[0] | |
| def CLEAN(): | |
| os.system('sudo rm nano-*.tar.xz*') | |
| os.system('sudo rm -rf nano-*/') | |
| if REMOTE_VERSION != LOCAL_VERSION: | |
| print('New version available! (Local: ' + LOCAL_VERSION + ' | Remote: ' + REMOTE_VERSION + ')') | |
| print('Trying to install ncurses...') | |
| os.system('sudo apt-get install libncursesw5-dev -y') | |
| print('Removing existing Nano archives...') | |
| CLEAN() | |
| print('Downloading Nano ' + REMOTE_VERSION + '...') | |
| os.system('wget -q ' + REMOTE_DOWNLOAD) | |
| print('Extracting Nano archive...') | |
| os.system('tar -xvf ' + REMOTE_FILENAME) | |
| print('Installing Nano...') | |
| os.chdir(os.path.normpath(CWD + '/' + REMOTE_FILENAME.replace('.tar.xz', '/'))) | |
| os.system('sudo ./configure') | |
| os.system('sudo make') | |
| os.system('sudo make install') | |
| os.chdir(CWD) | |
| print('Removing extracted files...') | |
| CLEAN() | |
| print('Installing nanorc (syntax highlighting)...') | |
| os.system('curl https://raw.githubusercontent.com/scopatz/nanorc/master/install.sh | sh') | |
| if re.search(r"(?<=version\s)[\d.]+(?=\n?)", os.popen('/usr/local/bin/nano -V').read())[0] == REMOTE_VERSION: | |
| print('Nano ' + REMOTE_VERSION + ' installed successfully!') | |
| print('Logging to ' + LOG) | |
| with open(LOG, 'a') as f: | |
| f.write(datetime.now().strftime('%G%m%d%H%M%S') + ' | Nano ' + REMOTE_VERSION + ' installed successfully!\n') | |
| else: | |
| with open(LOG, 'a') as f: | |
| f.write(datetime.now().strftime('%G%m%d%H%M%S') + ' | Nano ' + REMOTE_VERSION + ' installation weird. Versions doesn\'t match\n') | |
| else: | |
| print('Nano is up to date (Local: ' + LOCAL_VERSION + ' | Remote: ' + REMOTE_VERSION + ')') | |
| exit() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm backing up my old script here, because I wan't to delete repo.