There's always a 1st commit

This commit is contained in:
Darks 2021-06-08 23:08:11 +02:00
commit c185215c25
Signed by: Darks
GPG Key ID: 7515644268BE1433
22 changed files with 611 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
__pycache__/
*.py[cod]
*$py.class
packages/
pkgbuilds/
run.sh

20
Dockerfile Normal file
View File

@ -0,0 +1,20 @@
FROM archlinux:base-devel
RUN pacman-key --init && \
pacman -Syu --noconfirm git
ADD packages /tmp/packages
ADD pkgbuilds /tmp/pkgbuilds
ADD scripts/build.sh /tmp
ADD scripts/run.sh /tmp
RUN chmod +x /tmp/build.sh && \
chmod +x /tmp/run.sh && \
chmod -R 777 /tmp/pkgbuilds && \
chmod 777 /tmp/packages
RUN /tmp/run.sh
WORKDIR /tmp/gintctl
ENTRYPOINT git clone https://gitea.planet-casio.com/Lephenixnoir/gintctl.git . && \
fxsdk build-cg && \
fxsdk build-fx

43
main.py Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env python3
import logging
import requests as r
from utils import *
ARCH = "x86_64"
def main():
packages = load_config()
clean_directories()
# Manage each package
for p in packages:
# Retreive tag to apply
if 'tag' in p:
logging.debug(f"{p['name']} forced to {p['tag']}")
elif 'repo' in p:
p['tag'] = get_tags_from_git(p['repo'])
else:
p['tag'] = get_package_version(p['name'], ARCH)
# Retreive current package version
current_tag = get_package_version(p['name'], ARCH)
# Check if update is required
if p['tag'] != current_tag:
logging.info(f"{p['name']} will be updated: {current_tag}{p['tag']}")
render_pkgbuild(p['name'], p['tag'])
else:
tarball, url = get_package_tarball(p['name'], ARCH)
logging.info(f"{p['name']} will be retreived from {url}")
content = r.get(url).content
with open(f"packages/{tarball}", "wb") as file:
file.write(content)
if __name__ == "__main__":
logging.basicConfig(format="[%(asctime)s] %(levelname)s (%(filename)s.%(funcName)s): %(message)s",
level=logging.INFO)
main()

36
packages.yaml Normal file
View File

@ -0,0 +1,36 @@
- name: isl
- name: sh-elf-binutils-casio
- name: sh-elf-gcc-casio
- name: openlibm-casio
repo: https://gitea.planet-casio.com/Lephenixnoir/OpenLibm.git
- name: mkg3a
repo: https://github.com/tari/mkg3a.git
- name: fxsdk
repo: https://gitea.planet-casio.com/Lephenixnoir/fxsdk.git
- name: fxlibc
repo: https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
- name: gint
repo: https://gitea.planet-casio.com/Lephenixnoir/gint.git
- name: libimg
repo: https://gitea.planet-casio.com/Lephenixnoir/libimg.git
- name: libprof
repo: https://gitea.planet-casio.com/Lephenixnoir/libprof.git
- name: justui
repo: https://gitea.planet-casio.com/Lephenixnoir/justui.git
- name: libp7
tag: "3.0"
- name: p7
tag: "3.0"
- name: p7screen
tag: "3.0"

4
scripts/build.sh Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
cd $1
makepkg -si --noconfirm && cp *.pkg.tar.zst /tmp/packages/

29
templates/fxlibc.j2 Normal file
View File

@ -0,0 +1,29 @@
# Maintainer: {{ maintainer }}
pkgname=fxlibc
pkgver={{ tag }}
pkgrel=1
pkgdesc="A C standard library for fx Casio calculators, built for gint"
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/${pkgname}"
licence=('unkwown')
depends=('fxsdk')
makedepends=('fxsdk')
options=('!buildflags' '!strip')
source=("$pkgname-$pkgver.tar.gz::https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc/archive/${pkgver}.tar.gz")
sha256sums=('{{ hash }}')
prepare() {
cd "${srcdir}/${pkgname}"
rm -rf build-gint
cmake -B build-gint -DFXLIBC_TARGET=gint -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-sh.cmake
}
build() {
cd "$srcdir/${pkgname}"
make -C build-gint
}
package() {
cd "$srcdir/${pkgname}"
make -C build-gint DESTDIR="$pkgdir" install
}

