Qemu优化

This commit is contained in:
gfdgd xi 2022-12-03 21:47:05 +08:00
parent 9c0e2d11b3
commit f6698e2f39
5 changed files with 48 additions and 5 deletions

2
ChangePassword.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
echo -e "123456\n123456\n\n\n\n\n\n\n\n\n" | adduser "$1"

View File

@ -28,7 +28,7 @@ mount -o bind /usr/share/fonts ./usr/share/fonts
# 配置用户 # 配置用户
if [ ! -d "home/$2" ]; then if [ ! -d "home/$2" ]; then
# 新建用户,且密码为 123456以便读写 # 新建用户,且密码为 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 fi
# 挂载用户目录到 /root默认 $HOME 路径) # 挂载用户目录到 /root默认 $HOME 路径)
if [[ $2 == "root" ]]; then if [[ $2 == "root" ]]; then

View File

@ -7,7 +7,7 @@ import PyQt5.QtWidgets as QtWidgets
if __name__ == "__main__": if __name__ == "__main__":
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
homePath = os.getenv("HOME") homePath = os.getenv("HOME")
if len(sys.argv) <= 2: if len(sys.argv) <= 1:
print("参数不足") print("参数不足")
sys.exit(1) sys.exit(1)
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
@ -19,8 +19,23 @@ if __name__ == "__main__":
userName = getpass.getuser() userName = getpass.getuser()
for i in sys.argv[2:]: for i in sys.argv[2:]:
commandList += f"'{i}' " 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("文件暂未挂载,开始挂载") 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 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}")) 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}"))

View File

@ -25,3 +25,12 @@ umount ./opt/apps/deepin-wine-runner/
umount ./usr/share/fonts umount ./usr/share/fonts
# 挂载用户目录到 /root默认 $HOME 路径) # 挂载用户目录到 /root默认 $HOME 路径)
umount ./root 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

View File

@ -455,6 +455,16 @@ StartupNotify=true''') # 写入文本文档
traceback.print_exc() traceback.print_exc()
QtWidgets.QMessageBox.critical(widget, "错误", f"快捷方式创建失败,错误如下:\n{traceback.format_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 文件在桌面 # 生成 desktop 文件在桌面
# (第四个按钮的事件) # (第四个按钮的事件)
def make_desktop_on_desktop(): def make_desktop_on_desktop():
@ -2196,7 +2206,7 @@ updateThingsString = '''※1、容器自动配置脚本 GUI 查看介绍使用 Q
''' '''
for i in information["Thank"]: for i in information["Thank"]:
thankText += f"{i}\n" thankText += f"{i}\n"
updateTime = "2022年12月02" updateTime = "2022年12月03"
about = f'''<style> about = f'''<style>
a:link, a:active {{ a:link, a:active {{
text-decoration: none; text-decoration: none;
@ -2670,6 +2680,13 @@ log.addAction(checkLogText)
log.addAction(saveLogText) log.addAction(saveLogText)
log.addAction(uploadLogText) log.addAction(uploadLogText)
if len(qemuBottleList) >= 1:
qemuMenu = menu.addMenu(QtCore.QCoreApplication.translate("U", "配置Chroot容器(&C)"))
configMenu = QtWidgets.QAction(QtCore.QCoreApplication.translate("U", "配置指定容器"))
qemuMenu.addAction(configMenu)
configMenu.triggered.connect(ConfigQemu)
print(qemuBottleList)
help = menu.addMenu(QtCore.QCoreApplication.translate("U", "帮助(&H)")) help = menu.addMenu(QtCore.QCoreApplication.translate("U", "帮助(&H)"))
runStatusWebSize = QtWidgets.QAction(QtCore.QCoreApplication.translate("U", "查询程序在 Wine 的运行情况")) runStatusWebSize = QtWidgets.QAction(QtCore.QCoreApplication.translate("U", "查询程序在 Wine 的运行情况"))
h1 = help.addMenu(QtCore.QCoreApplication.translate("U", "程序官网")) h1 = help.addMenu(QtCore.QCoreApplication.translate("U", "程序官网"))