Spotter-VM/zz-extra/fix-apk

41 lines
1.3 KiB
Plaintext
Raw Normal View History

2018-09-12 16:12:23 +02:00
#!/usr/bin/python3
import os
import sys
def fix_installed(layers):
installed = []
for layer in layers[:-1]:
2018-09-12 19:04:55 +02:00
try:
with open(os.path.join(layer, 'lib/apk/db/installed'), 'r') as fd:
buffer = []
for line in fd:
if line.startswith('C:'):
buffer = ''.join(buffer)
if buffer not in installed:
installed.append(buffer)
buffer = []
buffer.append(line)
except:
continue
os.makedirs(os.path.join(layers[-1], 'lib/apk/db'), 0o755, True)
with open(os.path.join(layers[-1], 'lib/apk/db/installed'), 'w') as fd:
fd.writelines(installed)
2018-09-12 16:12:23 +02:00
def fix_world(layers):
world = []
for layer in layers[:-1]:
2018-09-12 19:04:55 +02:00
try:
with open(os.path.join(layer, 'etc/apk/world'), 'r') as fd:
for line in fd:
if line not in world:
2018-09-12 19:42:12 +02:00
world.append(line)
2018-09-12 19:04:55 +02:00
except:
continue
os.makedirs(os.path.join(layers[-1], 'etc/apk'), 0o755, True)
with open(os.path.join(layers[-1], 'etc/apk/world'), 'w') as fd:
fd.writelines(world)
2018-09-12 16:12:23 +02:00
2018-09-12 19:04:55 +02:00
fix_installed(sys.argv[1:])
fix_world(sys.argv[1:])