38
templates/fxsdk.j2 Normal file
View File

@ -0,0 +1,38 @@
# Maintainer: {{ maintainer }}
pkgname=fxsdk
pkgver={{ tag }}
pkgrel=1
pkgdesc='Tools to program for the Casio fx9860 calculators'
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/fxsdk"
licence=('unkwown')
depends=('cmake' 'libusb' 'mkg3a' 'python-pillow' 'sh-elf-gcc-casio')
makedepends=('cmake' 'gcc' 'libpng')
optdepends=(
'gint: alternative library and kernel for add-in development on fx-9860G and fx-CG50'
'udisks2: disk management service, for auto-mount of calculator')
provides=('fxconv' 'fxg1a' 'fxlink')
conflicts=('fxsdk-git')
options=('!buildflags')
source=("$pkgname-$pkgver.tar.gz::https://gitea.planet-casio.com/Lephenixnoir/${pkgname}/archive/${pkgver}.tar.gz")
sha256sums=('{{ hash }}')
prepare() {
cd "${srcdir}/${pkgname}"
# ensure a clean build
[[ -d build ]] && rm -rf build
mkdir build
}
build() {
cd "$srcdir/${pkgname}"
pacman -Q udisks2 &> /dev/null && udisks=0 || udisks=1
cmake -B build -DCMAKE_INSTALL_PREFIX="/usr" -DFXLINK_DISABLE_UDISKS2=$udisks
make -C build
}
package() {
cd "$srcdir/${pkgname}"
make DESTDIR="${pkgdir}" -C build install
}

34
templates/gint.j2 Normal file
View File

@ -0,0 +1,34 @@
# Maintainer: {{ maintainer }}
pkgname=gint
pkgver={{ tag }}
pkgrel=1
pkgdesc='Alternative library and kernel for add-in development on fx-9860G and fx-CG50 under Linux'
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/gint"
licence=('unkwown')
depends=('fxlibc' 'fxsdk' 'isl' 'openlibm-casio')
makedepends=('fxlibc' 'fxsdk' 'openlibm-casio')
conflicts=('gint-git')
options=('!buildflags' '!strip')
source=("$pkgname-$pkgver.tar.gz::https://gitea.planet-casio.com/Lephenixnoir/${pkgname}/archive/${pkgver}.tar.gz")
sha256sums=('{{ hash }}')
prepare() {
cd "${srcdir}/${pkgname}"
# ensure a clean build
fxsdk build-fx -c
fxsdk build-cg -c
}
build() {
cd "$srcdir/${pkgname}"
fxsdk build-fx
fxsdk build-cg
}
package() {
cd "$srcdir/${pkgname}"
fxsdk build-fx DESTDIR="$pkgdir" install
fxsdk build-cg DESTDIR="$pkgdir" install
}

33
templates/justui.j2 Normal file
View File

@ -0,0 +1,33 @@
# Maintainer: {{ maintainer }}
pkgname=justui
pkgver={{ tag }}
pkgrel=1
pkgdesc="Lephe's GUI toolkit for gint"
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/${pkgname}"
licence=('unkwown')
depends=('fxsdk' 'gint' 'openlibm-casio')
makedepends=('fxsdk' 'gint' 'openlibm-casio')
options=('!buildflags' '!strip')
source=("$pkgname-$pkgver.tar.gz::https://gitea.planet-casio.com/Lephenixnoir/${pkgname}/archive/${pkgver}.tar.gz")
sha256sums=('{{ hash }}')
prepare() {
cd "${srcdir}/${pkgname}"
# ensure a clean build
fxsdk build-fx -c
fxsdk build-cg -c
}
build() {
cd "$srcdir/${pkgname}"
fxsdk build-fx
fxsdk build-cg
}
package() {
cd "$srcdir/${pkgname}"
fxsdk build-fx DESTDIR="$pkgdir" install
fxsdk build-cg DESTDIR="$pkgdir" install
}

33
templates/libimg.j2 Normal file
View File

