-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-plugin-package.py
More file actions
48 lines (40 loc) · 1.53 KB
/
Copy pathcreate-plugin-package.py
File metadata and controls
48 lines (40 loc) · 1.53 KB
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
from __future__ import annotations
import os
from pathlib import Path
import sys
import tarfile
def mode_for(relative: Path, is_directory: bool) -> int:
if is_directory:
return 0o755
value = relative.as_posix()
if value.startswith("etc/rc.d/"):
return 0o755
if value.startswith("usr/local/emhttp/plugins/unraid.vmbackup/event/"):
return 0o755
return 0o644
def main() -> None:
if len(sys.argv) != 3:
raise SystemExit("usage: create-plugin-package.py STAGE OUTPUT")
stage = Path(sys.argv[1]).resolve()
output = Path(sys.argv[2]).resolve()
if not stage.is_dir():
raise SystemExit(f"stage directory not found: {stage}")
output.parent.mkdir(parents=True, exist_ok=True)
timestamp = int(os.environ.get("SOURCE_DATE_EPOCH", "0"))
with tarfile.open(output, "w:xz", format=tarfile.GNU_FORMAT) as archive:
for source in sorted(stage.rglob("*"), key=lambda item: item.relative_to(stage).as_posix()):
relative = source.relative_to(stage)
info = archive.gettarinfo(str(source), arcname=f"./{relative.as_posix()}")
info.uid = 0
info.gid = 0
info.uname = "root"
info.gname = "root"
info.mtime = timestamp
info.mode = mode_for(relative, source.is_dir())
if source.is_file():
with source.open("rb") as stream:
archive.addfile(info, stream)
else:
archive.addfile(info)
if __name__ == "__main__":
main()