Installer script

This commit is contained in:
Vinicius Moreira
2019-06-13 14:56:03 -03:00
parent bf1175626a
commit d5142662eb
6 changed files with 126 additions and 11 deletions

10
README.md Normal file
View File

@@ -0,0 +1,10 @@
## fpakman
Graphical interface for Flatpak application management. It has also a tray icon to let the user known when new updates are available.
Wriiten in Python for QT5.
### Roadmap
- Test installer for Ubuntu
- Load the database in a thread when the application starts. It will prevent the delay of showing the icon.
- Locales
- System notification whe new updates
- Search and install applications.

0
app.py Normal file → Executable file
View File

View File

@@ -1,7 +1,8 @@
import re import re
import subprocess
from typing import List from typing import List
from core import system
def app_str_to_json(line: str, version: str) -> dict: def app_str_to_json(line: str, version: str) -> dict:
@@ -40,22 +41,17 @@ def app_str_to_json(line: str, version: str) -> dict:
return app return app
def _run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False) -> str:
res = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE)
return res.stdout.decode() if ignore_return_code or res.returncode == expected_code else None
def get_version(): def get_version():
res = _run_cmd('flatpak --version') res = system.run_cmd('flatpak --version')
return res.split(' ')[1].strip() if res else None return res.split(' ')[1].strip() if res else None
def get_app_info(app_id: str): def get_app_info(app_id: str):
return _run_cmd('flatpak info ' + app_id) return system.run_cmd('flatpak info ' + app_id)
def list_installed() -> List[dict]: def list_installed() -> List[dict]:
apps_str = _run_cmd('flatpak list') apps_str = system.run_cmd('flatpak list')
if apps_str: if apps_str:
version = get_version() version = get_version()
@@ -66,8 +62,8 @@ def list_installed() -> List[dict]:
def update(ref: str): def update(ref: str):
return bool(_run_cmd('flatpak update -y ' + ref)) return bool(system.run_cmd('flatpak update -y ' + ref))
def list_updates_as_str(): def list_updates_as_str():
return _run_cmd('flatpak update', ignore_return_code=True) return system.run_cmd('flatpak update', ignore_return_code=True)

6
core/system.py Normal file
View File

@@ -0,0 +1,6 @@
import subprocess
def run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False) -> str:
res = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE)
return res.stdout.decode() if ignore_return_code or res.returncode == expected_code else None

2
run.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
/home/dafiti/workspace/fpakman/env/bin/python /home/dafiti/workspace/fpakman/app.py

101
sandbox_installer.py Executable file
View File

@@ -0,0 +1,101 @@
#!/usr/bin/env python3
################################################################
# It installs the application without compromising you system. #
# libraries. 'qt5' is required to be installed. #
# #
# If you use GTK, install 'libappindicator3' also. #
# #
# EXECUTE THIS SCRIPT INSIDE THE PROJECT FOLDER AS ROOT #
# #
################################################################
import os
import sys
from shutil import rmtree
from core import system, flatpak
if not os.geteuid() == 0:
sys.exit("\nOnly root can run this script\n")
link_path = '/usr/local/bin/fpakman'
runner_file = 'run.sh'
env_name = 'env'
def log(msg: str):
print('[fpakman] {}'.format(msg))
if os.path.exists(link_path):
log('already installed')
log('Do you wish to uninstall it ? (y/N)')
uninstall = input()
if uninstall.lower() == 'y':
try:
os.unlink(link_path)
except:
log("Could not remove the runner syslink '{}'".format(link_path))
log("Aborting...")
exit(1)
if os.path.exists('{}/{}'.format(os.getcwd(), env_name)):
try:
rmtree(env_name)
except:
log("Could not remove the virtualenv '{}'".format(env_name))
log("Aborting")
exit(1)
if os.path.exists('{}/{}'.format(os.getcwd(), runner_file)):
try:
os.remove(runner_file)
except:
log("Could not remove the runner file '{}'".format(runner_file))
log("Aborting...")
exit(1)
log("Successfully uninstalled")
else:
log('Aborting...')
else:
if flatpak.get_version is None:
print('flatpak seems not to be installed. Aborting...')
exit(1)
if not os.path.exists('env'):
log("Creating a new 'virtualenv' as '{}'...".format(env_name))
res = system.run_cmd('python3 -m venv ' + env_name)
if res is None:
log("Could create a virtualenv for installation. Check if 'virtualenv' is installed.")
log('Aborting...')
exit(1)
res = system.run_cmd('env/bin/pip install -r requirements.txt')
if res:
log("Creating runner as '{}'".format(runner_file))
with open('run.sh', 'w+') as f:
f.write('#!/bin/bash\n{d}/env/bin/python {d}/app.py'.format(d=os.getcwd()))
system.run_cmd('chmod +x ' + runner_file)
log("Creating syslink as '{}'".format(link_path))
try:
os.link('{}/{}'.format(os.getcwd(), runner_file), link_path)
except:
log("Could not create the syslink")
log("Aborting...")
exit(1)
log('Successfully installed')
else:
log('Could not install python requirements to the virtualenv')
log('Aborting...')
exit(1)