@ -0,0 +1,33 @@
# Maintainer: {{ maintainer }}
pkgname=libimg
pkgver={{ tag }}
pkgrel=1
pkgdesc="Lephe's GUI toolkit for gint"
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/${pkgname}"
licence=('unkwown')
depends=('fxsdk' 'gint')
makedepends=('fxsdk' 'gint')
options=('!buildflags' '!strip')
source=("$pkgname-$pkgver.tar.gz::https://gitea.planet-casio.com/Lephenixnoir/${pkgname}/archive/${pkgver}.tar.gz")
sha256sums=('{{ hash }}')
prepare() {
cd "${srcdir}/${pkgname}"
# ensure a clean build
fxsdk build-fx -c
fxsdk build-cg -c
}
build() {
cd "$srcdir/${pkgname}"
fxsdk build-fx
fxsdk build-cg
}
package() {
cd "$srcdir/${pkgname}"
fxsdk build-fx DESTDIR="$pkgdir" install
fxsdk build-cg DESTDIR="$pkgdir" install
}

33
templates/libp7.j2 Normal file
View File

@ -0,0 +1,33 @@
# Maintainer: Breizh <breizh@breizh.pm>
# Contributor: {{ maintainer }}
pkgname=libp7
pkgver={{ tag }}
pkgrel=1
pkgdesc="Casio Communication Protocol 7.00 implementation"
arch=('i686' 'x86_64')
url="https://p7.planet-casio.com"
license=('LGPL3')
groups=()
depends=('libusb>=1.0')
makedepends=('asciidoc>=8.6.9')
optdepends=()
provides=('libp7')
conflicts=()
replaces=()
backup=()
options=()
install=
changelog=
source=(https://p7.planet-casio.com/pub/${pkgname}-${pkgver}.tar.gz)
noextract=()
sha256sums=('{{ hash }}')
build() {
cd "$pkgname-$pkgver"
./configure --udev --udevrulesdir='${libdir}/udev/rules.d' && make
}
package() {
cd "$pkgname-$pkgver"
make install DESTDIR="$pkgdir"
}

33
templates/libprof.j2 Normal file
View File

@ -0,0 +1,33 @@
# Maintainer: {{ maintainer }}
pkgname=libprof
pkgver={{ tag }}
pkgrel=1
pkgdesc="A microsecond-level performance profiling library for gint"
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/${pkgname}"
licence=('unkwown')
depends=('fxsdk' 'gint')
makedepends=('fxsdk' 'gint')
options=('!buildflags' '!strip')
source=("$pkgname-$pkgver.tar.gz::https://gitea.planet-casio.com/Lephenixnoir/${pkgname}/archive/${pkgver}.tar.gz")
sha256sums=('{{ hash }}')
prepare() {
cd "${srcdir}/${pkgname}"
# ensure a clean build
fxsdk build-fx -c
fxsdk build-cg -c
}
build() {
cd "$srcdir/${pkgname}"
fxsdk build-fx
fxsdk build-cg
}
package() {
cd "$srcdir/${pkgname}"
fxsdk build-fx DESTDIR="$pkgdir" install
fxsdk build-cg DESTDIR="$pkgdir" install
}

26
templates/mkg3a.j2 Normal file
View File

@ -0,0 +1,26 @@
# Maintainer: Peter Marheine <peter@taricorp.net>
# Contributor: {{ maintainer }}
pkgname=mkg3a
pkgver={{ tag }}
pkgrel=1
pkgdesc="A tool to create Casio FX-CG addon (.g3a) files."
arch=('i686' 'x86_64')
url="https://gitlab.com/taricorp/mkg3a/"
license=('ZLIB')
depends=('libpng')
makedepends=('cmake')
source=(https://gitlab.com/taricorp/mkg3a/-/archive/${pkgver}/mkg3a-${pkgver}.tar.gz)
sha256sums=('{{ hash }}')
build() {
cd "$srcdir/mkg3a-$pkgver"
cmake -D CMAKE_INSTALL_PREFIX=/usr .
make
}
package() {
cd "$srcdir/mkg3a-$pkgver"
make DESTDIR="$pkgdir/" install
mkdir -p "$pkgdir/usr/share/licenses/$pkgname"
cp COPYING "$pkgdir/usr/share/licenses/$pkgname"
}

View File

@ -0,0 +1,32 @@
# Maintainer: {{ maintainer }}
pkgname=openlibm-casio
pkgver={{ tag }}
pkgrel=2
pkgdesc='Fork of the OpenLibm math library with support for fx-9860G and fx-CG 50'
arch=('i686' 'x86_64')
url="https://gitea.planet-casio.com/Lephenixnoir/OpenLibm"
licence=('custom')
makedepends=('sh-elf-gcc-casio')
options=('!buildflags' '!strip')
source=("$pkgname-$pkgver.tar.gz::https://gitea.planet-casio.com/Lephenixnoir/OpenLibm/archive/${pkgver}-sh3eb.tar.gz")
sha256sums=('{{ hash }}')
prepare() {
cd "${srcdir}/openlibm"
make clean
}
build() {
cd "$srcdir/openlibm"
_prefix=$(sh-elf-gcc --print-search-dirs | grep install | sed 's/install: //')
make USEGCC=1 TOOLPREFIX=sh-elf- CC=sh-elf-gcc AR=sh-elf-ar ARCH=sh3eb libdir="${_prefix}" includedir="${_prefix}/include" libopenlibm.a
}
package() {
cd "$srcdir/openlibm"
_prefix=$(sh-elf-gcc --print-search-dirs | grep install | sed 's/install: //')
make USEGCC=1 TOOLPREFIX=sh-elf- CC=sh-elf-gcc AR=sh-elf-ar ARCH=sh3eb libdir="${_prefix}" includedir="${_prefix}/include" DESTDIR="$pkgdir" install-static install-headers
# Install licence
install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

33
templates/p7.j2 Normal file
View File

@ -0,0 +1,33 @@
# Maintainer: Breizh <breizh.craft.98@openmailbox.org>
# Contributor: {{ maintainer }}
pkgname=p7
pkgver={{ tag }}
pkgrel=1
pkgdesc="Casio Communication Protocol 7.00 implementation"
arch=('i686' 'x86_64')
url="https://p7.planet-casio.com/"
license=('GPL2')
groups=()
depends=('libusb>=1.0' 'libp7>=3.0')
makedepends=('asciidoc>=8.6.9')
optdepends=()
provides=('p7')
conflicts=()
replaces=()
backup=()
options=()
install=
changelog=
source=(https://p7.planet-casio.com/pub/p7utils-${pkgver}.tar.gz)
sha256sums=('{{ hash }}')
noextract=()
build() {
cd "p7utils-$pkgver"
./configure && make all-p7
}
package() {
cd "p7utils-$pkgver"
make install-p7 DESTDIR="$pkgdir"
}

33
templates/p7screen.j2 Normal file
View File

@ -0,0 +1,33 @@
# Maintainer: Breizh <breizh.craft.98@openmailbox.org>
# Contributor: {{ maintainer }}
pkgname=p7screen
pkgver={{ tag }}
pkgrel=1
pkgdesc="Casio Communication Protocol 7.00 implementation"
arch=('i686' 'x86_64')
url="https://p7.planet-casio.com/"
license=('GPL2')
groups=()
depends=('libusb>=1.0' 'libp7>=3.0' 'sdl>=1.2.15')
makedepends=('asciidoc>=8.6.9')
optdepends=()
provides=('p7screen')
conflicts=()
replaces=()
backup=()
options=()
install=
changelog=
source=(https://p7.planet-casio.com/pub/p7utils-${pkgver}.tar.gz)
sha256sums=('{{ hash }}')
noextract=()
build() {
cd "p7utils-$pkgver"
./configure && make all-p7screen
}
package() {
cd "p7utils-$pkgver"
make install-p7screen DESTDIR="$pkgdir"
}

21
templates/run.sh.j2 Normal file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
useradd user
echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
pacman -U /tmp/packages/isl-0.24-1.tar.gz --no-confirm
pacman -U /tmp/packages/sh-elf-binutils-casio-2.36.1-3.tar.gz --no-confirm
pacman -U /tmp/packages/sh-elf-gcc-casio-11.1.0-4.tar.gz --no-confirm
pacman -U /tmp/packages/openlibm-casio-0.7.5-2.tar.gz --no-confirm
su -c '/tmp/build.sh /tmp/pkgbuilds/mkg3a' user
pacman -U /tmp/packages/fxsdk-2.5.1-1.tar.gz --no-confirm
su -c '/tmp/build.sh /tmp/pkgbuilds/fxlibc' user
su -c '/tmp/build.sh /tmp/pkgbuilds/gint' user
pacman -U /tmp/packages/libimg-2.4.0-1.tar.gz --no-confirm
pacman -U /tmp/packages/libprof-2.4.0-1.tar.gz --no-confirm
pacman -U /tmp/packages/justui-1.1.0-1.tar.gz --no-confirm
pacman -U /tmp/packages/libp7-3.0-1.tar.gz --no-confirm
pacman -U /tmp/packages/libp7-3.0-1.tar.gz --no-confirm
pacman -U /tmp/packages/p7screen-3.0-2.tar.gz --no-confirm
ls -l /tmp/packages

4
utils/__init__.py Normal file
View File

@ -0,0 +1,4 @@
from .middlearch import get_package_version, get_package_tarball
from .config import load_config, clean_directories
from .git import get_tags_from_git
from .pkgbuild import render_pkgbuild

21
utils/config.py Normal file
View File

@ -0,0 +1,21 @@
import logging
import os, shutil
import yaml
def load_config(path="packages.yaml"):
with open(path) as file:
packages = yaml.load(file, Loader=yaml.SafeLoader)
logging.info(f"{len(packages)} packages loaded")
logging.debug(", ".join([p['name'] for p in packages]))
return packages
def clean_directories():
for i in ["pkgbuilds", "packages"]:
try:
shutil.rmtree(i)
except FileNotFoundError:
pass
os.mkdir(i)

24
utils/git.py Normal file
View File

@ -0,0 +1,24 @@
import logging
import os
import re
def get_tags_from_git(remote):
regex = re.compile("^refs/tags/v?(\d+\.\d+\.\d+)$")
def extract_tag(tag):
m = regex.search(tag)
if m:
return m.groups()[0]
return ""
raw_tags = os.popen(f"git ls-remote --tags {remote}").read().split()
tags = sorted(
list(
filter(''.__ne__,
map(extract_tag, raw_tags)
),
)
)
logging.debug(f"{remote}: {', '.join(tags)}")
return tags[-1]

36
utils/middlearch.py Normal file
View File

@ -0,0 +1,36 @@
from io import BytesIO
import logging
import re
import requests as r
import tarfile
BASE_URL = "https://arch.middleearth.fr"
DB_NAME = "casio.db"
def get_from_regex(regex, package, arch):
file = BytesIO(r.get(f"{BASE_URL}/{arch}/{DB_NAME}").content)
db = tarfile.open(fileobj=file)
name = list(filter(
lambda item: item.isdir() and package in item.name,
db.getmembers()
))[0].name
return regex.search(name).group(1)
def get_package_version(package, arch):
regex = re.compile(".+-(\d+\.\d+(?:\.\d+)?)-\d+")
version = get_from_regex(regex, package, arch)
logging.debug(f"{package}: found {version}")
return version
def get_package_tarball(package, arch):
regex = re.compile("(.+)")
tarball = get_from_regex(regex, package, arch) + f"-{arch}.pkg.tar.xz"
logging.debug(f"{package}: found {tarball}")
return tarball, f"{BASE_URL}/{arch}/{tarball}"

38
utils/pkgbuild.py Normal file
View File

@ -0,0 +1,38 @@
import hashlib
import jinja2 as j2
import os
import re
import requests as r
MAINTAINER = "Eldeberen <eldeberen.aur@middleearth.fr>"
env = j2.Environment(
loader=j2.FileSystemLoader('templates'),
autoescape=j2.select_autoescape([])
)
def get_hash(name, tag):
regex = re.compile("^source=.+(https://.+\.tar\.[a-z]+)", re.MULTILINE)
with open(f"templates/{name}.j2") as file:
content = file.read()
try:
url = regex.search(content).group(1)
except:
return "SKIP"
url = url.replace("${pkgver}", tag)
url = url.replace("${pkgname}", name)
archive = r.get(url)
hash = hashlib.sha256(archive.content).hexdigest()
return hash
def render_pkgbuild(name, tag):
template = env.get_template(f"{name}.j2")
hash = get_hash(name, tag)
os.mkdir(f"pkgbuilds/{name}")
with open(f"pkgbuilds/{name}/PKGBUILD", "w") as file:
file.write(template.render(tag=tag, hash=hash, maintainer=MAINTAINER))