From 0bd3acd361695a586fc4e02214858648a3e7e7a3 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Tue, 21 Feb 2023 20:14:39 +0100 Subject: [PATCH] setup: add support for easily switching system boot mode Signed-off-by: Joachim Wiberg --- board/common/rootfs/bin/chom | 99 +++++++++++++++++++++ board/common/rootfs/bin/setup | 2 + board/common/rootfs/etc/dialogrc | 144 +++++++++++++++++++++++++++++++ configs/amd64_defconfig | 1 + 4 files changed, 246 insertions(+) create mode 100755 board/common/rootfs/bin/chom create mode 100644 board/common/rootfs/etc/dialogrc diff --git a/board/common/rootfs/bin/chom b/board/common/rootfs/bin/chom new file mode 100755 index 00000000..29d44033 --- /dev/null +++ b/board/common/rootfs/bin/chom @@ -0,0 +1,99 @@ +#!/bin/sh +#set -x + +mode=/mnt/cfg/infix/.use_etc +boot=/tmp/.boot_mode +if [ -f $boot ]; then + current=$(cat $boot) +else + current="unknown" +fi +m=on +n=off + +select_mode() +{ + if [ -f $mode ]; then + m=off + n=on + fi + + exec 3>&1 + selection=$(dialog --erase-on-exit --no-tags \ + --hline "Arrow keys + space to select, enter to confirm" \ + --backtitle "Select Operating Mode" \ + --title "Select Operating Mode" \ + --radiolist "System currently runs in: $current mode" 10 60 1 \ + "1" "Managed NETCONF, XML datastore" "$m" \ + "2" "Native Linux, /etc datastore" "$n" \ + 2>&1 1>&3) + exit_status=$? + exec 3>&- + case $exit_status in + 1) # cancel + exit 0 + ;; + 255) # escape + exit 1 + ;; + esac +} + +usage() +{ + cat </dev/null + grep -qi netconf $boot 2>/dev/null && exit 0 + result="Manageed NETCONF" + ;; + 2) + touch $mode 2>/dev/null + grep -qi native $boot 2>/dev/null && exit 0 + result="Native Linux, /etc" + ;; +esac + +if [ -n "$use_dialog" ]; then + dialog --erase-on-exit --cr-wrap --title "Activate Mode Change?" --yesno "\n Reboot to $result mode now?" 8 50 + if [ $? -eq 0 ]; then + reboot + fi +fi + +echo "Remember to reboot later to activate the change." +exit 0 diff --git a/board/common/rootfs/bin/setup b/board/common/rootfs/bin/setup index 66519ac7..a0267c26 100755 --- a/board/common/rootfs/bin/setup +++ b/board/common/rootfs/bin/setup @@ -60,6 +60,8 @@ menu:system:System:System Settings exec:_Enable service:edit:initctl enable ~Enter name of service (filename) to enable:~ exec:_Disable service:edit:initctl disable ~Enter name of service (filename) to disable:~ nop + exec:_Change Operating Mode::chom + nop exit:_Main menu.. menu:tools:Tools:Tools diff --git a/board/common/rootfs/etc/dialogrc b/board/common/rootfs/etc/dialogrc new file mode 100644 index 00000000..830ae000 --- /dev/null +++ b/board/common/rootfs/etc/dialogrc @@ -0,0 +1,144 @@ +# +# Run-time configuration file for dialog +# +# Automatically generated by "dialog --create-rc " +# +# +# Types of values: +# +# Number - +# String - "string" +# Boolean - +# Attribute - (foreground,background,highlight?,underline?,reverse?) + +# Set aspect-ration. +aspect = 0 + +# Set separator (for multiple widgets output). +separate_widget = "" + +# Set tab-length (for textbox tab-conversion). +tab_len = 0 + +# Make tab-traversal for checklist, etc., include the list. +visit_items = OFF + +# Shadow dialog boxes? This also turns on color. +use_shadow = ON + +# Turn color support ON or OFF +use_colors = ON + +# Screen color +screen_color = (WHITE,BLUE,OFF) + +# Shadow color +shadow_color = (BLACK,BLACK,OFF) + +# Dialog box color +dialog_color = (BLACK,CYAN,OFF) + +# Dialog box title color +title_color = (BLACK,CYAN,ON) + +# Dialog box border color +border_color = dialog_color + +# Active button color +button_active_color = (CYAN,BLACK,ON) + +# Inactive button color +button_inactive_color = dialog_color + +# Active button key color +button_key_active_color = (WHITE,BLACK,ON) + +# Inactive button key color +button_key_inactive_color = (WHITE,CYAN,ON) + +# Active button label color +button_label_active_color = button_active_color + +# Inactive button label color +button_label_inactive_color = dialog_color + +# Input box color +inputbox_color = (BLACK,CYAN,OFF) + +# Input box border color +inputbox_border_color = inputbox_color + +# Search box color +searchbox_color = inputbox_color + +# Search box title color +searchbox_title_color = (BLUE,WHITE,ON) + +# Search box border color +searchbox_border_color = (WHITE,WHITE,ON) + +# File position indicator color +position_indicator_color = searchbox_title_color + +# Menu box color +menubox_color = dialog_color + +# Menu box border color +menubox_border_color = dialog_color + +# Item color +item_color = inputbox_color + +# Selected item color +item_selected_color = button_key_active_color + +# Tag color +tag_color = button_inactive_color + +# Selected tag color +tag_selected_color = (CYAN,BLACK,OFF) + +# Tag key color +tag_key_color = button_key_inactive_color + +# Selected tag key color +tag_key_selected_color = (WHITE,BLACK,ON) + +# Check box color +check_color = inputbox_color + +# Selected check box color +check_selected_color = button_key_active_color + +# Up arrow color +uarrow_color = (GREEN,WHITE,ON) + +# Down arrow color +darrow_color = uarrow_color + +# Item help-text color +itemhelp_color = (WHITE,BLACK,OFF) + +# Active form text color +form_active_text_color = button_key_active_color + +# Form text color +form_text_color = (WHITE,CYAN,ON) + +# Readonly form item color +form_item_readonly_color = (CYAN,WHITE,ON) + +# Dialog box gauge color +gauge_color = searchbox_title_color + +# Dialog box border2 color +border2_color = dialog_color + +# Input box border2 color +inputbox_border2_color = inputbox_color + +# Search box border2 color +searchbox_border2_color = inputbox_color + +# Menu box border2 color +menubox_border2_color = dialog_color diff --git a/configs/amd64_defconfig b/configs/amd64_defconfig index d5bddd53..21ffcc81 100644 --- a/configs/amd64_defconfig +++ b/configs/amd64_defconfig @@ -84,6 +84,7 @@ BR2_PACKAGE_TCPDUMP=y BR2_PACKAGE_TRACEROUTE=y BR2_PACKAGE_ULOGD=y BR2_PACKAGE_BASH_COMPLETION=y +BR2_PACKAGE_DIALOG=y BR2_PACKAGE_NEOFETCH=y BR2_PACKAGE_PDMENU=y BR2_PACKAGE_TMUX=y