From f6698e2f3963e8555f83447c5e5414b2eb09b089 Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Sat, 3 Dec 2022 21:47:05 +0800 Subject: [PATCH] =?UTF-8?q?Qemu=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangePassword.sh | 2 ++ Mount.sh | 2 +- QemuRun.py | 19 +++++++++++++++++-- UnMount.sh | 11 ++++++++++- mainwindow.py | 19 ++++++++++++++++++- 5 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 ChangePassword.sh diff --git a/ChangePassword.sh b/ChangePassword.sh new file mode 100644 index 0000000..020586e --- /dev/null +++ b/ChangePassword.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo -e "123456\n123456\n\n\n\n\n\n\n\n\n" | adduser "$1" \ No newline at end of file diff --git a/Mount.sh b/Mount.sh index 45c0d7a..bd8d06b 100755 --- a/Mount.sh +++ b/Mount.sh @@ -28,7 +28,7 @@ mount -o bind /usr/share/fonts ./usr/share/fonts # 配置用户 if [ ! -d "home/$2" ]; then # 新建用户,且密码为 123456,以便读写 - chroot . echo -e "123456\n123456\n\n\n\n\n\n\n\n\n" | adduser "$2" + chroot . bash /opt/apps/deepin-wine-runner/ChangePassword.sh "$2" fi # 挂载用户目录到 /root(默认 $HOME 路径) if [[ $2 == "root" ]]; then diff --git a/QemuRun.py b/QemuRun.py index eda1857..77bcd5f 100755 --- a/QemuRun.py +++ b/QemuRun.py @@ -7,7 +7,7 @@ import PyQt5.QtWidgets as QtWidgets if __name__ == "__main__": programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string homePath = os.getenv("HOME") - if len(sys.argv) <= 2: + if len(sys.argv) <= 1: print("参数不足") sys.exit(1) app = QtWidgets.QApplication(sys.argv) @@ -19,8 +19,23 @@ if __name__ == "__main__": userName = getpass.getuser() for i in sys.argv[2:]: commandList += f"'{i}' " + if commandList.replace(" ", "") == "": + commandList = "bash" + # 需要先取消挂载其它目录以防止冲突 + path = f"{homePath}/.deepin-wine-runner-ubuntu-images" + for i in os.listdir(path): + archPath = f"{path}/{i}" + if os.path.isdir(archPath): + for k in os.listdir(archPath): + bottlePath = f"{archPath}/{k}" + if os.path.isdir(bottlePath): + if f"{i}/{k}" == sys.argv[1]: + continue + if os.path.ismount(f"{bottlePath}/dev"): + os.system(f"pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash '{programPath}/UnMount.sh' '{bottlePath}' ") + # 判断是否挂载 - if not os.path.ismount(f"{homePath}/.deepin-wine-runner-ubuntu-images/{sys.argv[1]}/proc"): + if not os.path.ismount(f"{homePath}/.deepin-wine-runner-ubuntu-images/{sys.argv[1]}/dev"): print("文件暂未挂载,开始挂载") sys.exit(os.system(f"pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash '{programPath}/Mount.sh' '{homePath}/.deepin-wine-runner-ubuntu-images/{sys.argv[1]}' '{userName}' {commandList}")) sys.exit(os.system(f"pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY chroot '--userspec={userName}:{userName}' '{homePath}/.deepin-wine-runner-ubuntu-images/{sys.argv[1]}/' env 'HOME=/home/{userName}' {commandList}")) diff --git a/UnMount.sh b/UnMount.sh index ac9b385..a8b0316 100755 --- a/UnMount.sh +++ b/UnMount.sh @@ -24,4 +24,13 @@ umount ./opt/apps/deepin-wine-runner/ # 挂载字体 umount ./usr/share/fonts # 挂载用户目录到 /root(默认 $HOME 路径) -umount ./root \ No newline at end of file +umount ./root +for username in $(ls ./home) + do + echo ./home/$username + umount ./home/$username +# if [ -d ./home/$username/.deepinwine/$CONTAINER_NAME ] +# then +# rm -rf ./home/$username/.deepinwine/$CONTAINER_NAME +# fi + done diff --git a/mainwindow.py b/mainwindow.py index c1c58ab..6f2f046 100755 --- a/mainwindow.py +++ b/mainwindow.py @@ -455,6 +455,16 @@ StartupNotify=true''') # 写入文本文档 traceback.print_exc() QtWidgets.QMessageBox.critical(widget, "错误", f"快捷方式创建失败,错误如下:\n{traceback.format_exc()}") +def ConfigQemu(): + lists = [] + for i in qemuBottleList: + lists.append(f"{i[0]}/{i[1]}") + choose = QtWidgets.QInputDialog.getItem(window, "提示", "选择需要 Chroot 到里面的容器", lists, 0, False) + if not choose[1]: + return + threading.Thread(target=OpenTerminal, args=[f"python3 '{programPath}/QemuRun.py' '{choose[0]}' "]).start() + print(choose) + # 生成 desktop 文件在桌面 # (第四个按钮的事件) def make_desktop_on_desktop(): @@ -2196,7 +2206,7 @@ updateThingsString = '''※1、容器自动配置脚本 GUI 查看介绍使用 Q ''' for i in information["Thank"]: thankText += f"{i}\n" -updateTime = "2022年12月02日" +updateTime = "2022年12月03日" about = f'''