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
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
}