From: xf0r3m Date: Sat, 15 Jul 2023 13:40:41 +0000 (+0200) Subject: Poprawienie błedu związanego z instalacją konkretnego kontenera, dodanie obsługi... X-Git-Url: https://gitweb.morketsmerke.org/?a=commitdiff_plain;h=0a1482a42f0b7bf32a20968d779b7ad3a6153231;p=idle.git Poprawienie błedu związanego z instalacją konkretnego kontenera, dodanie obsługi instalacji grup kontenerów - tworzenie kontenerów, funkcja 'idle-fetch-containers', skrypt 'idle.sh' --- diff --git a/idle.sh b/idle.sh index 3f07b94..f763250 100644 --- a/idle.sh +++ b/idle.sh @@ -58,30 +58,52 @@ function idle-list-containers() { function idle-fetch-containers() { + rpmGrepOpts='-E rpm.sh|fedora.sh|opensuse.sh|alt.sh'; + debGrepOpts='deb.sh'; + otherGrepOpts='-v -e rpm.sh|fedora.sh|opensuse.sh|alt.sh|deb.sh'; + function create-container() { containerName=$1; - containerImagePath=$(grep $containerName $DATABASE | cut -d ";" -f 1); - startupScript=$(grep $containerName $DATABASE | cut -d ";" -f 4); - echo "lxc launch $containerImagePath $containerName"; - echo "lxc file push ${HOME}/idle/$startupScript ${containerName}/root/${startupScript}"; - echo "lxc exec $containerName /bin/bash /root/${startupScript}"; - echo "Container is ready for work."; + if grep -q $containerName $DATABASE; then + containerImagePath=$(grep $containerName $DATABASE | cut -d ";" -f 1); + startupScript=$(grep $containerName $DATABASE | cut -d ";" -f 4); + echo "lxc launch $containerImagePath $containerName"; + echo "lxc file push ${HOME}/idle/$startupScript ${containerName}/root/${startupScript}"; + echo "lxc exec $containerName /bin/bash /root/${startupScript}"; + echo "Container is ready for work."; + else + echo "Given container name doesn't exist in project database"; + fi } function list-containers() { - for contName in $(grep $@ $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); do + containerNameList=$(grep $@ $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); + for contName in $containerNameList; do echo -e " $contName"; done } + function mass-create-container() { + containerNameList=$(grep $@ $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); + for contName in $containerNameList; do + create-container $contName; + done + } + 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 $debGrepOptions; + elif [ "$1" = "--rpm" ]; then + mass-create-container $rpmGrepOptions; + elif [ "$1" = "--other" ]; then + mass-create-container $otherGrepOptions; else - $contName=$1; + contName=$1; create-container $contName; fi else @@ -98,20 +120,13 @@ function idle-fetch-containers() { echo; echo "Groups:"; echo -e " --deb - based on APT package manager"; - grepOpts="deb.sh"; - list-containers $grepOpts; - #for contName in $(grep 'deb.sh' $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); do - # echo -e "\t\t $contName"; - #done + list-containers $debGrepOpts; echo -e " --rpm - based on RPM package manager"; grepOpts='-E rpm.sh|fedora.sh|opensuse.sh|alt.sh'; - list-containers $grepOpts; - #for contName in $(grep -E 'rpm.sh|fedora.sh|opensuse.sh|alt.sh' $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); do - # echo -e "\t\t $contName"; - #done + list-containers $rpmGrepOpts; echo -e " --other - other containers not fit to above groups:"; - grepOpts='-v -E rpm.sh|fedora.sh|opensuse.sh|alt.sh|deb.sh'; - list-containers $grepOpts; + grepOpts='-v -e rpm.sh|fedora.sh|opensuse.sh|alt.sh|deb.sh'; + list-containers $otherGrepOpts; return 1; fi }