|
37 | 37 |
|
38 | 38 | from vyos.base import Warning |
39 | 39 | from vyos.configtree import ConfigTree |
| 40 | +from vyos.defaults import base_dir |
| 41 | +from vyos.defaults import directories |
40 | 42 | from vyos.remote import download |
41 | 43 | from vyos.system import disk |
42 | 44 | from vyos.system import grub |
|
116 | 118 | CONST_RESERVED_SPACE: int = (2 + 1 + 256) * 1024**2 |
117 | 119 |
|
118 | 120 | # define directories and paths |
| 121 | +DIR_CONFIG: str = directories['config'] |
119 | 122 | DIR_INSTALLATION: str = '/mnt/installation' |
120 | 123 | DIR_ROOTFS_SRC: str = f'{DIR_INSTALLATION}/root_src' |
121 | 124 | DIR_ROOTFS_DST: str = f'{DIR_INSTALLATION}/root_dst' |
|
125 | 128 | FILE_ROOTFS_SRC: str = '/usr/lib/live/mount/medium/live/filesystem.squashfs' |
126 | 129 | ISO_DOWNLOAD_PATH: str = '' |
127 | 130 |
|
128 | | -external_download_script = '/usr/libexec/vyos/simple-download.py' |
129 | | -external_latest_image_url_script = '/usr/libexec/vyos/latest-image-url.py' |
| 131 | +external_download_script: str = f'{base_dir}/simple-download.py' |
| 132 | +external_latest_image_url_script: str = f'{base_dir}/latest-image-url.py' |
130 | 133 |
|
131 | 134 | # default boot variables |
132 | 135 | DEFAULT_BOOT_VARS: dict[str, str] = { |
@@ -344,7 +347,7 @@ def copy_preserve_owner(src: str, dst: str, *, follow_symlinks=True): |
344 | 347 |
|
345 | 348 | def copy_previous_installation_data(target_dir: str) -> None: |
346 | 349 | if Path('/mnt/config').exists(): |
347 | | - copytree('/mnt/config', f'{target_dir}/opt/vyatta/etc/config', |
| 350 | + copytree('/mnt/config', f'{target_dir}{DIR_CONFIG}', |
348 | 351 | dirs_exist_ok=True) |
349 | 352 | if Path('/mnt/ssh').exists(): |
350 | 353 | copytree('/mnt/ssh', f'{target_dir}/etc/ssh', |
@@ -697,7 +700,7 @@ def migrate_config() -> bool: |
697 | 700 | Returns: |
698 | 701 | bool: user's decision |
699 | 702 | """ |
700 | | - active_config_path: Path = Path('/opt/vyatta/etc/config/config.boot') |
| 703 | + active_config_path: Path = Path(f'{DIR_CONFIG}/config.boot') |
701 | 704 | if active_config_path.exists(): |
702 | 705 | if ask_yes_no(MSG_INPUT_CONFIG_FOUND, default=True): |
703 | 706 | return True |
@@ -882,7 +885,7 @@ def install_image() -> None: |
882 | 885 | valid_responses=['K', 'S']) |
883 | 886 | console_dict: dict[str, str] = {'K': 'tty', 'S': 'ttyS'} |
884 | 887 |
|
885 | | - config_boot_list = ['/opt/vyatta/etc/config/config.boot', |
| 888 | + config_boot_list = [f'{DIR_CONFIG}/config.boot', |
886 | 889 | '/opt/vyatta/etc/config.boot.default'] |
887 | 890 | default_config = config_boot_list[0] |
888 | 891 |
|
@@ -918,7 +921,7 @@ def install_image() -> None: |
918 | 921 | # a config dir. It is the deepest one, so the comand will |
919 | 922 | # create all the rest in a single step |
920 | 923 | print('Creating a configuration file') |
921 | | - target_config_dir: str = f'{DIR_DST_ROOT}/boot/{image_name}/rw/opt/vyatta/etc/config/' |
| 924 | + target_config_dir: str = f'{DIR_DST_ROOT}/boot/{image_name}/rw{DIR_CONFIG}/' |
922 | 925 | Path(target_config_dir).mkdir(parents=True) |
923 | 926 | chown(target_config_dir, group='vyattacfg') |
924 | 927 | chmod_2775(target_config_dir) |
@@ -1085,15 +1088,15 @@ def add_image(image_path: str, vrf: str = None, username: str = '', |
1085 | 1088 |
|
1086 | 1089 | # a config dir. It is the deepest one, so the comand will |
1087 | 1090 | # create all the rest in a single step |
1088 | | - target_config_dir: str = f'{root_dir}/boot/{image_name}/rw/opt/vyatta/etc/config/' |
| 1091 | + target_config_dir: str = f'{root_dir}/boot/{image_name}/rw{DIR_CONFIG}/' |
1089 | 1092 | # copy config |
1090 | 1093 | if no_prompt or migrate_config(): |
1091 | 1094 | print('Copying configuration directory') |
1092 | 1095 | # copytree preserves perms but not ownership: |
1093 | 1096 | Path(target_config_dir).mkdir(parents=True) |
1094 | 1097 | chown(target_config_dir, group='vyattacfg') |
1095 | 1098 | chmod_2775(target_config_dir) |
1096 | | - copytree('/opt/vyatta/etc/config/', target_config_dir, symlinks=True, |
| 1099 | + copytree(f'{DIR_CONFIG}/', target_config_dir, symlinks=True, |
1097 | 1100 | copy_function=copy_preserve_owner, dirs_exist_ok=True) |
1098 | 1101 |
|
1099 | 1102 | # Record information from which image we upgraded to the new one. |
@@ -1132,11 +1135,12 @@ def add_image(image_path: str, vrf: str = None, username: str = '', |
1132 | 1135 | if set_as_default: |
1133 | 1136 | grub.set_default(image_name, root_dir) |
1134 | 1137 |
|
1135 | | - cmdline_options = get_cli_kernel_options( |
1136 | | - f'{target_config_dir}/config.boot') |
1137 | | - grub_util.update_kernel_cmdline_options(' '.join(cmdline_options), |
1138 | | - root_dir=root_dir, |
1139 | | - version=image_name) |
| 1138 | + if Path(f'{target_config_dir}/config.boot').exists(): |
| 1139 | + cmdline_options = get_cli_kernel_options( |
| 1140 | + f'{target_config_dir}/config.boot') |
| 1141 | + grub_util.update_kernel_cmdline_options(' '.join(cmdline_options), |
| 1142 | + root_dir=root_dir, |
| 1143 | + version=image_name) |
1140 | 1144 |
|
1141 | 1145 | except OSError as e: |
1142 | 1146 | # if no space error, remove image dir and cleanup |
|
0 commit comments