Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Seshpenguin committed Apr 26, 2023
1 parent 81842bc commit cf8c7da
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 83 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ProLinux 2 Plasma Mobile Nightly Edition piggy-backs on parts of postmarketOS (i
- simg2img (android-tools)
- pigz
- util-linux (for Alpine)
- zsync

Environment Configuration (.env):
```env
Expand Down
75 changes: 75 additions & 0 deletions misc/generate_wallpaper_sizes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3

# from https://invent.kde.org/plasma/breeze/-/blob/master/wallpapers/generate_wallpaper_sizes.py

import logging
from multiprocessing import cpu_count
from multiprocessing.pool import Pool
from pathlib import Path
from itertools import chain
from typing import Final

try:
import PIL
from PIL import Image
except ImportError:
logging.critical("Please install the python PIL library.")
logging.critical("e.g.: python3 -m pip install PIL")
exit()

sizes = {
'horizontal': (
(5120, 2880), (3840, 2160), (3200, 2000), (3200, 1800),
(2560, 1600), (2560, 1440), (1920, 1200), (1920, 1080),
(1680, 1050), (1600, 1200), (1440, 900), (1366, 768),
(1280, 1024), (1280, 800), (1024, 768), (440, 247)
),
'vertical': ((720, 1440), (360, 720), (1080, 1920))
}

templates = {
'horizontal': ('base_size.png', 'base_size.jpg'),
'vertical': ('vertical_base_size.png', 'vertical_base_size.jpg')
}

PIL_VERSION: Final = tuple(map(int, PIL.__version__.split(".")))


def resize_and_save_image(file: Path, image: Image, width: int, height: int) -> None:
"""
Image.LANCZOS is deprecated since 9.1.0 https://pillow.readthedocs.io/en/stable/deprecations.html#constants
"""
logging.info(f'Generating {width}x{height}')

base_dir, extension = file.parent, file.suffix
base_width, base_height = image.size

if width / height > base_width / base_height:
crop = int(base_height - height / (width / base_width)) // 2
box = (0, crop, base_width, base_height - crop)
elif width / height < base_width / base_height:
crop = int(base_width - width / (height / base_height)) // 2
box = (crop, 0, base_width - crop, base_height)
else:
box = None

if PIL_VERSION >= (9, 1):
resized_image = image.resize((width, height), Image.Resampling.LANCZOS, box)
else:
resized_image = image.resize((width, height), Image.LANCZOS, box)

resized_image.save(base_dir / f'{width}x{height}{extension}',
quality=90, optimize=True, subsampling=1)


argument_list: list[tuple] = []

for orientation in ('horizontal', 'vertical'):
for file in chain(*map(Path().rglob, templates[orientation])):
image = Image.open(file)
image.load();
for width, height in sizes[orientation]:
argument_list.append((file, image, width, height))

with Pool(processes=cpu_count()) as pool:
pool.starmap(resize_and_save_image, argument_list)
90 changes: 7 additions & 83 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { createAndMountPMOSImage, genPMOSImage, pmosFinalCleanup } from './pmboo
import axios from 'axios';
import { v4 as uuidv4 } from 'uuid';
import { compileKexecTools } from './custom-packages/kexec-tools';
import { buildMobileDev } from './os-variants/mobile/mobile-dev';
import { buildEmbedded } from './os-variants/embedded/embedded';

console.log("Starting ProLinux build on " + new Date().toLocaleString());

Expand Down Expand Up @@ -131,90 +133,12 @@ EOF`);
popd
`);

/* ------------- kdesrc-build ------------- */
if(PROLINUX_VARIANT === "mobile" && PROLINUX_CHANNEL === "dev") {
const exportEnv = (arch === "arm64") ? [
//"export CC='ccache distcc'",
//"export CXX='ccache distcc g++'",
//"export DISTCC_HOSTS='192.168.11.138/20'",
"export CC='ccache gcc'",
"export CXX='ccache g++'",
] : [
"export CC='ccache gcc'",
"export CXX='ccache g++'",
]

// @ts-ignore
const checkoutBranches: [[string, string]] = [
//["kio", "076337fd"]
//["kwin", "master"]
]

//const packagesToBuild = "kcmutils plasma5support kirigami-addons plasma-mobile plasma-pa plasma-nm qqc2-breeze-style"
const packagesToBuild = "extra-cmake-modules kcoreaddons ki18n kconfig plasma-wayland-protocols karchive kdoctools kwidgetsaddons polkit-qt-1 kcodecs kauth kguiaddons kwindowsystem kconfigwidgets kdbusaddons kcrash kiconthemes kcompletion kitemviews sonnet kglobalaccel kservice ktextwidgets gpgme qca knotifications kxmlgui kbookmarks kjobwidgets kwallet solid kactivities kpackage kcmutils kio kirigami kdeclarative kwayland kidletime oxygen-icons5 breeze-icons kparts syntax-highlighting kdnssd kitemmodels ktexteditor kunitconversion threadweaver attica kcmutils plasma-framework syndication knewstuff frameworkintegration kdecoration layer-shell-qt libkscreen poppler krunner breeze kscreenlocker libqaccessibilityclient zxing-cpp phonon kfilemetadata kpty networkmanager-qt kpipewire kwin libkexiv2 selenium-webdriver-at-spi baloo kactivities-stats kded kdesu kholidays knotifyconfig kpeople kquickcharts modemmanager-qt prison libksysguard plasma-nano kuserfeedback kirigami-addons plasma5support plasma-workspace bluez-qt milou plasma-mobile plasma-nm plasma-pa qqc2-breeze-style plasma-settings kactivitymanagerd ksystemstats qqc2-desktop-style kscreen powerdevil plasma-desktop bluedevil"

// todo remove ssh-keygen -A from here
if(process.env.KDE_CACHE === "true") {
console.log("Using cached KDE build");
exec(`sudo mkdir -pv ${ROOTFS_DIR}/opt/kde/ && sudo tar --exclude='src' -xvf ${BUILD_DIR}/kde-cache.tar -C ${ROOTFS_DIR}/opt/kde/`);
} else {
exec(`mkdir -pv ${BUILD_DIR}/cache`);
exec(`mkdir -pv ${BUILD_DIR}/cache-src`);
// mount cache folder into rootfs /home/user/.cache
exec(`sudo mount --bind ${BUILD_DIR}/cache ${ROOTFS_DIR}/home/user/.cache`);
exec(`sudo mount --bind ${BUILD_DIR}/cache-src ${ROOTFS_DIR}/opt/kde/src`);

exec(`sudo arch-chroot ${ROOTFS_DIR} /bin/bash -x <<'EOF'
set -e
chown -R user:user /home/user
mkdir -pv /opt/kde
chown -R user:user /opt/kde
${arch === "arm64" ? 'ln -s /usr/bin/aarch64-unknown-linux-gnu-g++ "/usr/bin/ distcc g++"' : ''}
${arch === "arm64" ? 'ln -s /usr/bin/aarch64-unknown-linux-gnu-g++ "/usr/bin/ g++"' : ''}
${arch === "x64" ? 'ln -s /usr/bin/g++ "/usr/bin/ g++"' : ''}
sudo -u user bash << EOFSU
set -e
whoami
${exportEnv.join("; ")}
export CCACHE_LOGFILE=/home/user/.cache/ccache.log
cd /opt/kde
mkdir -p /opt/kde/src
cd /opt/kde/src
rm -rf kdesrc-build
git clone https://invent.kde.org/sdk/kdesrc-build.git
cd kdesrc-build
./kdesrc-build --version
yes | ./kdesrc-build --initial-setup
./kdesrc-build --metadata-only
./kdesrc-build --src-only ${packagesToBuild}
${checkoutBranches.map(([repo, branch]) => `cd /opt/kde/src/${repo} && git checkout ${branch} && cd /opt/kde/src/kdesrc-build`).join("; ")}
${packagesToBuild.split(" ").map((p, i, a) => `mold -run ./kdesrc-build --stop-on-failure --no-include-dependencies --no-src ${p}; echo "-- ✅ Built ${i} of ${a.length}!"`).join("; ")}
EOFSU
sleep 2
EOF`);
exec(`sudo tar --exclude='src' -cvf ${BUILD_DIR}/kde-cache.tar -C ${ROOTFS_DIR}/opt/kde/ .`);
}
// ${packagesToBuild.split(" ").map((p) => `find /opt/kde/src/${p} -name CMakeLists.txt -exec sed -i '1i include_directories(/opt/kde/usr/include)' {} \\;`).join("; ")}
// ${packagesToBuild.split(" ").map((p) => `find /opt/kde/src/${p} -name CMakeLists.txt -exec sed -i '1i include_directories(/opt/kde/usr/include/KF6)' {} \\;`).join("; ")}
exec(`sudo arch-chroot ${ROOTFS_DIR} /bin/bash -x <<'EOF'
set -e
mkdir -pv /usr/share/xsessions/ /usr/share/wayland-sessions/ /etc/dbus-1/
/opt/kde/build/plasma-workspace/login-sessions/install-sessions.sh
/opt/kde/build/plasma-mobile/bin/install-sessions.sh
EOF`);
// unmount cache folder
exec(`sudo umount ${ROOTFS_DIR}/home/user/.cache || true`);
exec(`sudo rm -rf ${BUILD_DIR}/home/user/.cache`);
exec(`sudo umount ${ROOTFS_DIR}/opt/kde/src || true`);
} // end of kdesrc-build

/* ------------- ProLinux Embedded ------------- */
if(PROLINUX_VARIANT === "embedded") {
exec(`sudo arch-chroot ${ROOTFS_DIR} /bin/bash -x <<'EOF'
sudo pacman -S --noconfirm plasma-meta plasma-wayland-session konsole firefox dolphin
EOF`);

/* ------------- ProLinux Mobile Dev (Plasma Mobile Nightly / kdesrc-build ) ------------- */
await buildMobileDev();
} else if(PROLINUX_VARIANT === "embedded") {
/* ------------- ProLinux Embedded ------------- */
buildEmbedded();
} // end of embedded

exec(`sudo arch-chroot ${ROOTFS_DIR} /bin/bash -x <<'EOF'
Expand Down
8 changes: 8 additions & 0 deletions src/os-variants/embedded/embedded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import exec from "../../helpers/exec";
import { BUILD_DIR, ROOTFS_DIR, OUTPUT_DIR, FILES_DIR, arch, TARGET_DEVICE, PROLINUX_CHANNEL, PROLINUX_VARIANT } from '../../helpers/consts';

