|
46 | 46 | import iocage_lib.ioc_create |
47 | 47 | import iocage_lib.ioc_destroy |
48 | 48 | import iocage_lib.ioc_exec |
| 49 | +import iocage_lib.ioc_fstab |
49 | 50 | import iocage_lib.ioc_list |
50 | 51 | import iocage_lib.ioc_json |
51 | 52 | import iocage_lib.ioc_start |
@@ -94,6 +95,7 @@ def __init__( |
94 | 95 | self.plugin_json_path = None |
95 | 96 | self.plugin = plugin |
96 | 97 | self.jail = jail |
| 98 | + self.mountpoints = kwargs.pop("mountpoints", []) |
97 | 99 | self.http = kwargs.pop("http", True) |
98 | 100 | self.hardened = kwargs.pop("hardened", False) |
99 | 101 | self.date = datetime.datetime.utcnow().strftime("%F") |
@@ -321,6 +323,7 @@ def fetch_plugin(self, props, num, accept_license): |
321 | 323 |
|
322 | 324 | try: |
323 | 325 | jaildir, _conf, repo_dir = self.__fetch_plugin_create__(props) |
| 326 | + self.__fetch_plugin_add_mountpoints__(jaildir) |
324 | 327 | # As soon as we create the jail, we should write the plugin manifest to jail directory |
325 | 328 | # This is done to ensure that subsequent starts of the jail make use of the plugin |
326 | 329 | # manifest as required |
@@ -607,6 +610,52 @@ def __fetch_plugin_create__(self, create_props): |
607 | 610 |
|
608 | 611 | return jaildir, _conf, repo_dir |
609 | 612 |
|
| 613 | + def __fetch_plugin_add_mountpoints__(self, jaildir): |
| 614 | + for mountpoint in self.mountpoints: |
| 615 | + fstype = "nullfs" |
| 616 | + options = "rw" |
| 617 | + dump = "0" |
| 618 | + _pass = "0" |
| 619 | + |
| 620 | + parts = mountpoint.split(":") |
| 621 | + if len(parts) < 2 or len(parts) > 3: |
| 622 | + raise RuntimeError( |
| 623 | + f"Ignoring invalid mountpoint `{mountpoint}`, expecting " |
| 624 | + "`source:destination[:options]`." |
| 625 | + ) |
| 626 | + else: |
| 627 | + source = parts[0].strip() |
| 628 | + destination = parts[1].strip() |
| 629 | + if len(parts) == 3: |
| 630 | + options = parts[2] |
| 631 | + |
| 632 | + if (not source or source[0] != "/" |
| 633 | + or not destination or destination[0] != "/" |
| 634 | + or not options): |
| 635 | + raise RuntimeError( |
| 636 | + f"Ignoring invalid mountpoint `{mountpoint}`, source and " |
| 637 | + "destination must be absolute path, options cannot be " |
| 638 | + "empty." |
| 639 | + ) |
| 640 | + |
| 641 | + destination = f"{jaildir}/root{destination}" |
| 642 | + if destination and len(destination) > 88: |
| 643 | + iocage_lib.ioc_common.logit( |
| 644 | + { |
| 645 | + "level": |
| 646 | + "WARNING", |
| 647 | + "message": |
| 648 | + "The destination's mountpoint exceeds 88 " |
| 649 | + "characters, this may cause failure!" |
| 650 | + }, |
| 651 | + silent=self.silent) |
| 652 | + |
| 653 | + os.makedirs(destination, exist_ok=True) |
| 654 | + iocage_lib.ioc_fstab.IOCFstab( |
| 655 | + self.jail, "add", source, destination, |
| 656 | + fstype, options, dump, _pass |
| 657 | + ) |
| 658 | + |
610 | 659 | def __fetch_plugin_install_packages__(self, jaildir, conf, pkg_repos, |
611 | 660 | create_props, repo_dir): |
612 | 661 | """Attempts to start the jail and install the packages""" |
|
0 commit comments