戻りスクリプトの root_menu が応答しません。

戻りスクリプトの root_menu が応答しません。

単一ファイルbashスクリプトのメニューとサブメニュー、それぞれルートメニューに戻る機能があります。

私の問題は、呼び出しが時々show_root_menuルートの代わりに親メニューに移動することです。

Bashインストーラメニュー

Nvidiaサブメニューは、ルートメニューに戻ると最も頻繁に間違っています。

show_pckg_menu代わりに、「グラフィック専用ドライバのインストール」サブメニューから「ルートメニューを表示」を選択すると、「パッケージオプション」に移動します。

ルートメニューを表示


NVIDIAメニュー表示


showpckg_menu

これまでに解決された他の関連質問は次のとおりです。

$ shellcheck myscript No issues detected!

実際のスクリプトは次のとおりです。

#!/bin/bash
show_root_menu(){
width=72
height=50
menu_height=8
backtitle="Installer-menu"
title="Setup opions"
menu="Choose one of the following options:"

options=(1 'Add Mint PPA and update' 
         2 'Install Cinnamon '
         3 'update and upgrade '
         4 'Additional software installation '
         5 'Upgrade Kernel '
         6 'Resolve Ubuntu Cinnamon issues '
         7 'Install graphic proprietary driver'
         x reboot
         q quit )
    
result=$(dialog --clear \
                --backtitle "$backtitle" \
                --title "$title" \
                --menu "$menu" \
                $height $width $menu_height \
                "${options[@]}" \
                2>&1 >/dev/tty)
}
show_pckg_menu(){
width=72
height=22
menu_height=8
backtitle='Installer-menu'
title='Package options'
menu='Choose one of the following options:'

options=(1 'Install package list'
         2 'Export package list'
         3 'update and upgrade'
         4 'Show root menu'
         x reboot
         q quit )

result=$(dialog --clear \
                --backtitle "$backtitle" \
                --title "$title" \
                --menu "$menu" \
                $height $width $menu_height \
                "${options[@]}" \
                2>&1 >/dev/tty)
}
show_solver_menu(){
width=72
height=22
menu_height=8
backtitle='Installer-menu'
title='Resolver menu'
menu='Choose one of the following options:'

options=(1 'Network applet problem'
         2 'Sound problem'
         3 'update and upgrade'
         4 'Show root menu'
         x reboot
         q quit )


result=$(dialog --clear \
                --backtitle "$backtitle" \
                --title "$title" \
                --menu "$menu" \
                $height $width $menu_height \
                "${options[@]}" \
                2>&1 >/dev/tty)
}
show_nvidia_menu(){
width=72
height=22
menu_height=8
backtitle='Installer-menu'
title='NVidia driver selection'
menu='Choose one of the following options:'

options=(1 'Install nvidia 515'
         2 'Install nvidia 525'
         3 'Update and upgrade'
         4 'Show root menu'
         x reboot
         q quit )

result=$(dialog --clear \
                --backtitle "$backtitle" \
                --title "$title" \
                --menu "$menu" \
                $height $width $menu_height \
                "${options[@]}" \
                2>&1 >/dev/tty)
}
show_root_menu
case "$result" in
    1)  echo 'Mint backport repos installed';
        apt-key adv --recv-keys --keyserver keyserver.ubuntu.com A1715D88E1DF1F24 40976EAF437D05B5 3B4FE6ACC0B21F32 A6616109451BBBF2;
        sh -c 'echo "deb http://packages.linuxmint.com vanessa main upstream import backport romeo" >> /etc/apt/sources.list.d/mint.list';
        sh -c 'echo "deb-src http://packages.linuxmint.com vanessa main upstream import backport romeo" >> /etc/apt/sources.list.d/mint.list';
        apt-key export 451BBBF2 | gpg --dearmour -o /etc/apt/trusted.gpg.d/mint.gpg;
        apt update;
        show_root_menu;;
    2)  echo 'Installation of Cinnamon';
        apt install slick-greeter muffin cinnamon;
        show_root_menu;;
    3)  echo 'Package upgrade';
        apt update && apt upgrade -y;
        show_root_menu;;
    4)  show_pckg_menu;;
    5)  sh ubuntu-mainline-kernel.sh;
        show_root_menu;;
    6)  show_solver_menu;;
    7)  show_nvidia_menu;;
    x)  echo Reboot;
        reboot;;
    q)  clear; 
        exit ;;
