• 由于站长工作忙无暇管理论坛,特此欢迎有能力的用户加入管理组,加入的管理人员拥有专属认证
  • 游客,我们的全新下载站开放了,快去看看吧!【点击前往
资源图标

源码 aptRestorer —— apt操作回滚 2022-08-23

登录后下载

欢迎来到像素工坊

您可以在此停留,喝一杯下午茶吗?

资源类型
原创
版权链接
#
开发者团队
[所有者]WillowSauceR
[维护者]WillowSauceR
运行方式/前置组件
1.apt包管理器
2.python3
语言
English
注意:
1. 您必须以root权限启动本脚本
2. 仅兼容python3
命令:
Bash:
sudo python3 aptRestorer.py <操作类型> <"命令前缀"> <可选: 软件包架构>
参数解释:
操作类型: 搜索相关类型的日志进行操作,合法的值有 Install Reinstall Remove Purge 等等
命令前缀: 由于本脚本通过日志文件获取软件包列表,所以需要通过命令前缀,如"apt remove"
软件包架构: 欲操作的软件包的架构,如amd64,i386,i686,arm64,armhf等等
示例:
Bash:
sudo python3 aptRestorer.py Install "apt remove" amd64
Bash:
sudo python3 aptRestorer.py Remove "apt install" amd64
源码:
Python:
import os
import sys
checkType = sys.argv[1]
prefixCmd = sys.argv[2]
try:
    arch = sys.argv[3]
except:
    arch = "amd64"

with open("/var/log/apt/history.log") as file:
    info = []
    index = 0
    fileLines = file.readlines()
    for line in fileLines:
        if checkType in line:
            info.append(line[len(checkType)+2:])
            print(f"{str(index)}: {line[len(checkType)+2:]}")
            index += 1

    selected = int(input("Which one do you want to process?(Type number): "))
    #print(installInfo)
    processedPackageList = info[selected].split("), ")
    packageList = ""
    for segument in processedPackageList:
        if f":{arch}" in segument:
            packageList += (segument.split(f":{arch}")[0]) + " "
    
    print(f"\nYou will execute:\n{prefixCmd} {packageList}\n")
    if input("Type y to continue or type any other key to exit: ") == "y":
        os.system(f"{prefixCmd} {packageList}")
作者
WillowSauceR
下载
0
查看
116
首次发布
最后更新
评分
0.00 星 0 星

分享资源

后退
顶部