Skip to content

Instantly share code, notes, and snippets.

@ski7777
Created May 5, 2016 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ski7777/b21581171d255dd4a68509ce070e179b to your computer and use it in GitHub Desktop.
Save ski7777/b21581171d255dd4a68509ce070e179b to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
import sys, os, os.path, time, urllib.request, json
#from PyQt4.QtNetwork import *
#from TxtStyle import *
downloadzip = "update.zip"
sdcardbase = "/media/sdcard/"
extractdir = "update_extract"
olddir = "update_rollback"
required_file = "rootfs.img"
curreentver = os.popen("cat /etc/fw-ver.txt").read()
#Cleanup files
os.system("rm " + sdcardbase + extractdir + "/*")
os.system("rm " + sdcardbase + downloadzip)
#create Folders
os.system("mkdir " + sdcardbase + olddir)
os.system("mkdir " + sdcardbase + extractdir)
#check whether simple layout is used
required_file_exsits = os.path.exists(sdcardbase + required_file)
raw_data = urllib.request.urlopen('https://api.github.com/repos/ftCommunity/ftcommunity-TXT/releases').read().decode()
all_releases = json.loads(raw_data)
##filter out to latest release
latest_release = all_releases[0]
##Getting version number
release_version = latest_release['tag_name']
release_version = release_version.replace("v","")
print ("Repo version" + release_version)
##Getting download link
assets = latest_release['assets']
assets_count = -1
content_type = ''
while content_type != 'application/zip':
assets_count = int(assets_count) + 1
#if assets_count > (len(assets) + 1):
# print("No valid download link found! Contact the developer!")
# exit(0x01a)
file_info = assets[assets_count]
content_type = file_info['content_type']
dl_link = file_info['browser_download_url']
#print('assets_count: ' + str(assets_count))
#print('DL: ' + dl_link)
if required_file_exsits != True:
print ("Abort! No simple Layout")
exit("Abort! No simple Layout")
#check whether we use the current version
if release_version != curreentver:
print ("Update")
os.system("wget -O " + sdcardbase + downloadzip + " --no-check-certificate " + dl_link)
print ("This can take a wile! Go and grep a coffe")
os.system("unzip " + sdcardbase + downloadzip + " -d " + sdcardbase + extractdir)
os.system("mv " + sdcardbase + "am335x-kno_txt.dtb" + " " + sdcardbase + olddir + "/am335x-kno_txt.dtb")
os.system("mv " + sdcardbase + "rootfs.img" + " " + sdcardbase + olddir + "/rootfs.img")
os.system("mv " + sdcardbase + "uImage" + " " + sdcardbase + olddir + "/uImage")
os.system("mv " + sdcardbase + extractdir + "/am335x-kno_txt.dtb" + " " + sdcardbase + "am335x-kno_txt.dtb")
os.system("mv " + sdcardbase + extractdir + "/rootfs.img" + " " + sdcardbase + "rootfs.img")
os.system("mv " + sdcardbase + extractdir + "/uImage" + " " + sdcardbase + "uImage")
print ("Update finished! TXT will reboot soon!")
time.sleep (1.5)
os.system("/sbin/poweroff")
os.system('/bin/echo "msg Shutting down... When the blue light switches off boot the TXT again!" | /usr/bin/nc localhost 9000')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment