Compare commits

9 Commits

Author SHA1 Message Date
ilgiaco
860c870ac0 Fixed syntax error 2019-07-28 12:06:33 +02:00
Michele Giacomoli
4c57479e6a Added AUTHORS file 2019-06-25 19:34:51 +02:00
Michele Giacomoli
3c0c0c5288 Added Scratch and Air checksums 2019-06-24 23:48:16 +02:00
Michele Giacomoli
821411dbe6 Ensure /opt exists 2019-06-24 23:07:21 +02:00
Michele Giacomoli
636b1a21b2 Merge branch 'master' into new-procedure 2019-06-19 23:20:30 +02:00
Michele Giacomoli
4d08604828 Removed air-wrapper from code 2019-06-17 19:20:54 +02:00
Michele Giacomoli
ddd7d1be65 Do apt-get update before installing 2019-06-17 19:11:50 +02:00
Michele Giacomoli
36065b7dc1 air-wrapper is no more needed (still required in GUI) 2019-06-17 19:02:28 +02:00
Michele Giacomoli
49ca81b662 New install procedure with Air SDK 2019-06-17 19:01:14 +02:00
2 changed files with 97 additions and 29 deletions

2
AUTHORS Normal file
View File

@@ -0,0 +1,2 @@
Stefano Salvi <stefano@salvi.mn.it>
Michele Giacomoli <michele.giacomoli@gmail.com>

View File

