From: xf0r3m Date: Sat, 15 Jul 2023 10:51:49 +0000 (+0200) Subject: Dodanie funkcji 'idle-fetch-container' do skryptu 'idle.sh' X-Git-Url: https://gitweb.morketsmerke.org/?a=commitdiff_plain;h=d5a02fa744e0dbc7e651e8191ca987baa25eca5b;p=idle.git Dodanie funkcji 'idle-fetch-container' do skryptu 'idle.sh' --- diff --git a/idle.sh b/idle.sh index dd80dc4..b867f4b 100644 --- a/idle.sh +++ b/idle.sh @@ -55,3 +55,63 @@ function idle-list-containers() { done fi } + +function idle-fetch-containers() { + + function create-container() { + containerName=$1; + containerImagePath=$(grep $name $DATABASE | cut -d ";" -f 1); + startupScript=$(grep $name $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."; + } + + function list-containers() { + for contName in $(grep $1 $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); do + echo -e "\t\t $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 + else + $contName=$1; + create-container $contName; + fi + else + echo "idle-fetch-containers - fetch IDLE containers"; + echo "IDLE Project @ 2023 morketsmerke.org"; + echo; + echo "Usage: "; + echo "$ idle-fetch-containers <--all/container_name/group_containers>"; + echo; + echo "Containers name:"; + for contName in $(cut -d ";" -f 1 $DATABASE | awk '{printf $1" "}'); do + echo -e "\t${contName}"; + done + echo; + echo "Groups:"; + echo -e "\t --deb - based on APT package manager (like Debian or Ubuntu)"; + 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 + echo -e "\t --rpm - based on RPM package manager (like CentOS or Fedora)"; + 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 + echo -e "\t --other - other containers not fit to above group (like Arch or Gentoo)"; + grepOpts="-v -E 'rpm.sh|fedora.sh|opensuse.sh|alt.sh|deb.sh'"; + list-containers $grepOpts; + return 1; + fi +}