diff --git a/install/build.sh b/install/build.sh index 072307e..60785c4 100755 --- a/install/build.sh +++ b/install/build.sh @@ -23,6 +23,12 @@ case $1 in mv -v $SRC_DIR/glacier $PREFIX printf "directory $PREFIX/bin does not exist, moving to $PREFIX instead\n" fi + CC $SRC_DIR/int-check/main.c -o glacier-integrity-check + mv -v $SRC_DIR/int-check/glacier-integrity-check $PREFIX/bin + if [ "$?" != 0 ]; then + mv -v $SRC_DIR/int-check/glacier-integrity-check $PREFIX + printf "directory $PREFIX/bin does not exist, moving to $PREFIX instead.\n" + fi printf "installing configuration files\n" mv -v $SRC_DIR/glacier.conf $CONFDIR if [ "$?" != 0 ]; then diff --git a/install/install.conf.def b/install/install.conf.def index 1d0a191..6f1f508 100755 --- a/install/install.conf.def +++ b/install/install.conf.def @@ -8,3 +8,6 @@ PREFIX="/usr" # System config directory # On almost all systems, this should be /etc CONFDIR="/etc" + +# C Compiler to use +CC="gcc" diff --git a/src/glacier b/src/glacier index 4f52239..84b4c1b 100755 --- a/src/glacier +++ b/src/glacier @@ -27,7 +27,9 @@ get_pkg() { int_check() { if [ "$GLACIER_DO_INT_CHECK" = "true" ]; then printf "$blue[ i ]$reset Checking package integrity...\n" - /usr/bin/glacier-integrity-check + mv *.checksum local_sum + sha256sum *.tar.gz > pkg_sum + /usr/bin/glacier-integrity-check local_sum pkg_sum if [ "$?" != "0" ]; then printf "$red[ $error ]$reset Integrity check failed.\n" exit 1 diff --git a/src/glacier-integrity-check b/src/glacier-integrity-check deleted file mode 100755 index 4b41bfb..0000000 --- a/src/glacier-integrity-check +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python3 - -import sys -import os - -LOCAL_SUM=os.system("cat *.checksum") -PKG_SUM=os.system("sha256sum *.tar.gz") - -if LOCAL_SUM == PKG_SUM: - print("checksums match\n") - sys.exit(0) -elif LOCAL_SUM != PKG_SUM: - print("checksums do not match\n") - sys.exit(1) -else: - print("an error occured\n") - sys.exit(1) -print("=======================================") diff --git a/src/int-check/main.c b/src/int-check/main.c new file mode 100644 index 0000000..60d9d6b --- /dev/null +++ b/src/int-check/main.c @@ -0,0 +1,70 @@ +//Write a program to compare two file. +#include +#include + +int main(int argc, char *argv[]) +{ + FILE *fp1 ; + FILE *fp2 ; + + int cnt1 = 0; + int cnt2 = 0; + int flg = 0; + + if( argc < 3 ) + { + printf("Insufficient Arguments!!!\n"); + printf("Please use \"program-name file-name1 file-name2\" format.\n"); + return -1; + } + + fp1 = fopen(argv[1],"r"); + if( fp1 == NULL ) + { + printf("\n%s File can not be opened : \n",argv[1]); + return -1; + } + + // move file pointer to end and get total number of bytes + fseek(fp1,0,SEEK_END); + cnt1 = ftell(fp1); + + fp2 = fopen(argv[2],"r"); + if( fp2 == NULL ) + { + printf("\n%s File can not be opened : \n",argv[2]); + return -1; + } + + // move file pointer to end and get total number of bytes + fseek(fp2,0,SEEK_END); + cnt2 = ftell(fp2); + + fseek(fp1,0,SEEK_SET); + fseek(fp2,0,SEEK_SET); + + // check for the total number of bytes + if( cnt1 != cnt2 ){ + return 1; + } + else + { + while( ! feof(fp1) ) + { + if( fgetc(fp1) != fgetc(fp2) ) + { + flg = 1; + break; + } + } + + if( flg ) return 1; + else return 0; + } + + fclose(fp1); + fclose(fp2); + + return 0; +} +