From 44923aa454a0fddc170e75981a5669708bc79fdb Mon Sep 17 00:00:00 2001 From: gfdgd-xi <3025613752@qq.com> Date: Mon, 26 Jun 2023 14:44:06 +0800 Subject: [PATCH] pardus-chroot --- gui/runner.py | 30 ++++++++++++++++++++++++++++++ gx-env-run | 8 +++++++- pardus-chroot | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 gui/runner.py create mode 100755 pardus-chroot diff --git a/gui/runner.py b/gui/runner.py new file mode 100644 index 0000000..84bc26d --- /dev/null +++ b/gui/runner.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import sys +import PyQt5.QtWidgets as QtWidgets + +app = QtWidgets.QApplication(sys.argv) +window = QtWidgets.QMainWindow() +widget = QtWidgets.QWidget() +layout = QtWidgets.QGridLayout() + +programPath = QtWidgets.QLineEdit() +browser = QtWidgets.QPushButton("浏览……") +runProgramWithRoot = QtWidgets.QCheckBox("以 root 权限运行应用") +layout.addWidget(QtWidgets.QLabel("""你可以在兼容模式下运行程序"""), 0, 0, 1, 4) +layout.addWidget(QtWidgets.QLabel("程序路径:"), 1, 0) +layout.addWidget(programPath, 1, 1, 1, 3) +#layout.addWidget(browser, 1, 3) + +controlLayout = QtWidgets.QHBoxLayout() +cancelButton = QtWidgets.QPushButton("取消") +okButton = QtWidgets.QPushButton("确定") +controlLayout.addWidget(runProgramWithRoot) +controlLayout.addWidget(browser) +controlLayout.addWidget(cancelButton) +controlLayout.addWidget(okButton) +layout.addLayout(controlLayout, 2, 2, 1, 2) + +widget.setLayout(layout) +window.setCentralWidget(widget) +window.show() +sys.exit(app.exec_()) \ No newline at end of file diff --git a/gx-env-run b/gx-env-run index 378dc25..51d568a 100755 --- a/gx-env-run +++ b/gx-env-run @@ -4,12 +4,18 @@ chrootEnvPath=/opt/new-system-env # echo 请使用 root 权限运行 # exit 1 #fi +if [[ -f ~/.config/gx-env/bwrap ]]; then + bwrap --dev-bind / / --dev-bind $chrootEnvPath/etc /etc --dev-bind $chrootEnvPath/opt /opt --dev-bind $chrootEnvPath/usr /usr --dev-bind $chrootEnvPath/var /var --dev-bind $chrootEnvPath/bin /bin --dev-bind $chrootEnvPath/boot /boot --dev-bind $chrootEnvPath/lib /lib --dev-bind $chrootEnvPath/lib32 /lib32 --dev-bind $chrootEnvPath/lib64 /lib64 --dev-bind $chrootEnvPath/libx32 /libx32 --dev-bind $chrootEnvPath/gx-env /gx-env "$@" + pkexec gx-env-load-desktop + exit +fi echo aa > /tmp/env-$USER.txt if [[ ! -f $chrootEnvPath/tmp/env-$USER.txt ]]; then echo 未挂载目录,立即挂载 - pkexec gx-env-mount-root + pkexec gx-env-init fi command="$@" #echo $command pkexec env DISPLAY=$DISPLAY chroot $chrootEnvPath sudo -u $USER bash -c "$command" #echo $@ +pkexec gx-env-load-desktop \ No newline at end of file diff --git a/pardus-chroot b/pardus-chroot new file mode 100755 index 0000000..7ae43f6 --- /dev/null +++ b/pardus-chroot @@ -0,0 +1,38 @@ +#!/bin/bash +set +e +DESTDIR="$1" +if [[ $UID -ne 0 ]] ; then + echo "You must be root!" + exit 1 +fi +if [[ -b "$1" ]] ; then + DESTDIR=$(mktemp -d) + mount "$1" "$DESTDIR" +fi +shift +if [[ "$DESTDIR" == "" || ! -f "$DESTDIR/etc/os-release" ]] ; then + echo "Target filesystem is invalid: $DESTDIR" + exit 1 +fi +mount --bind /dev "$DESTDIR/dev" +mount --bind /run "$DESTDIR/run" +mount --bind /media "$DESTDIR/media" +mount -t devpts devpts "$DESTDIR/dev/pts" +mount -t sysfs sysfs "$DESTDIR/sys" +mount -t proc proc "$DESTDIR/proc" +mount -t tmpfs tmpfs "$DESTDIR/dev/shm" +mount --bind /tmp "$DESTDIR/tmp" +if [[ -d /sys/firmware/efi/ ]] ; then + mount -t efivarfs efivarfs "$DESTDIR/sys/firmware/efi/efivars" +fi +#cat /etc/resolv.conf > $DESTDIR/etc/resolv.conf +#SHELL=/bin/bash unshare --fork --pid chroot "$DESTDIR" "$@" +#exit +# 下面的因为有问题,不使用 +#if [[ -d /sys/firmware/efi/ ]] ; then +# while umount "$DESTDIR/sys/firmware/efi/efivars" 2>/dev/null ; do : ;done +#fi +#for dir in dev/pts dev/shm dev sys proc run media ; do +# while umount "$DESTDIR/$dir" 2>/dev/null; do : ;done +#done +#umount -lf "$DESTDIR" 2>/dev/null