This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusrlocal.py
76 lines (67 loc) · 2.04 KB
/
usrlocal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /usr/bin/env python
import os
import sys
import subprocess
last = ""
files = {""}
sym = {""}
pkgs = {""}
hashe = {""}
sizee = {""}
opene = {""}
for root, dirs, filesw in os.walk("/usr/local"):
for f in filesw:
if(os.path.islink(root + "/" + f)):
sym.add(root + "/" + f)
else:
files.add(root + "/" + f)
for root, dirs, filesw in os.walk("/var/db/pkg"):
for f in filesw:
if(f == "+CONTENTS"):
for line in open(root + "/" + f, "r").readlines():
if(len(line) <= 1): continue
if(line[0] == "@"):
arr = line[1:- 1].split(" ")
if(arr[0] == "bin" or arr[0] == "lib" or arr[0] == "man" or arr[0] == "shell" or arr[0] == "so" or arr[0] == "static-lib" or arr[0] == "info" or arr[0] == "unexec-delete"):
last = "/usr/local/" + arr[1]
pkgs.add("/usr/local/" + arr[1])
if(last == ""): continue
try:
if(arr[0] == "sha"):
if(0 < len(last) and \
arr[1] != subprocess.check_output(["/bin/sha256", "-b", last]).decode("utf-8")[:- 1].split(" ")[- 1]):
print(arr[1])
print(subprocess.check_output(["/bin/sha256", "-b", last]).decode("utf-8")[:- 1].split(" ")[- 1])
hashe.add(last)
if(arr[0] == "size"):
if(0 < len(last) and int(arr[1]) != os.stat(last).st_size):
sizee.add(last)
except:
opene.add(last)
else:
last = "/usr/local/" + line[:- 1]
pkgs.add("/usr/local/" + line[:- 1])
print("/usr/local - /var/db/pkg")
for line in sorted(list(files - pkgs)):
print(line)
print("")
print("/var/db/pkg - /usr/local")
for line in sorted(list(pkgs - files)):
if(line[- 1] != "/"):
print(line)
print("")
print("hash error")
for line in sorted(list(hashe)):
print(line)
print("")
print("size error")
for line in sorted(list(sizee)):
print(line)
print("")
print("open error")
for line in sorted(list(opene)):
print(line)
print("")
print("symbolic links")
for line in sorted(list(sym)):
print(line)