Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T6207: restore ability to copy config.boot.default on image install (backport #3278) #3279

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions python/vyos/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.

from typing import Callable
from typing import Callable, Optional

def print_error(str='', end='\n'):
"""
Expand Down Expand Up @@ -81,7 +81,8 @@ def is_dumb_terminal():
return os.getenv('TERM') in ['vt100', 'dumb']

def select_entry(l: list, list_msg: str = '', prompt_msg: str = '',
list_format: Callable = None,) -> str:
list_format: Optional[Callable] = None,
default_entry: Optional[int] = None) -> str:
"""Select an entry from a list

Args:
Expand All @@ -99,6 +100,9 @@ def select_entry(l: list, list_msg: str = '', prompt_msg: str = '',
print(f'\t{i}: {list_format(e)}')
else:
print(f'\t{i}: {e}')
select = ask_input(prompt_msg, numeric_only=True,
valid_responses=range(1, len(l)+1))
valid_entry = range(1, len(l)+1)
if default_entry and default_entry not in valid_entry:
default_entry = None
select = ask_input(prompt_msg, default=default_entry, numeric_only=True,
valid_responses=valid_entry)
return next(filter(lambda x: x[0] == select, en))[1]
16 changes: 15 additions & 1 deletion src/op_mode/image_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
MSG_INFO_INSTALL_RAID_CONFIRM: str = 'Installation will delete all data on both drives. Continue?'
MSG_INFO_INSTALL_PARTITONING: str = 'Creating partition table...'
MSG_INPUT_CONFIG_FOUND: str = 'An active configuration was found. Would you like to copy it to the new image?'
MSG_INPUT_CONFIG_CHOICE: str = 'The following config files are available for boot:'
MSG_INPUT_CONFIG_CHOOSE: str = 'Which file would you like as boot config?'
MSG_INPUT_IMAGE_NAME: str = 'What would you like to name this image?'
MSG_INPUT_IMAGE_DEFAULT: str = 'Would you like to set the new image as the default one for boot?'
MSG_INPUT_PASSWORD: str = 'Please enter a password for the "vyos" user'
Expand Down Expand Up @@ -652,6 +654,10 @@ def install_image() -> None:
valid_responses=['K', 'S', 'U'])
console_dict: dict[str, str] = {'K': 'tty', 'S': 'ttyS', 'U': 'ttyUSB'}

config_boot_list = ['/opt/vyatta/etc/config/config.boot',
'/opt/vyatta/etc/config.boot.default']
default_config = config_boot_list[0]

disks: dict[str, int] = find_disks()

install_target: Union[disk.DiskDetails, raid.RaidDetails, None] = None
Expand All @@ -660,6 +666,14 @@ def install_image() -> None:
if install_target is None:
install_target = ask_single_disk(disks)

# if previous install was selected in search_previous_installation,
# directory /mnt/config was prepared for copy below; if not, prompt:
if not Path('/mnt/config').exists():
default_config: str = select_entry(config_boot_list,
MSG_INPUT_CONFIG_CHOICE,
MSG_INPUT_CONFIG_CHOOSE,
default_entry=1) # select_entry indexes from 1

# create directories for installation media
prepare_tmp_disr()

Expand All @@ -681,7 +695,7 @@ def install_image() -> None:
chown(target_config_dir, group='vyattacfg')
chmod_2775(target_config_dir)
# copy config
copy('/opt/vyatta/etc/config/config.boot', target_config_dir)
copy(default_config, f'{target_config_dir}/config.boot')
configure_authentication(f'{target_config_dir}/config.boot',
user_password)
Path(f'{target_config_dir}/.vyatta_config').touch()
Expand Down
Loading