Skip to content

Commit

Permalink
automataCI: finalized tar.gz and tar.xz libraries
Browse files Browse the repository at this point in the history
Since we want to release soon, we must finalize the library. Hence,
let's deal with tar.gz and tar.xz libraries.

This patch finalizes tar.gz and tar.xz libraries capabilities in
automataCI/ directory.

Co-authored-by: Galyna, Cory <124406765+corygalyna@users.noreply.github.com>
Co-authored-by: (Holloway) Chew, Kean Ho <hollowaykeanho@gmail.com>
Signed-off-by: (Holloway) Chew, Kean Ho <hollowaykeanho@gmail.com>
hollowaykeanho and corygalyna committed Dec 15, 2023
1 parent 673a3e1 commit bd1ac53
Showing 8 changed files with 182 additions and 108 deletions.
4 changes: 2 additions & 2 deletions automataCI/_package-archive_unix-any.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions automataCI/_package-homebrew_unix-any.sh
Original file line number Diff line number Diff line change
@@ -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
117 changes: 74 additions & 43 deletions automataCI/services/archive/tar.ps1
Original file line number Diff line number Diff line change
@@ -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
}

$___process = FS-Is-File "${___destination}"
if ($___process -eq 0) {
return 1
}

if (Test-Path -Path $__destination) {
$___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,32 +139,44 @@ 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
}

$___process = FS-Is-File "${___destination}"
if ($___process -eq 0) {
return 1
}

$___process = FS-Is-Directory "${___destination}"
if ($___process -eq 0) {
return 1
}

if (Test-Path -Path $__destination) {
$___process = XZ-Is-Available
if ($___process -ne 0) {
return 1
}


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

87 changes: 57 additions & 30 deletions automataCI/services/archive/tar.sh
Original file line number Diff line number Diff line change
@@ -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

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


# 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,32 +127,43 @@ 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


# create tar archive
TAR::create "${1%.xz*}" "$2" "$3" "$4"
TAR_Create "${1%.xz*}" "$2" "$3" "$4"
if [ $? -ne 0 ]; then
return 1
fi


# compress archive
XZ::create "${1%%.xz*}"
XZ_Create "${1%%.xz*}"
if [ $? -ne 0 ]; then
return 1
fi
6 changes: 3 additions & 3 deletions automataCI/services/compilers/deb.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions automataCI/services/compilers/ipk.sh
Original file line number Diff line number Diff line change
@@ -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
30 changes: 20 additions & 10 deletions automataCI/services/compress/xz.ps1
Original file line number Diff line number Diff line change
@@ -9,44 +9,54 @@
# 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:LIBS_AUTOMATACI}\services\io\os.ps1"
. "${env:LIBS_AUTOMATACI}\services\io\fs.ps1"
. "${env:LIBS_AUTOMATACI}\services\io\strings.ps1"




function XZ-Create {
param (
[string]$__source
[string]$___source
)


# validate input
$__process = XZ-Is-Available
if ($__process -ne 0) {
$___process = XZ-Is-Available
if ($___process -ne 0) {
return 1
}

if ([string]::IsNullOrEmpty($__source) -or (Test-Path $__source -PathType Container)) {
if ($(STRINGS-Is-Empty "${___source}") -eq 0) {
return 1
}

$___process = FS-Is-Directory "${___source}"
if ($___process -eq 0) {
return 1
}
$__source = $__source -replace "\.xz$"


# create .gz compressed target
$__process = OS-Exec "xz" "-9 --compress `"${__source}`""
$___source = $___source -replace "\.xz$"
$___process = OS-Exec "xz" "-9 --compress `"${___source}`""
if ($___process -ne 0) {
return 1
}


# report status
return $__process
return 0
}




function XZ-Is-Available {
# execute
$__process = OS-Is-Command-Available "xz"
if ($__process -eq 0) {
$___process = OS-Is-Command-Available "xz"
if ($___process -eq 0) {
return 0
}

34 changes: 20 additions & 14 deletions automataCI/services/compress/xz.sh
Original file line number Diff line number Diff line change
@@ -10,44 +10,50 @@
# 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/io/os.sh"
. "${LIBS_AUTOMATACI}/services/io/os.sh"
. "${LIBS_AUTOMATACI}/services/io/fs.sh"
. "${LIBS_AUTOMATACI}/services/io/strings.sh"




XZ::create() {
__source="$1"
XZ_Create() {
___source="$1"


# validate input
XZ::is_available
XZ_Is_Available
if [ $? -ne 0 ]; then
return 1
fi

if [ -z "$__source" ] || [ -d "$__source" ]; then
unset __source
if [ $(STRINGS_Is_Empty "$___source") -eq 0 ]; then
unset ___source
return 1
fi

FS::is_directory "$___source"
if [ $? -eq 0 ]; then
return 1
fi
__source="${__source%.xz}"


# create .gz compressed target
xz -9 --compress "$__source"
___source="${___source%.xz}"
xz -9 --compress "$___source"
if [ $? -ne 0 ]; then
return 1
fi


# report status
if [ $? -eq 0 ]; then
return 0
fi

return 1
return 0
}




XZ::is_available() {
XZ_Is_Available() {
# execute
OS::is_command_available "xz"
if [ $? -eq 0 ]; then

0 comments on commit bd1ac53

Please sign in to comment.