diff --git a/scripts/global/share-common.func b/scripts/global/share-common.func index 238095e..9dcf09d 100644 --- a/scripts/global/share-common.func +++ b/scripts/global/share-common.func @@ -254,4 +254,38 @@ select_host_directory() { fi echo "$result" +} + + + + + + +select_lxc_container() { + local ct_list ctid ct_status + + ct_list=$(pct list | awk 'NR>1 {print $1, $2, $3}') + if [[ -z "$ct_list" ]]; then + dialog --title "$(translate "Error")" \ + --msgbox "$(translate "No LXC containers available")" 8 50 + return 1 + fi + + local options=() + while read -r id name status; do + if [[ -n "$id" ]]; then + options+=("$id" "$name ($status)") + fi + done <<< "$ct_list" + + ctid=$(dialog --title "$(translate "Select LXC Container")" \ + --menu "$(translate "Select container:")" 20 70 12 \ + "${options[@]}" 3>&1 1>&2 2>&3) + + if [[ -z "$ctid" ]]; then + return 1 + fi + + echo "$ctid" + return 0 } \ No newline at end of file