#!/bin/sh #----------------------------------------------------------------------------- # /var/install/include/cuivmlib - library for VM create and edit # # Last Update: $Id:$ # # Copyright (c) 2006-2009 the eisfair team # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #----------------------------------------------------------------------------- #---------------------------------------------------------------------------- # check if handle is valid #---------------------------------------------------------------------------- function cuivm_valid_handle() { if [ "$1" != "" -a "$1" != "0" ] then return 0 fi return 1 } #---------------------------------------------------------------------------- # check if parameter is numeric #---------------------------------------------------------------------------- function cuivm_check_is_numeric() { [ "$(echo $*|grep -v "[^0-9]")" ]; return $? } #---------------------------------------------------------------------------- # check if parameter is quota value #---------------------------------------------------------------------------- function cuivm_check_is_quota() { [ "$(echo $* | grep -i '[^0-9]*[G]:[0-9]*[G]')" ]; return $? } #---------------------------------------------------------------------------- # check if parameter is a ip address #---------------------------------------------------------------------------- function cuivm_check_is_ipaddress() { if echo $1 | egrep -qs '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b' then return 0 else return 1 fi } #---------------------------------------------------------------------------- # terminal_exit # close terminal #---------------------------------------------------------------------------- terminal_exit() { win="$p2" ctrl="$p3" cui_window_close "$ctrl" "$IDOK" cui_return 0 } #---------------------------------------------------------------------------- # cuivm_create_terminal # run modifications with output to terminal #---------------------------------------------------------------------------- function cuivm_create_terminal() { local win="$1" local dlg local runfile="$2" local termtitle="$3" cui_terminal_new "$win" " $termtitle " 0 0 72 18 1112 $[$CWS_POPUP + $CWS_CENTERED] $CWS_NONE && dlg="$p2" if cuivm_valid_handle $dlg then cui_terminal_callback "$dlg" "$TERMINAL_EXIT" "$win" "terminal_exit" cui_window_create "$dlg" cui_terminal_run "$dlg" "$runfile" cui_window_modal "$dlg" cui_window_destroy "$dlg" fi }