From: xf0r3m Date: Wed, 9 Aug 2023 08:58:13 +0000 (+0200) Subject: Wdrożenie funkcji 'idle-get-container-name-list' zwracającej listę nazw kontenerów... X-Git-Url: https://gitweb.morketsmerke.org/?a=commitdiff_plain;h=e561ca393188f994cf0e6c2e655f8d71437b1a7a;p=idle.git Wdrożenie funkcji 'idle-get-container-name-list' zwracającej listę nazw kontenerów (wszystkich/z grup/z rozwiązania list) - głowny skrypt funkcji - idle.sh --- diff --git a/idle.sh b/idle.sh index cb55690..da59050 100644 --- a/idle.sh +++ b/idle.sh @@ -39,12 +39,31 @@ function idle-lxd-init() { cat $HOME/idle/idle_preseed.yaml | sudo lxd init --preseed; } + +function idle-get-container-name-list() { + rpmGrepOpts='-E rocky.sh|fedora.sh|opensuse.sh'; + debGrepOpts='deb.sh'; + otherGrepOpts='-v -E rocky.sh|fedora.sh|opensuse.sh|deb.sh'; + if [ "$1" = "--deb" ]; then + echo $(grep $debGrepOpts $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); + elif [ "$1" = "--rpm" ]; then + echo $(grep $rpmGrepOpts $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); + elif [ "$1" = "--other" ]; then + echo $(grep $otherGrepOpts $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); + elif [ "$1" = "--all" ]; then + echo $(cut -d ";" -f 3 $DATABASE | awk '{printf $1" "}'); + elif echo $1 | grep -q '\,'; then + echo $(echo $1 | sed 's/,/ /g'); + fi +} + function idle-list-containers() { if ! lxc profile show default | grep -q 'idle'; then echo -e "${RED}LXD isn't initialized. You must run 'idle-lxd-init' firs${ENDCOLOR}"; exit 1; else - for container in $(cut -d ";" -f 3 $DATABASE | awk '{printf $1" "}'); do + containerNameList=$(idle-get-container-name-list --all); + for container in $containerNameList; do if lxc info $container >> /dev/null 2>&1; then installed="\e[32m\u2714\e[0m"; else @@ -88,18 +107,16 @@ function idle-fetch-containers() { } function list-containers() { - containerNameList=$(grep $@ $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); + containerNameList=$(idle-get-container-name-list $1); for contName in $containerNameList; do echo -e " $contName"; done } + + function mass-create-container() { - if echo $1 | grep -q '\,'; then - containerNameList=$(echo $1 | sed 's/,/ /g'); - else - containerNameList=$(grep $@ $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); - fi + containerNameList=$(idle-get-container-name-list $1); for contName in $containerNameList; do create-container $contName; done @@ -115,18 +132,7 @@ function idle-fetch-containers() { exit 1; else if [ "$1" ]; then - if [ "$1" = "--all" ]; then - containerNameList=$(cut -d ";" -f 3 $DATABASE | awk '{printf $1" "}'); - for contName in $containerNameList; do - create-container $contName; - done - elif [ "$1" = "--deb" ]; then - mass-create-container $debGrepOpts; - elif [ "$1" = "--rpm" ]; then - mass-create-container $rpmGrepOpts; - elif [ "$1" = "--other" ]; then - mass-create-container $otherGrepOpts; - elif echo $1 | grep -q '\,'; then + if echo $1 | grep -q '\-\-'; then mass-create-container $1; else contName=$1; @@ -175,3 +181,5 @@ function idle-rm-container() { containerName=$1; lxc delete -f $containerName; } + +