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
@@ -1083,30 +1084,60 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
1083
1084
# find target directory
1084
1085
root_dir : str = disk .find_persistence ()
1085
1086
1087
+ cmdline_options = []
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
1091
target_config_dir : str = f'{ root_dir } /boot/{ image_name } /rw/opt/vyatta/etc/config/'
1089
1092
# copy config
1090
1093
if no_prompt or migrate_config ():
1091
- print ('Copying configuration directory' )
1092
- # copytree preserves perms but not ownership:
1093
- Path (target_config_dir ).mkdir (parents = True )
1094
- chown (target_config_dir , group = 'vyattacfg' )
1095
- chmod_2775 (target_config_dir )
1096
- copytree ('/opt/vyatta/etc/config/' , target_config_dir , symlinks = True ,
1097
- copy_function = copy_preserve_owner , dirs_exist_ok = True )
1098
-
1099
- # Record information from which image we upgraded to the new one.
1100
- # This can be used for a future automatic rollback into the old image.
1101
- tmp = {'previous_image' : image .get_running_image ()}
1102
- write_file (f'{ target_config_dir } /first_boot' , dumps (tmp ))
1103
-
1094
+ if Path ('/dev/mapper/vyos_config' ).exists ():
1095
+ print ('Copying encrypted configuration volume' )
1096
+
1097
+ # Record information from which image we upgraded to the new one.
1098
+ # This can be used for a future automatic rollback into the old image.
1099
+ #
1100
+ # For encrypted config, we need to copy, sync filesystems and remove from current image
1101
+ tmp = {'previous_image' : image .get_running_image ()}
1102
+ write_file ('/opt/vyatta/etc/config/first_boot' , dumps (tmp ))
1103
+ sync ()
1104
+
1105
+ # Copy encrypteed volumes
1106
+ current_name = image .get_running_image ()
1107
+ current_config_path = f'{ root_dir } /luks/{ current_name } '
1108
+ target_config_path = f'{ root_dir } /luks/{ image_name } '
1109
+ copy (current_config_path , target_config_path )
1110
+
1111
+ # Now remove from current image
1112
+ Path ('/opt/vyatta/etc/config/first_boot' ).unlink ()
1113
+
1114
+ cmdline_options = get_cli_kernel_options (
1115
+ f'/opt/vyatta/etc/config/config.boot' )
1116
+ else :
1117
+ print ('Copying configuration directory' )
1118
+ # copytree preserves perms but not ownership:
1119
+ Path (target_config_dir ).mkdir (parents = True )
1120
+ chown (target_config_dir , group = 'vyattacfg' )
1121
+ chmod_2775 (target_config_dir )
1122
+ copytree ('/opt/vyatta/etc/config/' , target_config_dir , symlinks = True ,
1123
+ copy_function = copy_preserve_owner , dirs_exist_ok = True )
1124
+
1125
+ # Record information from which image we upgraded to the new one.
1126
+ # This can be used for a future automatic rollback into the old image.
1127
+ tmp = {'previous_image' : image .get_running_image ()}
1128
+ write_file (f'{ target_config_dir } /first_boot' , dumps (tmp ))
1129
+
1130
+ cmdline_options = get_cli_kernel_options (
1131
+ f'{ target_config_dir } /config.boot' )
1104
1132
else :
1105
1133
Path (target_config_dir ).mkdir (parents = True )
1106
1134
chown (target_config_dir , group = 'vyattacfg' )
1107
1135
chmod_2775 (target_config_dir )
1108
1136
Path (f'{ target_config_dir } /.vyatta_config' ).touch ()
1109
1137
1138
+ cmdline_options = get_cli_kernel_options (
1139
+ f'{ target_config_dir } /config.boot' )
1140
+
1110
1141
target_ssh_dir : str = f'{ root_dir } /boot/{ image_name } /rw/etc/ssh/'
1111
1142
if no_prompt or copy_ssh_host_keys ():
1112
1143
print ('Copying SSH host keys' )
@@ -1132,8 +1163,6 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
1132
1163
if set_as_default :
1133
1164
grub .set_default (image_name , root_dir )
1134
1165
1135
- cmdline_options = get_cli_kernel_options (
1136
- f'{ target_config_dir } /config.boot' )
1137
1166
grub_util .update_kernel_cmdline_options (' ' .join (cmdline_options ),
1138
1167
root_dir = root_dir ,
1139
1168
version = image_name )
0 commit comments