diff --git a/automataCI/_package-archive_unix-any.sh b/automataCI/_package-archive_unix-any.sh index fccafaaf..6d625293 100644 --- a/automataCI/_package-archive_unix-any.sh +++ b/automataCI/_package-archive_unix-any.sh @@ -50,7 +50,7 @@ PACKAGE::run_archive() { OS::print_status info "checking tar functions availability...\n" - TAR::is_available + TAR_Is_Available if [ $? -ne 0 ]; then OS::print_status error "check failed.\n" return 1 @@ -121,7 +121,7 @@ PACKAGE::run_archive() { *) _target_path="${_target_path}.tar.xz" OS::print_status info "packaging ${_target_path}\n" - TAR::create_xz "$_target_path" "*" + TAR_Create_XZ "$_target_path" "*" __exit=$? ;; esac diff --git a/automataCI/_package-homebrew_unix-any.sh b/automataCI/_package-homebrew_unix-any.sh index fef63f61..6bd33ebd 100644 --- a/automataCI/_package-homebrew_unix-any.sh +++ b/automataCI/_package-homebrew_unix-any.sh @@ -58,7 +58,7 @@ PACKAGE::run_homebrew() { # validate input I18N_Status_Print_Check_Availability "TAR" - TAR::is_available + TAR_Is_Available if [ $? -ne 0 ]; then I18N_Status_Print_Check_Availability_Incompatible "TAR" return 1 @@ -117,7 +117,7 @@ PACKAGE::run_homebrew() { # archive the assembled payload __current_path="$PWD" && cd "$_src" I18N_Status_Print_File_Archive "${_target_path}.tar.xz" - TAR::create_xz "${_target_path}.tar.xz" "*" + TAR_Create_XZ "${_target_path}.tar.xz" "*" __exit=$? cd "$__current_path" && unset __current_path if [ $__exit -ne 0 ]; then diff --git a/automataCI/services/archive/tar.ps1 b/automataCI/services/archive/tar.ps1 index 5c0d3049..36340293 100644 --- a/automataCI/services/archive/tar.ps1 +++ b/automataCI/services/archive/tar.ps1 @@ -9,17 +9,19 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\io\os.ps1" -. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\compress\gz.ps1" -. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\compress\xz.ps1" +. "${env:LIBS_AUTOMATACI}\services\io\os.ps1" +. "${env:LIBS_AUTOMATACI}\services\io\fs.ps1" +. "${env:LIBS_AUTOMATACI}\services\io\strings.ps1" +. "${env:LIBS_AUTOMATACI}\services\compress\gz.ps1" +. "${env:LIBS_AUTOMATACI}\services\compress\xz.ps1" function TAR-Is-Available { # validate input - $__process = Get-Command "tar" -ErrorAction SilentlyContinue - if (-not ($__process)) { + $___process = OS-Is-Command-Available "tar" + if ($___process -ne 0) { return 1 } @@ -33,40 +35,50 @@ function TAR-Is-Available { function TAR-Create { param ( - [string]$__destination, - [string]$__source, - [string]$__owner, - [string]$__group + [string]$___destination, + [string]$___source, + [string]$___owner, + [string]$___group ) # validate input - if ([string]::IsNullOrEmpty($__destination) -or [string]::IsNullOrEmpty($__source)) { + if (($(STRINGS-Is-Empty "${___destination}") -eq 0) -or + ($(STRINGS-Is-Empty "${___source}") -eq 0)) { return 1 } - if (Test-Path -Path $__destination) { + $___process = FS-Is-File "${___destination}" + if ($___process -eq 0) { return 1 } - $__process = TAR-Is-Available - if ($__process -ne 0) { + $___process = FS-Is-Directory "${___destination}" + if ($___process -eq 0) { + return 1 + } + + $___process = TAR-Is-Available + if ($___process -ne 0) { return 1 } # create tar archive - if ((-not [string]::IsNullOrEmpty($__owner)) -and [string]::IsNullOrEmpty($__group)) { - $__arguments = "--numeric-owner --group=`"${__group}`" " ` - + "--owner=`"${__owner}`" " ` - + "-cvf `"${__destination}`" ${__source}" - $__process = OS-Exec "tar" "${__arguments}" - if ($__process -ne 0) { + $___supported = $false # windows' TAR system does not support UNIX UGID system + if (($___supported) -and + ($(STRINGS-Is-Empty "${___owner}") -ne 0) -and + ($(STRINGS-Is-Empty "${___group}") -ne 0)) { + $___arguments = "--numeric-owner --group=`"${___group}`" " ` + + "--owner=`"${___owner}`" " ` + + "-cvf `"${___destination}`" ${___source}" + $___process = OS-Exec "tar" "${___arguments}" + if ($___process -ne 0) { return 1 } } else { - $__process = OS-Exec "tar" "-cvf `"${__destination}`" ${__source}" - if ($__process -ne 0) { + $___process = OS-Exec "tar" "-cvf `"${___destination}`" ${___source}" + if ($___process -ne 0) { return 1 } } @@ -81,32 +93,39 @@ function TAR-Create { function TAR-Create-GZ { param ( - [string]$__destination, - [string]$__source, - [string]$__owner, - [string]$__group + [string]$___destination, + [string]$___source, + [string]$___owner, + [string]$___group ) # validate input - if ([string]::IsNullOrEmpty($__destination) -or [string]::IsNullOrEmpty($__source)) { + if (($(STRINGS-Is-Empty "${___destination}") -eq 0) -or + ($(STRINGS-Is-Empty "${___source}") -eq 0)) { return 1 } - if (Test-Path -Path $__destination) { + $___process = FS-Is-File "${___destination}" + if ($___process -eq 0) { + return 1 + } + + $___process = FS-Is-Directory "${___destination}" + if ($___process -eq 0) { return 1 } # create tar archive - $__dest = $__destination -replace '\.gz.*$' - $__process = TAR-Create "${__dest}" "${__source}" "0" "0" - if ($__process -ne 0) { + $___dest = $___destination -replace '\.gz.*$' + $___process = TAR-Create "${___dest}" "${___source}" "${___owner}" "${___group}" + if ($___process -ne 0) { return 1 } - $__process = GZ-Create "${__dest}" - if ($__process -ne 0) { + $___process = GZ-Create "${___dest}" + if ($___process -ne 0) { return 1 } @@ -120,19 +139,31 @@ function TAR-Create-GZ { function TAR-Create-XZ { param ( - [string]$__destination, - [string]$__source, - [string]$__owner, - [string]$__group + [string]$___destination, + [string]$___source, + [string]$___owner, + [string]$___group ) # validate input - if ([string]::IsNullOrEmpty($__destination) -or [string]::IsNullOrEmpty($__source)) { + if (($(STRINGS-Is-Empty "${___destination}") -eq 0) -or + ($(STRINGS-Is-Empty "${___source}") -eq 0)) { return 1 } - if (Test-Path -Path $__destination) { + $___process = FS-Is-File "${___destination}" + if ($___process -eq 0) { + return 1 + } + + $___process = FS-Is-Directory "${___destination}" + if ($___process -eq 0) { + return 1 + } + + $___process = XZ-Is-Available + if ($___process -ne 0) { return 1 } @@ -142,14 +173,14 @@ function TAR-Create-XZ { } # create tar archive - $__dest = $__destination -replace '\.xz.*$' - $__process = TAR-Create "${__dest}" "${__source}" "0" "0" - if ($__process -ne 0) { + $___destination = $___destination -replace '\.xz.*$' + $___process = TAR-Create "${___destination}" "${___source}" "${___owner}" "${___group}" + if ($___process -ne 0) { return 1 } - $__process = XZ-Create "${__dest}" - if ($__process -ne 0) { + $___process = XZ-Create "${___destination}" + if ($___process -ne 0) { return 1 } diff --git a/automataCI/services/archive/tar.sh b/automataCI/services/archive/tar.sh index 8a131682..fa93da8a 100644 --- a/automataCI/services/archive/tar.sh +++ b/automataCI/services/archive/tar.sh @@ -10,15 +10,19 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. -. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_AUTOMATA}/services/compress/gz.sh" -. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_AUTOMATA}/services/compress/xz.sh" +. "${LIBS_AUTOMATACI}/services/io/os.sh" +. "${LIBS_AUTOMATACI}/services/io/fs.sh" +. "${LIBS_AUTOMATACI}/services/io/strings.sh" +. "${LIBS_AUTOMATACI}/services/compress/gz.sh" +. "${LIBS_AUTOMATACI}/services/compress/xz.sh" -TAR::is_available() { +TAR_Is_Available() { # execute - if [ -z "$(type -t tar)" ]; then + OS::is_command_available "tar" + if [ $? -ne 0 ]; then return 1 fi @@ -30,30 +34,36 @@ TAR::is_available() { -TAR::create() { - #__destination="$1" - #__source="$2" - #__owner="$3" - #__group="$4" +TAR_Create() { + #___destination="$1" + #___source="$2" + #___owner="$3" + #___group="$4" # validate input - if [ -z "$2" ] || [ -z "$1" ]; then + if [ $(STRINGS_Is_Empty "$2") -eq 0 ] || [ $(STRINGS_Is_Empty "$1") -eq 0 ]; then + return 1 + fi + + FS::is_file "$1" + if [ $? -eq 0 ]; then return 1 fi - if [ -e "$1" ]; then + FS::is_directory "$1" + if [ $? -eq 0 ]; then return 1 fi - TAR::is_available + TAR_Is_Available if [ $? -ne 0 ]; then return 1 fi # create tar archive - if [ ! -z "$3" -a ! -z "$4" ]; then + if [ $(STRINGS_Is_Empty "$3") -ne 0 ] && [ $(STRINGS_Is_Empty "$4") -ne 0 ]; then tar --numeric-owner --group="$4" --owner="$3" -cvf "$1" $2 if [ $? -ne 0 ]; then return 1 @@ -73,25 +83,31 @@ TAR::create() { -TAR::create_gz() { - #__destination="$1" - #__source="$2" - #__owner="$3" - #__group="$4" +TAR_Create_GZ() { + #___destination="$1" + #___source="$2" + #___owner="$3" + #___group="$4" # validate input - if [ -z "$2" ] || [ -z "$1" ]; then + if [ $(STRINGS_Is_Empty "$2") -eq 0 ] || [ $(STRINGS_Is_Empty "$1") -eq 0 ]; then return 1 fi - if [ -e "$1" ]; then + FS::is_file "$1" + if [ $? -eq 0 ]; then + return 1 + fi + + FS::is_directory "$1" + if [ $? -eq 0 ]; then return 1 fi # create tar archive - TAR::create "${1%.gz*}" "$2" "$3" "$4" + TAR_Create "${1%.gz*}" "$2" "$3" "$4" if [ $? -ne 0 ]; then return 1 fi @@ -111,19 +127,30 @@ TAR::create_gz() { -TAR::create_xz() { - #__destination="$1" - #__source="$2" - #__owner="$3" - #__group="$4" +TAR_Create_XZ() { + #___destination="$1" + #___source="$2" + #___owner="$3" + #___group="$4" # validate input - if [ -z "$2" ] || [ -z "$1" ]; then + if [ $(STRINGS_Is_Empty "$2") -eq 0 ] || [ $(STRINGS_Is_Empty "$1") -eq 0 ]; then return 1 fi - if [ -e "$1" ]; then + FS::is_file "$1" + if [ $? -eq 0 ]; then + return 1 + fi + + FS::is_directory "$1" + if [ $? -eq 0 ]; then + return 1 + fi + + XZ_Is_Available + if [ $? -ne 0 ]; then return 1 fi @@ -133,7 +160,7 @@ TAR::create_xz() { fi # create tar archive - TAR::create "${1%.xz*}" "$2" "$3" "$4" + TAR_Create "${1%.xz*}" "$2" "$3" "$4" if [ $? -ne 0 ]; then return 1 fi diff --git a/automataCI/services/compilers/deb.sh b/automataCI/services/compilers/deb.sh index 1ad0c7a3..c6518655 100644 --- a/automataCI/services/compilers/deb.sh +++ b/automataCI/services/compilers/deb.sh @@ -59,7 +59,7 @@ DEB_Create_Archive() { # package control cd "${___directory}/control" - TAR::create_xz "../control.tar.xz" "*" + TAR_Create_XZ "../control.tar.xz" "*" if [ $? -ne 0 ]; then cd "$___current_path" && unset ___current_path return 1 @@ -68,7 +68,7 @@ DEB_Create_Archive() { # package data cd "${___directory}/data" - TAR::create_xz "../data.tar.xz" "*" + TAR_Create_XZ "../data.tar.xz" "*" if [ $? -ne 0 ]; then cd "$___current_path" && unset ___current_path return 1 @@ -467,7 +467,7 @@ DEB_Is_Available() { return 1 fi - TAR::is_available + TAR_Is_Available if [ $? -ne 0 ]; then return 1 fi diff --git a/automataCI/services/compilers/ipk.sh b/automataCI/services/compilers/ipk.sh index 6332a903..7508d57b 100644 --- a/automataCI/services/compilers/ipk.sh +++ b/automataCI/services/compilers/ipk.sh @@ -40,7 +40,7 @@ IPK::create_archive() { # package control cd "${__directory}/control" - TAR::create_gz "../control.tar.gz" "*" + TAR_Create_GZ "../control.tar.gz" "*" if [ $? -ne 0 ]; then cd "$__current_path" && unset __current_path return 1 @@ -49,7 +49,7 @@ IPK::create_archive() { # package data cd "${__directory}/data" - TAR::create_gz "../data.tar.gz" "*" + TAR_Create_GZ "../data.tar.gz" "*" if [ $? -ne 0 ]; then cd "$__current_path" && unset __current_path return 1 @@ -67,7 +67,7 @@ IPK::create_archive() { # archive into ipk __file="package.ipk" - TAR::create_gz "$__file" "debian-binary control.tar.gz data.tar.gz" + TAR_Create_GZ "$__file" "debian-binary control.tar.gz data.tar.gz" if [ $? -ne 0 ]; then cd "$__current_path" && unset __current_path return 1 @@ -217,7 +217,7 @@ IPK::is_available() { # validate dependencies - TAR::is_available + TAR_Is_Available if [ $? -ne 0 ]; then return 1 fi