@@ -1,8 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Luglio 2018 - Stefano Salvi stefano@salvi.mn.it
#
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
@@ -65,20 +63,41 @@
## libasound.so ## libasound.so
## ##
import argparse
import errno
import gi import gi
import os, errno import hashlib
import os
import os.path import os.path
import sys import sys
import threading import threading
import urllib.request import urllib.request
import time
import re import re
import shlex
import shutil
import subprocess import subprocess
import argparse
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gtk, Gdk, GObject from gi.repository import GLib, Gtk, Gdk, GObject
DESKTOP_FILE = '''[Desktop Entry]
Type=Application
Name=Scratch 2
Comment=Ide visuale per bambini
Exec=/opt/adobe-air-sdk/bin/adl -nodebug /opt/adobe-air-sdk/scratch/META-INF/AIR/application.xml /opt/adobe-air-sdk/scratch
Icon=/opt/adobe-air-sdk/scratch/icons/AppIcon128.png
Terminal=false
NoDisplay=false
StartupNotify=true
Categories=Development;
Keywords=ide;coding;
MimeType=application/x-scratch-project;
'''
AIR_SHA256 = "58912fc6797bcbab49de1f4accb4743a72e7b20384bae1babf9242ac88007501"
SCRATCH_VERSION = "458.0.1"
SCRATCH_SHA256 = "b48abfae6e29d112986e7870bacd15ba5cbd67c1e28dcec1bc2d7dfe00a5a56d"
class ShowActionDialog(Gtk.Dialog): class ShowActionDialog(Gtk.Dialog):
def __init__(self, parent, message): def __init__(self, parent, message):
Gtk.Dialog.__init__(self, "Installazione", parent, 0) Gtk.Dialog.__init__(self, "Installazione", parent, 0)
@@ -118,7 +137,7 @@ class MyWindow(Gtk.Window):
self.add(vbox) self.add(vbox)
frame = Gtk.Frame(); frame = Gtk.Frame();
frame.set_label("Adobe AIR") frame.set_label("Adobe AIR SDK")
vbox1 = Gtk.Box(orientation='vertical',spacing=6) vbox1 = Gtk.Box(orientation='vertical',spacing=6)
frame.add(vbox1) frame.add(vbox1)
vbox.pack_start(frame, False, False, 0) vbox.pack_start(frame, False, False, 0)
@@ -135,10 +154,10 @@ class MyWindow(Gtk.Window):
hbox.pack_start(airFromDisk, False, False, 0) hbox.pack_start(airFromDisk, False, False, 0)
filter = Gtk.FileFilter() filter = Gtk.FileFilter()
filter.set_name("bin files") filter.set_name("tbz2 files")
filter.add_pattern("*.bin") filter.add_pattern("*.tbz2")
self.fileButtonAir = Gtk.FileChooserButton (); self.fileButtonAir = Gtk.FileChooserButton ();
self.fileButtonAir.set_title("Seleziona l'installer di Adobe Air") self.fileButtonAir.set_title("Seleziona l'SDK di Adobe Air")
self.fileButtonAir.add_filter(filter) self.fileButtonAir.add_filter(filter)
self.fileButtonAir.set_current_folder(self.tempdir) self.fileButtonAir.set_current_folder(self.tempdir)
self.fileButtonAir.set_sensitive(False) self.fileButtonAir.set_sensitive(False)
@@ -154,7 +173,7 @@ class MyWindow(Gtk.Window):
vbox1.pack_start(hbox, False, False, 0) vbox1.pack_start(hbox, False, False, 0)
self.scratchFromNet = Gtk.RadioButton.new_with_label_from_widget(None, "Scarica dalla rete") self.scratchFromNet = Gtk.RadioButton.new_with_label_from_widget(None, "Scarica dalla rete")
self.scratchFromNet.connect("toggled", self.on_sctarch_button_toggled) self.scratchFromNet.connect("toggled", self.on_scratch_button_toggled)
hbox.pack_start(self.scratchFromNet, False, False, 0) hbox.pack_start(self.scratchFromNet, False, False, 0)
scratchFromFile = Gtk.RadioButton.new_with_label_from_widget(self.scratchFromNet, "Installa da file") scratchFromFile = Gtk.RadioButton.new_with_label_from_widget(self.scratchFromNet, "Installa da file")
@@ -186,7 +205,7 @@ class MyWindow(Gtk.Window):
def on_air_button_toggled (self, button): def on_air_button_toggled (self, button):
self.fileButtonAir.set_sensitive(not button.get_active()) self.fileButtonAir.set_sensitive(not button.get_active())
def on_sctarch_button_toggled (self, button): def on_scratch_button_toggled (self, button):
self.fileButtonScratch.set_sensitive(not button.get_active()) self.fileButtonScratch.set_sensitive(not button.get_active())
def error_message(self, message, isinfo = False): def error_message(self, message, isinfo = False):
@@ -258,6 +277,9 @@ class MyWindow(Gtk.Window):
return False return False
return True return True
def check_sha256(self, filename, hash):
return hashlib.sha256(contents).hexdigest() == hash
def get_url(self, url, basemessage): def get_url(self, url, basemessage):
GLib.idle_add(self.show_action_message, basemessage) GLib.idle_add(self.show_action_message, basemessage)
message = ""; message = "";
@@ -288,14 +310,26 @@ class MyWindow(Gtk.Window):
if self.airFromNet.get_active(): if self.airFromNet.get_active():
if not self.create_scratch_downoad_directory(): if not self.create_scratch_downoad_directory():
return False return False
self.air_installer_file = self.tempdir + "/AdobeAIRInstaller.bin" self.air_installer_file = self.tempdir + "/AdobeAIRSDK.tbz2"
return self.download_file("http://airdownload.adobe.com/air/lin/download/2.6/AdobeAIRInstaller.bin" ,self.air_installer_file ,"Scarico Adobe Air dalla rete") if not self.download_file("http://airdownload.adobe.com/air/lin/download/2.6/AdobeAIRSDK.tbz2" ,self.air_installer_file ,"Scarico Adobe Air dalla rete"):
return False
Glib.idle_add(self.show_action_message, "Verifica checksum file AIR")
if not self.check_sha256(self.scrathFile, SCRATCH_SHA256):
Glib.idle_add(self.error_message, "Verifica checksum file AIR: FAIL!")
return False
Glib.idle_add(self.append_action_message, "Verifica checksum file AIR: OK")
return True
else: else:
self.air_installer_file = self.fileButtonAir.get_filename() self.air_installer_file = self.fileButtonAir.get_filename()
if self.air_installer_file == None: if self.air_installer_file == None:
GLib.idle_add(self.error_message, "Non hai scelto il file con il pacchetto AIR di Scratch") GLib.idle_add(self.error_message, "Non hai scelto il file con il file AIR SDK")
return False return False
else: else:
Glib.idle_add(self.show_action_message, "Verifica checksum file Scratch")
if not self.check_sha256(self.scrathFile, SCRATCH_SHA256):
Glib.idle_add(self.error_message, "Verifica checksum file Scratch: FAIL!")
return False
Glib.idle_add(self.append_action_message, "Verifica checksum file Scratch: OK")
GLib.idle_add(self.show_action_message, "Installo Air dal file" + self.air_installer_file) GLib.idle_add(self.show_action_message, "Installo Air dal file" + self.air_installer_file)
return True return True
@@ -313,15 +347,27 @@ class MyWindow(Gtk.Window):
# GLib.idle_add(self.show_action_message, "Installo la versione " + m.group(1) + " dall'indirizzo " + m.group(2)) # GLib.idle_add(self.show_action_message, "Installo la versione " + m.group(1) + " dall'indirizzo " + m.group(2))
# self.scrathFile = self.tempdir + "/" + m.group(2).split('/')[-1] # self.scrathFile = self.tempdir + "/" + m.group(2).split('/')[-1]
# return self.download_file(m.group(2), self.scrathFile,"Scarico Scratch 2 dalla rete") # return self.download_file(m.group(2), self.scrathFile,"Scarico Scratch 2 dalla rete")
GLib.idle_add(self.show_action_message, "Installo la versione 442 Di Scratch 2") GLib.idle_add(self.show_action_message, "Installo la versione 458 Di Scratch 2")
self.scrathFile = self.tempdir + "/Scratch-455.air" self.scrathFile = self.tempdir + "/Scratch-458.0.1.air"
return self.download_file("http://cdn.scratch.mit.edu/scratchr2/static/sa/Scratch-455.air", self.scrathFile, "Scarico Scratch 2 dalla rete") if not self.download_file("https://scratch.mit.edu/scratchr2/static/sa/Scratch-458.0.1.air", self.scrathFile, "Scarico Scratch 2 dalla rete"):
return False
Glib.idle_add(self.show_action_message, "Verifica checksum file Scratch")
if not self.check_sha256(self.scrathFile, SCRATCH_SHA256):
Glib.idle_add(self.error_message, "Verifica checksum file Scratch: FAIL!")
return False
Glib.idle_add(self.append_action_message, "Verifica checksum file Scratch: OK")
return True
else: else:
self.scrathFile = self.fileButtonScratch.get_filename() self.scrathFile = self.fileButtonScratch.get_filename()
if self.scrathFile == None: if self.scrathFile == None:
GLib.idle_add(self.error_message, "Non hai scelto il file con il pacchetto AIR di Scratch") GLib.idle_add(self.error_message, "Non hai scelto il file con il pacchetto AIR di Scratch")
return False return False
else: else:
Glib.idle_add(self.show_action_message, "Verifica checksum file Scratch")
if not self.check_sha256(self.scrathFile, SCRATCH_SHA256):
Glib.idle_add(self.error_message, "Verifica checksum file Scratch: FAIL!")
return False
Glib.idle_add(self.append_action_message, "Verifica checksum file Scratch: OK")
GLib.idle_add(self.show_action_message, "Installo Scratch2 dal file" + self.scrathFile) GLib.idle_add(self.show_action_message, "Installo Scratch2 dal file" + self.scrathFile)
return True return True
@@ -334,7 +380,7 @@ class MyWindow(Gtk.Window):
"--xauthority=" + os.environ['XAUTHORITY'] ], stdout=subprocess.PIPE ,stderr=subprocess.STDOUT) "--xauthority=" + os.environ['XAUTHORITY'] ], stdout=subprocess.PIPE ,stderr=subprocess.STDOUT)
while True: while True:
line = inst.stdout.readline().decode('utf-8') line = inst.stdout.readline().decode('utf-8')
print (line) print (line, end='')
GLib.idle_add(self.append_action_message, line) GLib.idle_add(self.append_action_message, line)
if line == '' and inst.poll() != None: if line == '' and inst.poll() != None:
break break
@@ -347,7 +393,7 @@ class MyWindow(Gtk.Window):
# sys.stdout.write(char) # sys.stdout.write(char)
# GLib.idle_add(self.append_action_message, char) # GLib.idle_add(self.append_action_message, char)
if inst.returncode == 1: if inst.returncode == 1:
GLib.idle_add(self.error_message, "Il file di installazione di Adobe Air " + self.air_installer_file + " non esiste o non è leggibile") GLib.idle_add(self.error_message, "Il file SDK di Adobe Air " + self.air_installer_file + " non esiste o non è leggibile")
elif inst.returncode == 2: elif inst.returncode == 2:
GLib.idle_add(self.error_message, "Il file di installazione di Scratch2 " + self.scrathFile + " non esiste o non è leggibile") GLib.idle_add(self.error_message, "Il file di installazione di Scratch2 " + self.scrathFile + " non esiste o non è leggibile")
elif inst.returncode == 3: elif inst.returncode == 3:
@@ -390,11 +436,11 @@ def check_os():
def subprocess_call(command, new_env={}): def subprocess_call(command, new_env={}):
new_env['PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' new_env['PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
print(command) print(command)
return subprocess.call(command.split(' '), env=new_env) return subprocess.call(shlex.split(command), env=new_env)
def real_install(air_installer, scratch2_installer, xauthority): def real_install(air_installer, scratch2_installer, xauthority):
if not os.access(air_installer, os.R_OK): if not os.access(air_installer, os.R_OK):
print("Il file di installazione di Adobe Air " + air_installer + " non esiste o non è leggibile") print("Il file SDK di Adobe Air " + air_installer + " non esiste o non è leggibile")
sys.exit(1) sys.exit(1)
if not os.access(scratch2_installer, os.R_OK): if not os.access(scratch2_installer, os.R_OK):
print("Il file di installazione di Scratch2 " + scratch2_installer + " non esiste o non è leggibile") print("Il file di installazione di Scratch2 " + scratch2_installer + " non esiste o non è leggibile")
@@ -402,13 +448,14 @@ def real_install(air_installer, scratch2_installer, xauthority):
print ("Installer di Air: " + air_installer) print ("Installer di Air: " + air_installer)
print ("Installer di Scratch: " + scratch2_installer) print ("Installer di Scratch: " + scratch2_installer)
# Rende eseguibile l'installer di Air # Rende eseguibile l'installer di Air
os.chmod(air_installer, 0o755) # os.chmod(air_installer, 0o755)
# Recupera versione e architettura # Recupera versione e architettura
ver = subprocess.check_output(['/usr/bin/lsb_release', '-rs']).decode("utf-8") ver = subprocess.check_output(['/usr/bin/lsb_release', '-rs']).decode("utf-8")
arch = subprocess.check_output(['/bin/uname', '-m']) arch = subprocess.check_output(['/bin/uname', '-m']).decode("utf-8")
dependencies = '' dependencies = ''
# import pdb; pdb.set_trace()
# Cascata di if per le varie versioni/architetture # Cascata di if per le varie versioni/architetture
if ver == "12.04\n" or ver == "13\n": if ver == "12.04\n" or ver == "13\n":
if arch == "x86_64\n": if arch == "x86_64\n":
@@ -467,8 +514,8 @@ def real_install(air_installer, scratch2_installer, xauthority):
subprocess_call("ln -sf /usr/lib/i386-linux-gnu/libgnome-keyring.so.0.2.0 /usr/lib/libgnome-keyring.so.0.2.0") subprocess_call("ln -sf /usr/lib/i386-linux-gnu/libgnome-keyring.so.0.2.0 /usr/lib/libgnome-keyring.so.0.2.0")
elif ver == "18.04\n": elif ver == "18.04\n":
if arch == "x86_64\n": if arch == "x86_64\n":
dependencies = "libxt6:i386 libnspr4:i386 libgtk2.0-0:i386 libstdc++6:i386 libnss3:i386 libnss-mdns:i386 libxml2:i386 libxslt1.1:i386 libcanberra-gtk-module:i386 gtk2-engines-murrine:i386 libgnome-keyring0:i386 libxaw7" # dependencies = "libxt6:i386 libnspr4:i386 libgtk2.0-0:i386 libstdc++6:i386 libnss3:i386 libnss-mdns:i386 libxml2:i386 libxslt1.1:i386 libcanberra-gtk-module:i386 gtk2-engines-murrine:i386 libgnome-keyring0:i386 libxaw7"
# dependencies = "libgtk2.0-0:i386 libstdc++6:i386 libxml2:i386 libxslt1.1:i386 libcanberra-gtk-module:i386 gtk2-engines-murrine:i386 libqt4-qt3support:i386 libgnome-keyring0:i386 libnss-mdns:i386 libnss3:i386" dependencies = "libgtk2.0-0:i386 libstdc++6:i386 libxml2:i386 libxslt1.1:i386 libcanberra-gtk-module:i386 gtk2-engines-murrine:i386 libqt4-qt3support:i386 libgnome-keyring0:i386 libnss-mdns:i386 libnss3:i386"
subprocess_call("ln -sf /usr/lib/x86_64-linux-gnu/libgnome-keyring.so.0 /usr/lib/libgnome-keyring.so.0") subprocess_call("ln -sf /usr/lib/x86_64-linux-gnu/libgnome-keyring.so.0 /usr/lib/libgnome-keyring.so.0")
subprocess_call("ln -sf /usr/lib/x86_64-linux-gnu/libgnome-keyring.so.0.2.0 /usr/lib/libgnome-keyring.so.0.2.0") subprocess_call("ln -sf /usr/lib/x86_64-linux-gnu/libgnome-keyring.so.0.2.0 /usr/lib/libgnome-keyring.so.0.2.0")
else: else:
@@ -481,16 +528,35 @@ def real_install(air_installer, scratch2_installer, xauthority):
environment = { 'DISPLAY':':0', 'XAUTHORITY': xauthority, 'PATH':'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' } environment = { 'DISPLAY':':0', 'XAUTHORITY': xauthority, 'PATH':'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' }
subprocess_call("/bin/bash -c env") subprocess_call("/bin/bash -c env")
if subprocess_call("/usr/bin/apt-get -q -y install " + dependencies) != 0: # if subprocess_call("/usr/bin/apt-get -q -y install " + dependencies) != 0:
if subprocess_call("/usr/bin/apt-get update") != 0:
print("Installazione delle dipendenze fallita")
sys.exit(4)
if subprocess_call("/usr/bin/apt-get -y install " + dependencies) != 0:
print("Installazione delle dipendenze fallita") print("Installazione delle dipendenze fallita")
sys.exit(4) sys.exit(4)
# import pdb; pdb.set_trace() # import pdb; pdb.set_trace()
if subprocess_call(air_installer, environment) != 0: os.makedirs("/opt", exist_ok=True)
print("Installazione di Adobe Air dal file " + air_installer + " fallita") if "adobe-air-sdk" in os.listdir("/opt"):
shutil.rmtree("/opt/adobe-air-sdk")
os.mkdir("/opt/adobe-air-sdk")
if subprocess_call("/bin/tar jxf " + air_installer + " -C /opt/adobe-air-sdk", environment) != 0:
print("Installazione di Adobe Air SDK dal file " + air_installer + " fallita")
sys.exit(5) sys.exit(5)
if subprocess.call([ "/usr/bin/Adobe AIR Application Installer" , scratch2_installer ], env=environment) != 0: os.mkdir("/opt/adobe-air-sdk/scratch")
# import pdb; pdb.set_trace()
if subprocess_call( "/usr/bin/unzip -o " + scratch2_installer + " -d /opt/adobe-air-sdk/scratch/", environment) != 0:
print("Installazione di Scratch2 dal file " + scratch2_installer + " fallita") print("Installazione di Scratch2 dal file " + scratch2_installer + " fallita")
sys.exit(6) sys.exit(6)
try:
with open("/usr/share/applications/Scratch2.desktop", "w") as f:
f.write(DESKTOP_FILE)
os.chmod("/usr/share/applications/Scratch2.desktop", 0o644)
except Exception as e:
import pdb; pdb.set_trace()
print("Installazione di Scratch2 dal file " + scratch2_installer + " fallita")
sys.exit(6)
sys.exit(0) sys.exit(0)