export async function buildEmbedded() {
exec(`sudo arch-chroot ${ROOTFS_DIR} /bin/bash -x <<'EOF'
sudo pacman -S --noconfirm plasma-meta plasma-wayland-session konsole firefox dolphin
EOF`);
}
83 changes: 83 additions & 0 deletions src/os-variants/mobile/mobile-dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import exec from "../../helpers/exec";
import { BUILD_DIR, ROOTFS_DIR, OUTPUT_DIR, FILES_DIR, arch, TARGET_DEVICE, PROLINUX_CHANNEL, PROLINUX_VARIANT } from '../../helpers/consts';


export async function buildMobileDev() {
const exportEnv = (arch === "arm64") ? [
//"export CC='ccache distcc'",
//"export CXX='ccache distcc g++'",
//"export DISTCC_HOSTS='192.168.11.138/20'",
"export CC='ccache gcc'",
"export CXX='ccache g++'",
] : [
"export CC='ccache gcc'",
"export CXX='ccache g++'",
]

// @ts-ignore
const checkoutBranches: [[string, string]] = [
//["kio", "076337fd"]
//["kwin", "master"]
]

//const packagesToBuild = "kcmutils plasma5support kirigami-addons plasma-mobile plasma-pa plasma-nm qqc2-breeze-style"
const packagesToBuild = "extra-cmake-modules kcoreaddons ki18n kconfig plasma-wayland-protocols karchive kdoctools kwidgetsaddons polkit-qt-1 kcodecs kauth kguiaddons kwindowsystem kconfigwidgets kdbusaddons kcrash kiconthemes kcompletion kitemviews sonnet kglobalaccel kservice ktextwidgets gpgme qca knotifications kxmlgui kbookmarks kjobwidgets kwallet solid kactivities kpackage kcmutils kio kirigami kdeclarative kwayland kidletime oxygen-icons5 breeze-icons kparts syntax-highlighting kdnssd kitemmodels ktexteditor kunitconversion threadweaver attica kcmutils plasma-framework syndication knewstuff frameworkintegration kdecoration layer-shell-qt libkscreen poppler krunner breeze kscreenlocker libqaccessibilityclient zxing-cpp phonon kfilemetadata kpty networkmanager-qt kpipewire kwin libkexiv2 selenium-webdriver-at-spi baloo kactivities-stats kded kdesu kholidays knotifyconfig kpeople kquickcharts modemmanager-qt prison libksysguard plasma-nano kuserfeedback kirigami-addons plasma5support plasma-workspace bluez-qt milou plasma-mobile plasma-nm plasma-pa qqc2-breeze-style plasma-settings kactivitymanagerd ksystemstats qqc2-desktop-style kscreen powerdevil plasma-desktop bluedevil"

// todo remove ssh-keygen -A from here
if(process.env.KDE_CACHE === "true") {
console.log("Using cached KDE build");
exec(`sudo mkdir -pv ${ROOTFS_DIR}/opt/kde/ && sudo tar --exclude='src' -xvf ${BUILD_DIR}/kde-cache.tar -C ${ROOTFS_DIR}/opt/kde/`);
} else {
exec(`mkdir -pv ${BUILD_DIR}/cache`);
exec(`mkdir -pv ${BUILD_DIR}/cache-src`);
// mount cache folder into rootfs /home/user/.cache
exec(`sudo mount --bind ${BUILD_DIR}/cache ${ROOTFS_DIR}/home/user/.cache`);
exec(`sudo mount --bind ${BUILD_DIR}/cache-src ${ROOTFS_DIR}/opt/kde/src`);

exec(`sudo arch-chroot ${ROOTFS_DIR} /bin/bash -x <<'EOF'
set -e
chown -R user:user /home/user
mkdir -pv /opt/kde
chown -R user:user /opt/kde
${arch === "arm64" ? 'ln -s /usr/bin/aarch64-unknown-linux-gnu-g++ "/usr/bin/ distcc g++"' : ''}
${arch === "arm64" ? 'ln -s /usr/bin/aarch64-unknown-linux-gnu-g++ "/usr/bin/ g++"' : ''}
${arch === "x64" ? 'ln -s /usr/bin/g++ "/usr/bin/ g++"' : ''}
sudo -u user bash << EOFSU
set -e
whoami
${exportEnv.join("; ")}
export CCACHE_LOGFILE=/home/user/.cache/ccache.log
cd /opt/kde
mkdir -p /opt/kde/src
cd /opt/kde/src
rm -rf kdesrc-build
git clone https://invent.kde.org/sdk/kdesrc-build.git
cd kdesrc-build
./kdesrc-build --version
yes | ./kdesrc-build --initial-setup
./kdesrc-build --metadata-only
./kdesrc-build --src-only ${packagesToBuild}
${checkoutBranches.map(([repo, branch]) => `cd /opt/kde/src/${repo} && git checkout ${branch} && cd /opt/kde/src/kdesrc-build`).join("; ")}
${packagesToBuild.split(" ").map((p, i, a) => `mold -run ./kdesrc-build --stop-on-failure --no-include-dependencies --no-src ${p}; echo "-- ✅ Built ${i} of ${a.length}!"`).join("; ")}
EOFSU
sleep 2
EOF`);
exec(`sudo tar --exclude='src' -cvf ${BUILD_DIR}/kde-cache.tar -C ${ROOTFS_DIR}/opt/kde/ .`);
} /* end of kde-cache else */

// ${packagesToBuild.split(" ").map((p) => `find /opt/kde/src/${p} -name CMakeLists.txt -exec sed -i '1i include_directories(/opt/kde/usr/include)' {} \\;`).join("; ")}
// ${packagesToBuild.split(" ").map((p) => `find /opt/kde/src/${p} -name CMakeLists.txt -exec sed -i '1i include_directories(/opt/kde/usr/include/KF6)' {} \\;`).join("; ")}

exec(`sudo arch-chroot ${ROOTFS_DIR} /bin/bash -x <<'EOF'
set -e
mkdir -pv /usr/share/xsessions/ /usr/share/wayland-sessions/ /etc/dbus-1/
/opt/kde/build/plasma-workspace/login-sessions/install-sessions.sh
/opt/kde/build/plasma-mobile/bin/install-sessions.sh
EOF`);

// unmount cache folder
exec(`sudo umount ${ROOTFS_DIR}/home/user/.cache || true`);
exec(`sudo rm -rf ${BUILD_DIR}/home/user/.cache`);
exec(`sudo umount ${ROOTFS_DIR}/opt/kde/src || true`);
}
Empty file.

0 comments on commit cf8c7da

Please sign in to comment.