반환 스크립트의 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

설치 프로그램 끝에는 , show_root_menu, show_pckg_menu및 4개의 메뉴 호출이 있으며, 각 메뉴 show_solver_menu호출은 show_nvidia_menu해당하는 Case 문을 따릅니다.

무슨 일이 일어나는가: 루트 메뉴가 표시되고 사용자가 를 누르면 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

관련 정보