Skip to content

Commit

Permalink
automataCI: finalized md5 library
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 md5 library.

This patch finalizes md5 library capabilities in automataCI/
directory.

Signed-off-by: (Holloway) Chew, Kean Ho <[email protected]>
  • Loading branch information
hollowaykeanho committed Dec 15, 2023
1 parent 070b6ff commit 6bccde7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 24 deletions.
31 changes: 21 additions & 10 deletions automataCI/services/checksum/md5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,47 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
function MD5-Checksum-File {
. "${env:LIBS_AUTOMATACI}\services\io\fs.ps1"
. "${env:LIBS_AUTOMATACI}\services\io\strings.ps1"




function MD5-Checksum-From-File {
param (
[string]$__target
[string]$___target
)


# validate input
if ([string]::IsNullOrEmpty("${__target}") -or (-not (Test-Path -Path "${__target}"))) {
if ($(STRINGS-Is-Available "${___target}") -eq 0) {
return 1
}

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


# execute
$__hasher = [System.Security.Cryptography.MD5]::Create("MD5")
$__stream = [System.IO.File]::OpenRead($__target)
$__hash = [System.BitConverter]::ToString($__hasher.ComputeHash($__stream))
$null = $__stream.Close()
$___hasher = [System.Security.Cryptography.MD5]::Create("MD5")
$___stream = [System.IO.File]::OpenRead($___target)
$___hash = [System.BitConverter]::ToString($___hasher.ComputeHash($___stream))
$null = $___stream.Close()


# report status
return $__hash.Replace("-", "").ToLower()
return $___hash.Replace("-", "").ToLower()
}




function MD5-Is-Available {
# execute
$__md5 = [System.Security.Cryptography.MD5]::Create("MD5")
if ($__md5) {
$___md5 = [System.Security.Cryptography.MD5]::Create("MD5")
if ($___md5) {
return 0
}

Expand Down
50 changes: 39 additions & 11 deletions automataCI/services/checksum/md5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,67 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
MD5::checksum_file() {
# __target="$1"
. "${LIBS_AUTOMATACI}/services/io/os.sh"
. "${LIBS_AUTOMATACI}/services/io/fs.sh"
. "${LIBS_AUTOMATACI}/services/io/strings.sh"




MD5_Checksum_From_File() {
#___target="$1"


# validate input
if [ -z "$1" ] || [ ! -f "$1" ]; then
if [ $(STRINGS_Is_Empty "$1") -eq 0 ]; then
return 1
fi

FS::is_file "$1"
if [ $? -ne 0 ]; then
return 1
fi


# execute
if [ ! -z "$(type -t md5sum)" ]; then
OS::is_command_available "md5sum"
if [ $? -eq 0 ]; then
md5sum "$1"
elif [ ! -z "$(type -t md5)" ]; then
md5 "$1"
fi
if [ $? -ne 0 ]; then
return 1
fi

return 0
fi

# report status
OS::is_command_available "md5"
if [ $? -eq 0 ]; then
md5 "$1"
if [ $? -ne 0 ]; then
return 1
fi

return 0
fi


# report status
return 1
}




MD5::is_available() {
MD5_Is_Available() {
# execute
if [ ! -z "$(type -t md5sum)" ] || [ ! -z "$(type -t md5)" ]; then
return 0
OS::is_command_available "md5sum"
if [ $? -ne 0 ]; then
return 1
fi

OS::is_command_available "md5"
if [ $? -ne 0 ]; then
return 1
fi


Expand Down
2 changes: 1 addition & 1 deletion automataCI/services/compilers/deb.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function DEB-Create-Checksum {

# checksum each file
foreach ($___file in (Get-ChildItem -Path "${___directory}\data" -File -Recurse)) {
$___checksum = MD5-Checksum-File $___file.FullName
$___checksum = MD5-Checksum-From-File $___file.FullName
$___path = $___file.FullName `
-replace [regex]::Escape("${___directory}\data\"), ""
$___path = $___path -replace "\\", "/"
Expand Down
4 changes: 2 additions & 2 deletions automataCI/services/compilers/deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ DEB_Create_Checksum() {

# checksum every items
for ___line in $(find "${1}/data" -type f); do
___checksum="$(MD5::checksum_file "$___line")"
___checksum="$(MD5_Checksum_From_File "$___line")"
FS::append_file "$___location" \
"${___checksum%% *} ${___line##*${1}/data/}\n"
if [ $? -ne 0 ]; then
Expand Down Expand Up @@ -462,7 +462,7 @@ DEB_Is_Available() {


# validate dependencies
MD5::is_available
MD5_Is_Available
if [ $? -ne 0 ]; then
return 1
fi
Expand Down

0 comments on commit 6bccde7

Please sign in to comment.