summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rwxr-xr-xbackend/libsisyphus.py229
-rwxr-xr-xbackend/libsisyphus.sh179
2 files changed, 0 insertions, 408 deletions
diff --git a/backend/libsisyphus.py b/backend/libsisyphus.py
deleted file mode 100755
index 5dff073..0000000
--- a/backend/libsisyphus.py
+++ /dev/null
@@ -1,229 +0,0 @@
-#!/usr/bin/python3
-
-import csv
-import filecmp
-import os
-import shutil
-import sqlite3
-import sys
-import urllib3
-import subprocess
-
-redcore_portage_tree_path = '/usr/portage'
-redcore_desktop_overlay_path = '/var/lib/layman/redcore-desktop'
-redcore_portage_config_path = '/opt/redcore-build'
-
-sisyphus_remote_csv_url = 'http://mirror.math.princeton.edu/pub/redcorelinux/csv/remote_preinst.csv'
-sisyphus_remote_csv_path_pre = '/var/lib/sisyphus/csv/remote_preinst.csv'
-sisyphus_remote_csv_path_post = '/var/lib/sisyphus/csv/remote_postinst.csv'
-sisyphus_local_csv_path_pre = '/var/lib/sisyphus/csv/local_preinst.csv'
-sisyphus_local_csv_path_post = '/var/lib/sisyphus/csv/local_postinst.csv'
-sisyphus_database_path = '/var/lib/sisyphus/db/sisyphus.db'
-def check_if_root():
- if not os.getuid() == 0:
- sys.exit("you need root permissions to do this. exiting!")
-
-def check_if_srcmode():
- portage_srcmode_make_conf = '/opt/redcore-build/conf/intel/portage/make.conf.amd64-srcmode'
- portage_make_conf_symlink = '/etc/portage/make.conf'
-
- if os.path.islink(portage_make_conf_symlink) and os.path.realpath(portage_make_conf_symlink) == portage_srcmode_make_conf:
- print("the system is set to srcmode (full gentoo), refusing to run!")
- sys.exit(1)
-
-def check_redcore_portage_tree():
- os.chdir(redcore_portage_tree_path)
- subprocess.call(['git', 'remote', 'update'])
- redcore_portage_tree_local_hash = subprocess.check_output(['git', 'rev-parse', '@'])
- redcore_portage_tree_remote_hash = subprocess.check_output(['git', 'rev-parse', '@{u}'])
-
- if not redcore_portage_tree_local_hash == redcore_portage_tree_remote_hash:
- print("redcore desktop portage tree is out-of-date. run 'sisyphus update' first!")
- sys.exit(1)
-
-def check_redcore_desktop_overlay():
- os.chdir(redcore_desktop_overlay_path)
- subprocess.call(['git', 'remote', 'update'])
- redcore_desktop_overlay_local_hash = subprocess.check_output(['git', 'rev-parse', '@'])
- redcore_desktop_overlay_remote_hash = subprocess.check_output(['git', 'rev-parse', '@{u}'])
-
- if not redcore_desktop_overlay_local_hash == redcore_desktop_overlay_remote_hash:
- print("redcore desktop overlay is out-of-date. run 'sisyphus update' first!")
- sys.exit(1)
-
-def check_redcore_portage_config():
- os.chdir(redcore_portage_config_path)
- subprocess.call(['git', 'remote', 'update'])
- redcore_portage_config_local_hash = subprocess.check_output(['git', 'rev-parse', '@'])
- redcore_portage_config_remote_hash = subprocess.check_output(['git', 'rev-parse', '@{u}'])
-
- if not redcore_portage_config_local_hash == redcore_portage_config_remote_hash:
- print("redcore desktop portage config is out-of-date. run 'sisyphus update' first!")
- sys.exit(1)
-
-def fetch_sisyphus_remote_packages_table_csv():
- http = urllib3.PoolManager()
-
- if not os.path.isfile(sisyphus_remote_csv_path_pre):
- os.mknod(sisyphus_remote_csv_path_pre)
- with http.request('GET', sisyphus_remote_csv_url, preload_content=False) as tmp_buffer, open(sisyphus_remote_csv_path_post, 'wb') as output_file:
- shutil.copyfileobj(tmp_buffer, output_file)
- else:
- with http.request('GET', sisyphus_remote_csv_url, preload_content=False) as tmp_buffer, open(sisyphus_remote_csv_path_post, 'wb') as output_file:
- shutil.copyfileobj(tmp_buffer, output_file)
-
-def check_sisyphus_remote_packages_table_csv():
- if not filecmp.cmp(sisyphus_remote_csv_path_pre, sisyphus_remote_csv_path_post):
- print("sisyphus database remote_packages table is out-of-date. run 'sisyphus update' first!")
- os.remove(sisyphus_remote_csv_path_post)
- sys.exit(1)
- else:
- os.remove(sisyphus_remote_csv_path_post)
-
-def check_sisyphus_remote_packages_table():
- fetch_sisyphus_remote_packages_table_csv()
- check_sisyphus_remote_packages_table_csv()
-
-def check_sync():
- check_if_root()
- check_redcore_portage_tree()
- check_redcore_desktop_overlay()
- check_redcore_portage_config()
- check_sisyphus_remote_packages_table()
-
-def sync_redcore_portage_tree_and_desktop_overlay():
- subprocess.call(['emerge', '--sync'])
-
-def sync_redcore_portage_config():
- os.chdir(redcore_portage_config_path)
- print(">>> Syncing 'portage config' into '/etc/portage'...")
- print("/usr/bin/git pull")
- subprocess.call(['git', 'pull'])
- print("=== Sync completed for 'portage config'")
-
-def sync_sisyphus_remote_packages_table_csv():
- if not filecmp.cmp(sisyphus_remote_csv_path_pre, sisyphus_remote_csv_path_post):
- print(">>> Syncing 'sisyphus database remote_packages table' into '/var/lib/sisyphus/db/sisyphus.db'")
- print("/usr/bin/sqlite3 /var/lib/sisyphus/db/sisyphus.db")
- sisyphusdb = sqlite3.connect(sisyphus_database_path)
- sisyphusdb.cursor().execute('''drop table if exists remote_packages''')
- sisyphusdb.cursor().execute('''create table remote_packages (category TEXT,name TEXT,version TEXT,slot TEXT,description TEXT)''')
- with open(sisyphus_remote_csv_path_post) as sisyphus_remote_csv:
- for row in csv.reader(sisyphus_remote_csv):
- sisyphusdb.cursor().execute("insert into remote_packages (category, name, version, slot, description) values (?, ?, ?, ?, ?);", row)
- sisyphusdb.commit()
- sisyphusdb.close()
- print("=== Sync completed for 'sisyphus database remote_packages table'")
- else:
- print(">>> Syncing 'sisyphus database remote_packages table' into '/var/lib/sisyphus/db/sisyphus.db'")
- print("/usr/bin/sqlite3 /var/lib/sisyphus/db/sisyphus.db")
- print("Already up-to-date.")
- print("=== Sync completed for 'sisyphus database remote_packages table'")
- shutil.move(sisyphus_remote_csv_path_post, sisyphus_remote_csv_path_pre)
-
-def sync_sisyphus_database_remote_packages_table():
- fetch_sisyphus_remote_packages_table_csv()
- sync_sisyphus_remote_packages_table_csv()
-
-def redcore_sync():
- check_if_root()
- sync_redcore_portage_tree_and_desktop_overlay()
- sync_redcore_portage_config()
- sync_sisyphus_database_remote_packages_table()
-
-def generate_sisyphus_local_packages_table_csv_pre():
- subprocess.call(['/usr/share/sisyphus-cli/helpers/make_local_csv_pre']) # this is really hard to do in python, so we cheat with a bash helper script
-
-def generate_sisyphus_local_packages_table_csv_post():
- subprocess.call(['/usr/share/sisyphus-cli/helpers/make_local_csv_post']) # this is really hard to do in python, so we cheat with a bash helper script
-
-def sync_sisyphus_local_packages_table_csv():
- if filecmp.cmp(sisyphus_local_csv_path_pre, sisyphus_local_csv_path_post):
- print("sisyphus database local_packages table is in sync with portage database, nothing to do...")
- else:
- print("sisyphus database local_packages table is not in sync with portage database, syncing now...")
- sisyphusdb = sqlite3.connect(sisyphus_database_path)
- sisyphusdb.cursor().execute('''drop table if exists local_packages''')
- sisyphusdb.cursor().execute('''create table local_packages (category TEXT,name TEXT,version TEXT,slot TEXT,description TEXT)''')
- with open(sisyphus_local_csv_path_post) as sisyphus_local_csv:
- for row in csv.reader(sisyphus_local_csv):
- sisyphusdb.cursor().execute("insert into local_packages (category, name, version, slot, description) values (?, ?, ?, ?, ?);", row)
- sisyphusdb.commit()
- sisyphusdb.close()
- shutil.move(sisyphus_local_csv_path_post, sisyphus_local_csv_path_pre)
-
-def sisyphus_pkg_install():
- check_sync()
- generate_sisyphus_local_packages_table_csv_pre()
- subprocess.call(['emerge', '-a'] + sys.argv[2:])
- generate_sisyphus_local_packages_table_csv_post()
- sync_sisyphus_local_packages_table_csv()
-
-def sisyphus_pkg_uninstall():
- check_sync()
- generate_sisyphus_local_packages_table_csv_pre()
- subprocess.call(['emerge', '--depclean', '-a'] + sys.argv[2:])
- generate_sisyphus_local_packages_table_csv_post()
- sync_sisyphus_local_packages_table_csv()
-
-def sisyphus_pkg_force_uninstall():
- check_sync()
- generate_sisyphus_local_packages_table_csv_pre()
- subprocess.call(['emerge', '--unmerge', '-a'] + sys.argv[2:])
- generate_sisyphus_local_packages_table_csv_post()
- sync_sisyphus_local_packages_table_csv()
-
-def sisyphus_pkg_remove_orphans():
- check_sync()
- generate_sisyphus_local_packages_table_csv_pre()
- subprocess.call(['emerge', '--depclean', '-a'])
- generate_sisyphus_local_packages_table_csv_post()
- sync_sisyphus_local_packages_table_csv()
-
-def sisyphus_pkg_system_upgrade():
- check_sync()
- generate_sisyphus_local_packages_table_csv_pre()
- subprocess.call(['emerge', '-uDaN', '--with-bdeps=y', '@world'])
- generate_sisyphus_local_packages_table_csv_post()
- sync_sisyphus_local_packages_table_csv()
-
-def sisyphus_pkg_auto_install():
- redcore_sync()
- generate_sisyphus_local_packages_table_csv_pre()
- subprocess.call(['emerge'] + sys.argv[2:])
- generate_sisyphus_local_packages_table_csv_post()
- sync_sisyphus_local_packages_table_csv()
-
-def sisyphus_pkg_auto_uninstall():
- redcore_sync()
- generate_sisyphus_local_packages_table_csv_pre()
- subprocess.call(['emerge', '--depclean'] + sys.argv[2:])
- generate_sisyphus_local_packages_table_csv_post()
- sync_sisyphus_local_packages_table_csv()
-
-def sisyphus_pkg_auto_force_uninstall():
- redcore_sync()
- generate_sisyphus_local_packages_table_csv_pre()
- subprocess.call(['emerge', '--unmerge'] + sys.argv[2:])
- generate_sisyphus_local_packages_table_csv_post()
- sync_sisyphus_local_packages_table_csv()
-
-def sisyphus_pkg_auto_remove_orphans():
- redcore_sync()
- generate_sisyphus_local_packages_table_csv_pre()
- subprocess.call(['emerge', '--depclean', '-q'])
- generate_sisyphus_local_packages_table_csv_post()
- sync_sisyphus_local_packages_table_csv()
-
-def sisyphus_pkg_auto_system_upgrade():
- redcore_sync()
- generate_sisyphus_local_packages_table_csv_pre()
- subprocess.call(['emerge', '-uDN', '--with-bdeps=y', '@world'])
- generate_sisyphus_local_packages_table_csv_post()
- sync_sisyphus_local_packages_table_csv()
-
-def sisyphus_pkg_search():
- subprocess.call(['emerge', '--search'] + sys.argv[2:])
-
-def sisyphus_pkg_system_update():
- redcore_sync()
diff --git a/backend/libsisyphus.sh b/backend/libsisyphus.sh
deleted file mode 100755
index 530f9bf..0000000
--- a/backend/libsisyphus.sh
+++ /dev/null
@@ -1,179 +0,0 @@
-#!/usr/bin/env bash
-
-# import gentoo functions
-source /lib/gentoo/functions.sh
-
-checkroot () {
- if [[ "$(whoami)" != root ]] ; then
- eerror "You're not root?...No cookies for you, go away !!!"
- exit 1
- fi
-}
-
-checksystemmode() {
- if [[ "$(readlink -f "/etc/portage/make.conf")" = /opt/redcore-build/conf/intel/portage/make.conf.amd64-srcmode ]] ; then
- eerror "The system is set to srcmode (full Gentoo mode), cowardly refusing to run!"
- exit 1
- fi
-}
-
-checkportageconfig () {
- pushd /opt/redcore-build > /dev/null 2>&1
- git remote update > /dev/null 2>&1
- export local confhash=$(git rev-parse @)
- export local rconfhash=$(git rev-parse @{u})
- if [ $confhash != $rconfhash ] ; then
- eerror "Portage config is out-of-date, run "sisyphus update" first"
- exit 1
- fi
- popd > /dev/null 2>&1
-}
-
-checkportagetree () {
- pushd /usr/portage > /dev/null 2>&1
- git remote update > /dev/null 2>&1
- export local treehash=$(git rev-parse @)
- export local rtreehash=$(git rev-parse @{u})
- if [ $treehash != $rtreehash ] ; then
- eerror "Portage tree is out-of-date, run "sisyphus update" first"
- exit 1
- fi
- popd > /dev/null 2>&1
-}
-
-checkredcoreoverlay () {
- pushd /var/lib/layman/redcore-desktop > /dev/null 2>&1
- git remote update > /dev/null 2>&1
- export local overlayhash=$(git rev-parse @)
- export local roverlayhash=$(git rev-parse @{u})
- if [ $overlayhash != $roverlayhash ] ; then
- eerror "Redcore Desktop overlay is out-of-date, run "sisyphus update" first"
- exit 1
- fi
-}
-
-remotedbcsvget () {
- if [[ ! -f /var/lib/sisyphus/csv/remote_preinst.csv ]] ; then
- pushd /var/lib/sisyphus/csv > /dev/null 2>&1
- touch remote_preinst.csv
- wget -c http://mirror.math.princeton.edu/pub/redcorelinux/csv/remote_preinst.csv -O remote_postinst.csv > /dev/null 2>&1
- popd > /dev/null 2>&1
- elif [[ -f /var/lib/sisyphus/csv/remote_preinst.csv ]] ; then
- pushd /var/lib/sisyphus/csv > /dev/null 2>&1
- wget -c http://mirror.math.princeton.edu/pub/redcorelinux/csv/remote_preinst.csv -O remote_postinst.csv > /dev/null 2>&1
- popd > /dev/null 2>&1
- fi
-}
-
-remotedbcsvcheck () {
- if ! cmp /var/lib/sisyphus/csv/remote_preinst.csv /var/lib/sisyphus/csv/remote_postinst.csv > /dev/null 2>&1 ; then
- eerror "SisyphusDB : "remote_packages" table is out-of-date, run "sisyphus update" first"
- rm -rf /var/lib/sisyphus/csv/remote_postinst.csv
- exit 1
- elif cmp /var/lib/sisyphus/csv/remote_preinst.csv /var/lib/sisyphus/csv/remote_postinst.csv > /dev/null 2>&1 ; then
- rm -rf /var/lib/sisyphus/csv/remote_postinst.csv
- fi
-}
-
-checkremotedb () {
- remotedbcsvget
- remotedbcsvcheck
-}
-
-checksync () {
- checkroot
- checkportagetree
- checkredcoreoverlay
- checkportageconfig
- checkremotedb
-}
-
-syncrepos () {
- emerge --sync
-}
-
-syncportageconfig () {
- pushd /opt/redcore-build > /dev/null 2>&1
- echo ">>> Syncing 'portage config' into '/etc/portage'..."
- echo "/usr/bin/git pull"
- git pull
- echo "=== Sync completed for 'portage config'"
- popd > /dev/null 2>&1
-}
-
-remotedbcsvsync () {
- if ! cmp /var/lib/sisyphus/csv/remote_preinst.csv /var/lib/sisyphus/csv/remote_postinst.csv > /dev/null 2>&1 ; then
- echo ">>> Syncing 'SisyphusDB remote_packages' into '/var/lib/sisyphus/db/sisyphus.db'"
- echo "/usr/bin/sqlite3 /var/lib/sisyphus/db/sisyphus.db"
- pushd /var/lib/sisyphus/db > /dev/null 2>&1
- sqlite3 -echo sisyphus.db<<-EXIT_HERE
- drop table if exists remote_packages;
- create table remote_packages (category TEXT,name TEXT,version TEXT,slot TEXT,description TEXT);
- .mode csv
- .import /var/lib/sisyphus/csv/remote_postinst.csv remote_packages
- EXIT_HERE
- popd > /dev/null 2>&1
- echo "=== Sync completed for 'SisyphusDB remote_packages'"
- elif cmp /var/lib/sisyphus/csv/remote_preinst.csv /var/lib/sisyphus/csv/remote_postinst.csv > /dev/null 2>&1 ; then
- echo ">>> Syncing 'SisyphusDB remote_packages' into '/var/lib/sisyphus/db/sisyphus.db'"
- echo "/usr/bin/sqlite3 /var/lib/sisyphus/db/sisyphus.db"
- echo "Already up-to-date."
- echo "=== Sync completed for 'SisyphusDB remote_packages'"
- fi
- mv /var/lib/sisyphus/csv/remote_postinst.csv /var/lib/sisyphus/csv/remote_preinst.csv
-}
-
-syncremotedb() {
- remotedbcsvget
- remotedbcsvsync
-}
-
-redcoresync () {
- checkroot
- syncrepos
- syncportageconfig
- syncremotedb
-}
-
-localdbcsvpre () {
- if [[ ! -f /var/lib/sisyphus/csv/local_preinst.csv ]] ; then
- for i in $(qlist -ICv); do
- pushd /var/db/pkg/$i > /dev/null 2>&1
- echo "$(<CATEGORY),$(sed -re "s/-([0-9])/,\1/" <PF),$(<SLOT),$(sed -e "s/\"//g" -e "s/\'//g" -e "s/\,//g" <DESCRIPTION)" >> /var/lib/sisyphus/csv/local_preinst.csv
- popd > /dev/null 2>&1
- done
- fi
-}
-
-localdbcsvpost () {
- for i in $(qlist -ICv); do
- pushd /var/db/pkg/$i > /dev/null 2>&1
- echo "$(<CATEGORY),$(sed -re "s/-([0-9])/,\1/" <PF),$(<SLOT),$(sed -e "s/\"//g" -e "s/\'//g" -e "s/\,//g" <DESCRIPTION)" >> /var/lib/sisyphus/csv/local_postinst.csv
- popd > /dev/null 2>&1
- done
-}
-
-localdbcsvsync () {
- if cmp /var/lib/sisyphus/csv/local_preinst.csv /var/lib/sisyphus/csv/local_postinst.csv > /dev/null 2>&1 ; then
- einfo "'PortageDB' && 'SisyphusDB local_packages' are in sync, nothing to do..."
- else
- einfo "'PortageDB' && 'SisyphusDB local_packages' are out of sync, syncing now..."
- echo "/usr/bin/sqlite3 /var/lib/sisyphus/db/sisyphus.db"
- pushd /var/lib/sisyphus/db > /dev/null 2>&1
- sqlite3 -echo sisyphus.db<<-EXIT_HERE
- drop table if exists local_packages;
- create table local_packages (category TEXT,name TEXT,version TEXT,slot TEXT,description TEXT);
- .mode csv
- .import /var/lib/sisyphus/csv/local_postinst.csv local_packages
- EXIT_HERE
- popd > /dev/null 2>&1
- einfo "'PortageDB' && 'SisyphusDB local_packages' resync complete..."
- fi
- mv /var/lib/sisyphus/csv/local_postinst.csv /var/lib/sisyphus/csv/local_preinst.csv
-}
-
-updatelocaldb () {
- checkroot
- localdbcsvpost
- localdbcsvsync
-}