esac

show_pckg_menu
case "$result" in
     1) echo 'Package Install';
        sh installpkgs.sh;;
     2) echo 'Manualy installed packages exported';
        sh pkgsexport.sh;;
     3) echo 'Package upgrade';
        apt update && apt upgrade -y;
        show_pckg_menu;;
     4) show_root_menu;;
     x) echo 'Reboot';
        reboot;;
     q) clear; 
        exit ;;
esac

show_solver_menu
case "$result" in
     1) echo 'Applying changes to network settings';
        clear;
        option_picked "Option 1 Picked";
        touch /etc/network/interfaces;
        sh -c 'echo "auto lo" >> /etc/network/interfaces';
        sh -c 'echo "iface lo inet loopback" >> /etc/network/interfaces';
        sh -c 'echo "  renderer: NetworkManager" >> /etc/netplan/*.yaml';
        netplan apply;
        show_solver_menu;;
     2) echo 'Applying changes to sound settings';
        ln -s /usr/share/pipewire /etc/pipewire;
        touch /usr/share/pipewire/media-session.d/with-pulseaudio;
        systemctl --user restart pipewire-session-manager;
        systemctl --user start pulseaudio;
        show_solver_menu;;
     3) echo 'Package upgrade';
        apt update && apt upgrade -y;
        show_solver_menu;;
     4) show_root_menu;;
     x) echo 'Reboot';
        reboot;;
     q) clear; 
        exit ;;
esac

show_nvidia_menu
case "$result" in
     1) echo 'NVidia driver 515 installation';
        apt install nvidia-driver-515 -y;
        show_nvidia_menu;;
     2) echo 'NVidia driver 525 installation';
        apt install nvidia-driver-525 -y;
        show_nvidia_menu;;
     3) echo 'Package upgrade';
        apt update && apt upgrade -y;
        show_nvidia_menu;;
     4) show_root_menu;;
     x) echo 'Reboot';
        reboot;;
     q) clear; exit ;;
esac

答え1

インストーラの末尾には、、、および4つのメニュー呼び出しがあり、各メニュー呼び出しは対応するCaseステートメントに従いますshow_root_menushow_pckg_menushow_solver_menushow_nvidia_menu

何が起こるか:ルートメニューが表示され、ユーザーがを押すとcancelパッケージメニューが表示されます。cancel- >ソルバーメニュー、cancel- > nvidiaメニュー、cancel- >終了(スクリプト終了)を押します。

スクリプトを再起動して7(nvidiaメニュー)を押してから、を押して4ルートメニューに戻ると、Caseステートメントが失われてshow_pckg_menu呼び出されます。

修正:show_root_menuスクリプトの最後でのみ呼び出し、後でCaseステートメントをその関数に移動しますresult=$(dialog...)

#!/bin/bash
show_root_menu(){
width=72
height=50
menu_height=8
backtitle="Installer-menu"
title="Setup opions"
menu="Choose one of the following options:"

options=(1 'Add Mint PPA and update' 
         2 'Install Cinnamon '
         3 'update and upgrade '
         4 'Additional software installation '
         5 'Upgrade Kernel '
         6 'Resolve Ubuntu Cinnamon issues '
         7 'Install graphic proprietary driver'
         x reboot
         q quit )
    
result=$(dialog --clear \
                --backtitle "$backtitle" \
                --title "$title" \
                --menu "$menu" \
                $height $width $menu_height \
                "${options[@]}" \
                2>&1 >/dev/tty)

case "$result" in
    1)  echo 'Mint backport repos installed';
        apt-key adv --recv-keys --keyserver keyserver.ubuntu.com A1715D88E1DF1F24 40976EAF437D05B5 3B4FE6ACC0B21F32 A6616109451BBBF2;
        sh -c 'echo "deb http://packages.linuxmint.com vanessa main upstream import backport romeo" >> /etc/apt/sources.list.d/mint.list';
        sh -c 'echo "deb-src http://packages.linuxmint.com vanessa main upstream import backport romeo" >> /etc/apt/sources.list.d/mint.list';
        apt-key export 451BBBF2 | gpg --dearmour -o /etc/apt/trusted.gpg.d/mint.gpg;
        apt update;
        show_root_menu;;
    2)  echo 'Installation of Cinnamon';
        apt install slick-greeter muffin cinnamon;
        show_root_menu;;
    3)  echo 'Package upgrade';
        apt update && apt upgrade -y;
        show_root_menu;;
    4)  show_pckg_menu;;
    5)  sh ubuntu-mainline-kernel.sh;
        show_root_menu;;
    6)  show_solver_menu;;
    7)  show_nvidia_menu;;
    x)  echo Reboot;
        reboot;;
    q)  clear; 
        exit ;;
