Spotter-VM/zz-build/usr/bin/fix-apk

44 lines
1.4 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:
2018-10-02 22:09:34 +02:00
with open(os.path.join(layer, 'lib/apk/db/installed'), 'r') as f:
2018-09-12 19:04:55 +02:00
buffer = []
2018-10-02 22:09:34 +02:00
for line in f:
2018-09-12 19:04:55 +02:00
if line.startswith('C:'):
buffer = ''.join(buffer)
if buffer not in installed:
installed.append(buffer)
buffer = []
buffer.append(line)
2018-09-13 13:59:56 +02:00
buffer = ''.join(buffer)
if buffer not in installed:
installed.append(buffer)
2018-09-12 19:04:55 +02:00
except:
continue
os.makedirs(os.path.join(layers[-1], 'lib/apk/db'), 0o755, True)
2018-10-02 22:09:34 +02:00
with open(os.path.join(layers[-1], 'lib/apk/db/installed'), 'w') as f:
f.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:
2018-10-02 22:09:34 +02:00
with open(os.path.join(layer, 'etc/apk/world'), 'r') as f:
for line in f:
2018-09-12 19:04:55 +02:00
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)
2018-10-02 22:09:34 +02:00
with open(os.path.join(layers[-1], 'etc/apk/world'), 'w') as f:
f.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:])