Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatpak distribution #244

Open
wants to merge 13 commits into
base: installers
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flatpak_Test_App/flatpak/build-dir
Flatpak_Test_App/flatpak/.flatpak-builder
50 changes: 50 additions & 0 deletions Flatpak_Test_App/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Flatpak_Test_App (FOSSEE_Installer_Test) WIP :warning:


## Documentation to package demo installer using Flatpak.

### To get stared, we need to first install the runtimes required for packing our Qt5 application

```
flatpak install org.kde.Sdk//5.15-22.08

flatpak install com.riverbankcomputing.PyQt.BaseApp//5.15-22.08
```
---

### To build the flatpak application we require flatpak-builder

Ubuntu:
```
sudo apt install flatpak-builder -y
```
Fedora:
```
sudo dnf install flatpak-builder -y
```

### Install the dependencies mentioned below on the host system

Ubuntu:
```
sudo apt install make flex g++ ccache bison -y
```
Fedora:
```
sudo dnf install make flex g++ ccache bison -y
```
Other Linux Distributions: Use equivalent commands to install the necesarry packages

### To see all available commands for building, installing, accessing runtime through shell and more...
```bash
# execute the listed commands in ./flatpak/ dir
bash scripts/build_new_flatpak.sh
```

## Screenshots:
![image](https://user-images.githubusercontent.com/75079303/236667264-3d77cd7a-9bf0-405b-a0fc-32cde1f2f9be.png)

![image](https://user-images.githubusercontent.com/75079303/236667291-1467a423-d1d1-479d-b2f2-3fd49e195926.png)

![image](https://user-images.githubusercontent.com/75079303/236675064-114cffc4-f05f-4f7d-9e33-252cc7e062ef.png)

147 changes: 147 additions & 0 deletions Flatpak_Test_App/flatpak/FOSSEE_Inst_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import sys
import subprocess
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMessageBox
import PyQt5.QtCore
from PyQt5.QtCore import *
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QLabel
import py7zr
import os

class AppWindow(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.initUI()

def initUI(self):
self.Logo = QLabel(self)
self.pixmap = QPixmap('/app/assets/Fossee_logo.png')
self.Logo.setPixmap(self.pixmap)
self.Logo.setAlignment(PyQt5.QtCore.Qt.AlignRight)

self.label = QtWidgets.QLabel('Select package to install:')
self.combo = QtWidgets.QComboBox()
self.combo.addItems(['makerchip-app', 'sandpiper-saas', 'matplotlib'])

self.install_pkg_button = QtWidgets.QPushButton('Install Pip package')
self.install_pkg_button.clicked.connect(self.install_Pip_package)

self.install_verilator_from_Archive_button = QtWidgets.QPushButton('Install Verilator from Archive')
self.install_verilator_from_Archive_button.clicked.connect(self.intall_Verilator_from_Archive)

self.install_verilator_SRC_button = QtWidgets.QPushButton('Install Verilator from SRC')
self.install_verilator_SRC_button.clicked.connect(self.install_Verilator_SRC)

self.Install_Output = QtWidgets.QPlainTextEdit()

self.install_thread = InstallThread_SRC()
self.install_thread.output_signal.connect(self.update_output)

layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.Logo)
layout.addWidget(self.label)
layout.addWidget(self.combo)
layout.addWidget(self.install_pkg_button)
layout.addWidget(self.install_verilator_from_Archive_button)
layout.addWidget(self.install_verilator_SRC_button)
layout.addWidget(self.Install_Output)
self.setLayout(layout)

def install_Pip_package(self):
package = self.combo.currentText()
try:
subprocess.check_call(['flatpak-spawn', '--host', sys.executable, '-m', 'pip', 'install', package])
QtWidgets.QMessageBox.information(self, 'Success', f'{package} installed successfully')
self.Install_Output.appendPlainText(f'Success: {package} installed successfully')
except Exception as e:
QMessageBox.warning(self,"ERROR", str(e))
self.Install_Output.appendPlainText("[ERROR!]: ")
self.Install_Output.appendPlainText(str(e))

def intall_Verilator_from_Archive(self):
file_name = "/app/assets/packages/verilator.7z"
output_dir = os.getcwd()

source_file = f"{output_dir}/verilator/bin/verilator"
destination_dir = "/usr/bin/"

with py7zr.SevenZipFile(file_name, mode='r') as z:
z.extractall(path=output_dir)

try:
subprocess.check_call(['flatpak-spawn', '--host', "pkexec", "cp", source_file, destination_dir])
QtWidgets.QMessageBox.information(self, 'Success', 'Verilator installed successfully from Archive')
self.Install_Output.appendPlainText('[Success]: verilator installed successfully from Archive')
except subprocess.CalledProcessError as e:
QMessageBox.warning(self,"ERROR", str(e))
self.Install_Output.appendPlainText("[ERROR!]: ")
self.Install_Output.appendPlainText(str(e))

## Used to show updates for install_Verilator_SRC
def update_output(self, text):
self.Install_Output.appendPlainText(text)

def install_Verilator_SRC(self):
try:
self.Install_Output.clear()

self.Install_Output.clear()
self.install_thread.start()

except Exception as e:
self.Install_Output.appendPlainText("[ERROR!]: ")
self.Install_Output.appendPlainText(str(e))
QtWidgets.QMessageBox.information(self,"Error", str(e))
print("[ERROR!]: ",e)

class install_verilator(QThread):
P_progress = pyqtSignal(str)
def __init__(self, command, parent=None):
QThread.__init__(self, parent)
self.command = command
def start(self):
QThread.start(self)
def run(self):
try:
p = subprocess.run(str(self.command),shell=True,capture_output=True)
status = p.stdout.decode()
if p:
print(status)
self.P_progress.emit(status)
except Exception as e:
self.Install_Output.appendPlainText("[ERROR!]: ")
self.Install_Output.appendPlainText(str(e))
QMessageBox.warning(None,"Invalid Install Commands!","Error in install_verilator")

class InstallThread_SRC(QThread):
output_signal = pyqtSignal(str)

def __init__(self):
super().__init__()

def run(self):
command = "/app/assets/scripts/Install_verilator.sh"
process = subprocess.Popen(["bash", command], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

while True:
output = process.stdout.readline()
if output == b'' and process.poll() is not None:
break
if output:
self.output_signal.emit(str(output.strip())[2:-1])
print(output.strip()[2:-1])

rc = process.poll()
if rc == 0:
self.output_signal.emit("[Info] Installation succeeded!")
print("Installation succeeded!")
else:
self.output_signal.emit("[ERROR] Installation failed!")
print("Installation failed!")

if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
ex = AppWindow()
ex.show()
sys.exit(app.exec_())
Binary file added Flatpak_Test_App/flatpak/assets/Fossee_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
44 changes: 44 additions & 0 deletions Flatpak_Test_App/flatpak/assets/scripts/Install_verilator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

## Clone Verilator repository

echo '# Please wait... cloning https://github.com/verilator/verilator'
git clone http://git.veripool.org/git/verilator
echo '# repo cloned...'
echo "===============================================\n"

echo '# changing dir to verilator/'
cd ./verilator

echo '# current working directory is: '
pwd
echo "===============================================\n"

# Switch to version 4.106
git checkout v4.106

# Build Verilator
autoconf

echo '# please wait... This may take some time'
echo "===============================================\n"
./configure --prefix=/usr --libdir=/usr/lib64

echo '# current working directory is (supposed to be verilator): '
pwd
echo "==========================="
echo "Please enter root password:"
flatpak-spawn --host sudo -S make


echo 'Installing make...'
echo "==========================="
echo "Please enter root password:"
flatpak-spawn --host sudo -S make install

flatpak-spawn --host verilator --version

echo "===============================================\n"
echo "Cleaning up..."

flatpak-spawn --host rm -rf ./verilator
29 changes: 29 additions & 0 deletions Flatpak_Test_App/flatpak/assets/scripts/ngspice.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

echo "Installing ngspice..."
echo "==========================="

# write a script to install ngspice on any platform

# Download ngspice source code from GitHub
git clone https://github.com/ngspice/ngspice.git

# Change directory to ngspice folder
cd ngspice

# Install prerequisites

# Configure and build ngspice
echo '# please wait... This may take some time'
echo "===============================================\n"
./autogen.sh
./configure
make
sudo make install

# Add ngspice executable to PATH environment variable
echo 'export PATH=$PATH:/usr/local/bin' >> ~/.bashrc
source ~/.bashrc

# Test ngspice installation
ngspice --version
10 changes: 10 additions & 0 deletions Flatpak_Test_App/flatpak/assets/scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

echo "This is a test script"
echo "========================================"
git --version
echo "========================================"
make --version
echo "========================================"
autoconf --verison
echo "========================================"
26 changes: 26 additions & 0 deletions Flatpak_Test_App/flatpak/git.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "git",
"make-args": [
"INSTALL_SYMLINKS=1"
],
"make-install-args": [
"INSTALL_SYMLINKS=1"
],
"cleanup": [
"/lib/pkgconfig",
"/man"
],
"sources": [
{
"type": "archive",
"url": "https://www.kernel.org/pub/software/scm/git/git-2.40.1.tar.xz",
"sha256": "4893b8b98eefc9fdc4b0e7ca249e340004faa7804a433d17429e311e1fef21d2",
"x-checker-data": {
"type": "anitya",
"project-id": 5350,
"stable-only": true,
"url-template": "https://www.kernel.org/pub/software/scm/git/git-$version.tar.xz"
}
}
]
}
49 changes: 49 additions & 0 deletions Flatpak_Test_App/flatpak/org.flatpak.FOSSEE_Inst_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
app-id: org.flatpak.FOSSEE_Inst_test
runtime: org.kde.Sdk
runtime-version: '5.15-22.08'
sdk: org.kde.Sdk
base: com.riverbankcomputing.PyQt.BaseApp
base-version: 5.15-22.08

command: run.sh

finish-args:
- --share=ipc
- --share=network
- --socket=x11
- --socket=wayland
- --filesystem=host-os
- --filesystem=host
- --filesystem=home
- --device=dri
- --talk-name=org.freedesktop.Flatpak

files:
- path: /home/suchinton/verilator/*
read: true
write: true

modules:
- name: FOSSEE_Inst_test
buildsystem: simple
build-commands:
- install -D FOSSEE_Inst_test.py /app/bin/FOSSEE_Inst_test.py
- install -D run.sh /app/bin/run.sh

sources:
- type: file
path: FOSSEE_Inst_test.py
- type: file
path: run.sh

- name: assets
buildsystem: simple
build-commands:
- cp -r assets/ /app/assets/

sources:
- type: dir
path: assets/
dest: assets/

- python3-py7zr.json
Loading