From 669b428504f26b149fd054038f55432982c056e4 Mon Sep 17 00:00:00 2001 From: Amir Husayn Panahifar Date: Sat, 3 May 2025 19:58:47 +0330 Subject: [PATCH] Add project build and test process of ParchLinux WSL --- Makefile | 13 ++++ rootfs/etc/locale.conf | 10 +++ rootfs/etc/pacman.conf | 109 ++++++++++++++++++++++++++++++ rootfs/etc/pacman.d/mirrorlist | 3 + rootfs/etc/pacman.d/parch-mirrors | 1 + rootfs/etc/wsl-distribution.conf | 6 ++ rootfs/etc/wsl.conf | 2 + rootfs/usr/lib/wsl/archlinux.ico | 0 rootfs/usr/lib/wsl/first-setup.sh | 17 +++++ scripts/build-image.sh | 47 +++++++++++++ scripts/exclude | 16 +++++ scripts/test-image.sh | 29 ++++++++ 12 files changed, 253 insertions(+) create mode 100644 Makefile create mode 100644 rootfs/etc/locale.conf create mode 100644 rootfs/etc/pacman.conf create mode 100644 rootfs/etc/pacman.d/mirrorlist create mode 100644 rootfs/etc/pacman.d/parch-mirrors create mode 100644 rootfs/etc/wsl-distribution.conf create mode 100644 rootfs/etc/wsl.conf create mode 100644 rootfs/usr/lib/wsl/archlinux.ico create mode 100755 rootfs/usr/lib/wsl/first-setup.sh create mode 100755 scripts/build-image.sh create mode 100644 scripts/exclude create mode 100755 scripts/test-image.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..aa33b91 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +WORKDIR=$(shell pwd)/workdir +IMAGE_VERSION ?= $(shell date +"%Y.%m.%d") + +.PHONY: build test clean + +build: + scripts/build-image.sh $(WORKDIR) $(IMAGE_VERSION) + +test: + scripts/test-image.sh $(WORKDIR) $(IMAGE_VERSION) + +clean: + rm -rf $(WORKDIR) diff --git a/rootfs/etc/locale.conf b/rootfs/etc/locale.conf new file mode 100644 index 0000000..70edb1d --- /dev/null +++ b/rootfs/etc/locale.conf @@ -0,0 +1,10 @@ +LANG=C.UTF-8 +LC_ADDRESS=fa_IR +LC_IDENTIFICATION=fa_IR +LC_MEASUREMENT=fa_IR +LC_MONETARY=fa_IR +LC_NAME=fa_IR +LC_NUMERIC=fa_IR +LC_PAPER=fa_IR +LC_TELEPHONE=fa_IR +LC_TIME=fa_IR diff --git a/rootfs/etc/pacman.conf b/rootfs/etc/pacman.conf new file mode 100644 index 0000000..61b99c5 --- /dev/null +++ b/rootfs/etc/pacman.conf @@ -0,0 +1,109 @@ +# +# /etc/pacman.conf +# +# See the pacman.conf(5) manpage for option and repository directives + +# +# GENERAL OPTIONS +# +[options] +# The following paths are commented out with their default values listed. +# If you wish to use different paths, uncomment and update the paths. +#RootDir = / +#DBPath = /var/lib/pacman/ +#CacheDir = /var/cache/pacman/pkg/ +#LogFile = /var/log/pacman.log +#GPGDir = /etc/pacman.d/gnupg/ +#HookDir = /etc/pacman.d/hooks/ +HoldPkg = pacman glibc +#XferCommand = /usr/bin/curl -L -C - -f -o %o %u +#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u +#CleanMethod = KeepInstalled +Architecture = auto + +# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup +#IgnorePkg = +#IgnoreGroup = + +#NoUpgrade = +#NoExtract = + +# Misc options +#UseSyslog +ILoveCandy +Color +#NoProgressBar +CheckSpace +VerbosePkgLists +ParallelDownloads = 3 +DownloadUser = alpm +#DisableSandbox +DisableDownloadTimeout +ILoveCandy +# By default, pacman accepts packages signed by keys that its local keyring +# trusts (see pacman-key and its man page), as well as unsigned packages. +SigLevel = Required DatabaseOptional +LocalFileSigLevel = Optional +#RemoteFileSigLevel = Required + +# NOTE: You must run `pacman-key --init` before first using pacman; the local +# keyring can then be populated with the keys of all official Arch Linux +# packagers with `pacman-key --populate archlinux`. + +# +# REPOSITORIES +# - can be defined here or included from another file +# - pacman will search repositories in the order defined here +# - local/custom mirrors can be added here or in separate files +# - repositories listed first will take precedence when packages +# have identical names, regardless of version number +# - URLs will have $repo replaced by the name of the current repo +# - URLs will have $arch replaced by the name of the architecture +# +# Repository entries are of the format: +# [repo-name] +# Server = ServerName +# Include = IncludePath +# +# The header [repo-name] is crucial - it must be present and +# uncommented to enable the repo. +# + +# The testing repositories are disabled by default. To enable, uncomment the +# repo name header and Include lines. You can add preferred servers immediately +# after the header, and they will be used before the default mirrors. + +#[core-testing] +#Include = /etc/pacman.d/mirrorlist + +[core] +Include = /etc/pacman.d/mirrorlist + +#[extra-testing] +#Include = /etc/pacman.d/mirrorlist + +[extra] +Include = /etc/pacman.d/mirrorlist + +# If you want to run 32 bit applications on your x86_64 system, +# enable the multilib repositories as required here. + +#[multilib-testing] +#Include = /etc/pacman.d/mirrorlist + +[multilib] +Include = /etc/pacman.d/mirrorlist + +[ppr] +SigLevel = Optional TrustAll +Include = /etc/pacman.d/parch-mirrors + +[pcp] +SigLevel = Optional TrustAll +Include = /etc/pacman.d/parch-mirrors + +# An example of a custom package repository. See the pacman manpage for +# tips on creating your own repositories. +#[custom] +#SigLevel = Optional TrustAll +#Server = file:///home/custompkgs \ No newline at end of file diff --git a/rootfs/etc/pacman.d/mirrorlist b/rootfs/etc/pacman.d/mirrorlist new file mode 100644 index 0000000..495d883 --- /dev/null +++ b/rootfs/etc/pacman.d/mirrorlist @@ -0,0 +1,3 @@ +Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch +Server = https://mirror.rackspace.com/archlinux/$repo/os/$arch +Server = https://mirror.leaseweb.net/archlinux/$repo/os/$arch diff --git a/rootfs/etc/pacman.d/parch-mirrors b/rootfs/etc/pacman.d/parch-mirrors new file mode 100644 index 0000000..ba8fea4 --- /dev/null +++ b/rootfs/etc/pacman.d/parch-mirrors @@ -0,0 +1 @@ +Server = https://mirror.parchlinux.com/repos/$repo/$arch diff --git a/rootfs/etc/wsl-distribution.conf b/rootfs/etc/wsl-distribution.conf new file mode 100644 index 0000000..2cd9c34 --- /dev/null +++ b/rootfs/etc/wsl-distribution.conf @@ -0,0 +1,6 @@ +[oobe] +command = /usr/lib/wsl/first-setup.sh +defaultName = parchlinux + +[shortcut] +icon = /usr/lib/wsl/parchlinux.ico diff --git a/rootfs/etc/wsl.conf b/rootfs/etc/wsl.conf new file mode 100644 index 0000000..a544c09 --- /dev/null +++ b/rootfs/etc/wsl.conf @@ -0,0 +1,2 @@ +[boot] +systemd=true diff --git a/rootfs/usr/lib/wsl/archlinux.ico b/rootfs/usr/lib/wsl/archlinux.ico new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/usr/lib/wsl/first-setup.sh b/rootfs/usr/lib/wsl/first-setup.sh new file mode 100755 index 0000000..02f09f3 --- /dev/null +++ b/rootfs/usr/lib/wsl/first-setup.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Show some documentation +cat <. + +Please, report bugs at . +Note that WSL 1 is not supported. + +For more information about this WSL image and its usage (including "tips and tricks" and troubleshooting steps), see the related Arch Wiki page at . + +While images are built regularly, it is strongly recommended running "pacman -Syu" right after the first launch due to the rolling release nature of Parch Linux. +EOF + +echo -e "\nGenerating pacman keys..." && pacman-key --init 2> /dev/null && echo "Done" \ No newline at end of file diff --git a/scripts/build-image.sh b/scripts/build-image.sh new file mode 100755 index 0000000..01e2d02 --- /dev/null +++ b/scripts/build-image.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -euo pipefail + +declare -r WORKDIR="$1" +declare -r BUILDDIR="$WORKDIR/build" +declare -r OUTPUTDIR="$WORKDIR/output" +declare -r IMAGE_VERSION="$2" + +mkdir -vp "$BUILDDIR/alpm-hooks/usr/share/libalpm/hooks" +find /usr/share/libalpm/hooks -exec ln -sf /dev/null "$BUILDDIR/alpm-hooks"{} \; + +mkdir -vp "$BUILDDIR/var/lib/pacman/" "$OUTPUTDIR" +install -Dm 644 "/usr/share/devtools/pacman.conf.d/extra.conf" "$BUILDDIR/etc/pacman.conf" + +sed 's/Include = /&rootfs/g' < "$BUILDDIR/etc/pacman.conf" > "$WORKDIR/pacman.conf" + +cp --recursive --preserve=timestamps rootfs/* "$BUILDDIR/" +ln -sf /usr/lib/os-release "$BUILDDIR/etc/os-release" + +fakechroot -- fakeroot -- \ + pacman -Sy -r "$BUILDDIR" \ + --noconfirm --dbpath "$BUILDDIR/var/lib/pacman" \ + --config "$WORKDIR/pacman.conf" \ + --noscriptlet \ + --hookdir "$BUILDDIR/alpm-hooks/usr/share/libalpm/hooks/" base + +fakechroot -- fakeroot -- chroot "$BUILDDIR" update-ca-trust +fakechroot -- fakeroot -- chroot "$BUILDDIR" pacman-key --init +fakechroot -- fakeroot -- chroot "$BUILDDIR" pacman-key --populate +fakechroot -- fakeroot -- chroot "$BUILDDIR" /usr/bin/systemd-sysusers --root "/" +fakechroot -- fakeroot -- chroot "$BUILDDIR" /usr/bin/systemctl mask systemd-firstboot + +fakeroot -- \ + tar \ + --numeric-owner \ + --xattrs \ + --acls \ + --exclude-from=scripts/exclude \ + -C "$BUILDDIR" \ + -c . \ + -f "$OUTPUTDIR/parchlinux-$IMAGE_VERSION.tar" + +cd "$OUTPUTDIR" +xz -T0 -9 "parchlinux-$IMAGE_VERSION.tar" +mv -v "parchlinux-$IMAGE_VERSION.tar.xz" "parchlinux-$IMAGE_VERSION.wsl" +sha256sum "parchlinux-$IMAGE_VERSION.wsl" > "parchlinux-$IMAGE_VERSION.wsl.SHA256" diff --git a/scripts/exclude b/scripts/exclude new file mode 100644 index 0000000..ee088a5 --- /dev/null +++ b/scripts/exclude @@ -0,0 +1,16 @@ +./sys +./proc +./dev +./etc/hostname +./etc/machine-id +./etc/resolv.conf +./etc/pacman.d/gnupg/openpgp-revocs.d/* +./etc/pacman.d/gnupg/private-keys-v1.d/* +./etc/pacman.d/gnupg/pubring.gpg~ +./etc/pacman.d/gnupg/S.* +./root/* +./tmp/* +./var/cache/pacman/pkg/* +./var/lib/pacman/sync/* +./var/tmp/* +./alpm-hooks diff --git a/scripts/test-image.sh b/scripts/test-image.sh new file mode 100755 index 0000000..6490e01 --- /dev/null +++ b/scripts/test-image.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -euo pipefail + +declare -r WORKDIR="$1" +declare -r BUILDDIR="$WORKDIR/build" +declare -r OUTPUTDIR="$WORKDIR/output" +declare -r CLONEDIR="$WORKDIR/clone" +declare -r VENVDIR="$WORKDIR/venv" +declare -r IMAGE_VERSION="$2" + +fakechroot -- fakeroot -- chroot "$BUILDDIR" test "$(wc -l /etc/group | awk '{print $1}')" -gt 10 +fakechroot -- fakeroot -- chroot "$BUILDDIR" test "$(wc -l /etc/passwd | awk '{print $1}')" -gt 10 +fakechroot -- fakeroot -- chroot "$BUILDDIR" pacman -Sy +fakechroot -- fakeroot -- chroot "$BUILDDIR" pacman -Qqk +fakechroot -- fakeroot -- chroot "$BUILDDIR" pacman -Syu --noconfirm podman grep +fakechroot -- fakeroot -- chroot "$BUILDDIR" podman -v +fakechroot -- fakeroot -- chroot "$BUILDDIR" id -u http +fakechroot -- fakeroot -- chroot "$BUILDDIR" locale | grep -q UTF-8 + +if [ -d "$CLONEDIR" ]; then + git -C "$CLONEDIR" pull https://github.com/microsoft/WSL.git +else + git clone https://github.com/microsoft/WSL.git "$CLONEDIR" +fi +python -m venv "$VENVDIR" +export PATH="$VENVDIR/bin:$PATH" +pip install -r "$CLONEDIR/distributions/requirements.txt" +python "$CLONEDIR/distributions/validate-modern.py" --tar "$OUTPUTDIR/parchlinux-$IMAGE_VERSION.wsl"