|
26 | 26 | from os import readlink
|
27 | 27 | from os import getpid
|
28 | 28 | from os import getppid
|
| 29 | +from os import sync |
29 | 30 | from json import loads
|
30 | 31 | from json import dumps
|
31 | 32 | from typing import Union
|
@@ -1086,30 +1087,60 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
|
1086 | 1087 | # find target directory
|
1087 | 1088 | root_dir: str = disk.find_persistence()
|
1088 | 1089 |
|
| 1090 | + cmdline_options = [] |
| 1091 | + |
1089 | 1092 | # a config dir. It is the deepest one, so the comand will
|
1090 | 1093 | # create all the rest in a single step
|
1091 | 1094 | target_config_dir: str = f'{root_dir}/boot/{image_name}/rw{DIR_CONFIG}/'
|
1092 | 1095 | # copy config
|
1093 | 1096 | if no_prompt or migrate_config():
|
1094 |
| - print('Copying configuration directory') |
1095 |
| - # copytree preserves perms but not ownership: |
1096 |
| - Path(target_config_dir).mkdir(parents=True) |
1097 |
| - chown(target_config_dir, group='vyattacfg') |
1098 |
| - chmod_2775(target_config_dir) |
1099 |
| - copytree(f'{DIR_CONFIG}/', target_config_dir, symlinks=True, |
1100 |
| - copy_function=copy_preserve_owner, dirs_exist_ok=True) |
1101 |
| - |
1102 |
| - # Record information from which image we upgraded to the new one. |
1103 |
| - # This can be used for a future automatic rollback into the old image. |
1104 |
| - tmp = {'previous_image' : image.get_running_image()} |
1105 |
| - write_file(f'{target_config_dir}/first_boot', dumps(tmp)) |
1106 |
| - |
| 1097 | + if Path('/dev/mapper/vyos_config').exists(): |
| 1098 | + print('Copying encrypted configuration volume') |
| 1099 | + |
| 1100 | + # Record information from which image we upgraded to the new one. |
| 1101 | + # This can be used for a future automatic rollback into the old image. |
| 1102 | + # |
| 1103 | + # For encrypted config, we need to copy, sync filesystems and remove from current image |
| 1104 | + tmp = {'previous_image' : image.get_running_image()} |
| 1105 | + write_file('/opt/vyatta/etc/config/first_boot', dumps(tmp)) |
| 1106 | + sync() |
| 1107 | + |
| 1108 | + # Copy encrypteed volumes |
| 1109 | + current_name = image.get_running_image() |
| 1110 | + current_config_path = f'{root_dir}/luks/{current_name}' |
| 1111 | + target_config_path = f'{root_dir}/luks/{image_name}' |
| 1112 | + copy(current_config_path, target_config_path) |
| 1113 | + |
| 1114 | + # Now remove from current image |
| 1115 | + Path('/opt/vyatta/etc/config/first_boot').unlink() |
| 1116 | + |
| 1117 | + cmdline_options = get_cli_kernel_options( |
| 1118 | + f'/opt/vyatta/etc/config/config.boot') |
| 1119 | + else: |
| 1120 | + print('Copying configuration directory') |
| 1121 | + # copytree preserves perms but not ownership: |
| 1122 | + Path(target_config_dir).mkdir(parents=True) |
| 1123 | + chown(target_config_dir, group='vyattacfg') |
| 1124 | + chmod_2775(target_config_dir) |
| 1125 | + copytree(f'{DIR_CONFIG}/', target_config_dir, symlinks=True, |
| 1126 | + copy_function=copy_preserve_owner, dirs_exist_ok=True) |
| 1127 | + |
| 1128 | + # Record information from which image we upgraded to the new one. |
| 1129 | + # This can be used for a future automatic rollback into the old image. |
| 1130 | + tmp = {'previous_image' : image.get_running_image()} |
| 1131 | + write_file(f'{target_config_dir}/first_boot', dumps(tmp)) |
| 1132 | + |
| 1133 | + cmdline_options = get_cli_kernel_options( |
| 1134 | + f'{target_config_dir}/config.boot') |
1107 | 1135 | else:
|
1108 | 1136 | Path(target_config_dir).mkdir(parents=True)
|
1109 | 1137 | chown(target_config_dir, group='vyattacfg')
|
1110 | 1138 | chmod_2775(target_config_dir)
|
1111 | 1139 | Path(f'{target_config_dir}/.vyatta_config').touch()
|
1112 | 1140 |
|
| 1141 | + cmdline_options = get_cli_kernel_options( |
| 1142 | + f'{target_config_dir}/config.boot') |
| 1143 | + |
1113 | 1144 | target_ssh_dir: str = f'{root_dir}/boot/{image_name}/rw/etc/ssh/'
|
1114 | 1145 | if no_prompt or copy_ssh_host_keys():
|
1115 | 1146 | print('Copying SSH host keys')
|
|
0 commit comments