- 资源类型
- 原创
- 版权链接
- #
- 语言
- English
注意:
1. 您必须以root权限启动本脚本
2. 仅兼容python3
命令:
参数解释:
操作类型: 搜索相关类型的日志进行操作,合法的值有 Install Reinstall Remove Purge 等等
命令前缀: 由于本脚本通过日志文件获取软件包列表,所以需要通过命令前缀,如"apt remove"
软件包架构: 欲操作的软件包的架构,如amd64,i386,i686,arm64,armhf等等
示例:
源码:
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}")