esac
}
show_pckg_menu(){
width=72
height=22
menu_height=8
backtitle='Installer-menu'
title='Package options'
menu='Choose one of the following options:'

options=(1 'Install package list'
         2 'Export package list'
         3 'update and upgrade'
         4 'Show root menu'
         x reboot
         q quit )

result=$(dialog --clear \
                --backtitle "$backtitle" \
                --title "$title" \
                --menu "$menu" \
                $height $width $menu_height \
                "${options[@]}" \
                2>&1 >/dev/tty)

case "$result" in
     1) echo 'Package Install';
        sh installpkgs.sh;;
     2) echo 'Manualy installed packages exported';
        sh pkgsexport.sh;;
     3) echo 'Package upgrade';
        apt update && apt upgrade -y;
        show_pckg_menu;;
     4) show_root_menu;;
     x) echo 'Reboot';
        reboot;;
     q) clear; 
        exit ;;
esac
}
show_solver_menu(){
width=72
height=22
menu_height=8
backtitle='Installer-menu'
title='Resolver menu'
menu='Choose one of the following options:'

options=(1 'Network applet problem'
         2 'Sound problem'
         3 'update and upgrade'
         4 'Show root menu'
         x reboot
         q quit )


result=$(dialog --clear \
                --backtitle "$backtitle" \
                --title "$title" \
                --menu "$menu" \
                $height $width $menu_height \
                "${options[@]}" \
                2>&1 >/dev/tty)

case "$result" in
     1) echo 'Applying changes to network settings';
        clear;
        option_picked "Option 1 Picked";
        touch /etc/network/interfaces;
        sh -c 'echo "auto lo" >> /etc/network/interfaces';
        sh -c 'echo "iface lo inet loopback" >> /etc/network/interfaces';
        sh -c 'echo "  renderer: NetworkManager" >> /etc/netplan/*.yaml';
        netplan apply;
        show_solver_menu;;
     2) echo 'Applying changes to sound settings';
        ln -s /usr/share/pipewire /etc/pipewire;
        touch /usr/share/pipewire/media-session.d/with-pulseaudio;
        systemctl --user restart pipewire-session-manager;
        systemctl --user start pulseaudio;
        show_solver_menu;;
     3) echo 'Package upgrade';
        apt update && apt upgrade -y;
        show_solver_menu;;
     4) show_root_menu;;
     x) echo 'Reboot';
        reboot;;
     q) clear; 
        exit ;;
esac
}
show_nvidia_menu(){
width=72
height=22
menu_height=8
backtitle='Installer-menu'
title='NVidia driver selection'
menu='Choose one of the following options:'

options=(1 'Install nvidia 515'
         2 'Install nvidia 525'
         3 'Update and upgrade'
         4 'Show root menu'
         x reboot
         q quit )

result=$(dialog --clear \
                --backtitle "$backtitle" \
                --title "$title" \
                --menu "$menu" \
                $height $width $menu_height \
                "${options[@]}" \
                2>&1 >/dev/tty)

case "$result" in
     1) echo 'NVidia driver 515 installation';
        apt install nvidia-driver-515 -y;
        show_nvidia_menu;;
     2) echo 'NVidia driver 525 installation';
        apt install nvidia-driver-525 -y;
        show_nvidia_menu;;
     3) echo 'Package upgrade';
        apt update && apt upgrade -y;
        show_nvidia_menu;;
     4) show_root_menu;;
     x) echo 'Reboot';
        reboot;;
     q) clear; exit ;;
esac
}

show_root_menu

関連情報