mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-11-17 07:48:18 +01:00
added support checksum for sbo repo
This commit is contained in:
parent
18c6d8d7f1
commit
e2222fb7d7
5 changed files with 87 additions and 10 deletions
32
slpkg/checksum.py
Executable file
32
slpkg/checksum.py
Executable file
|
@ -0,0 +1,32 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# checksum.py file is part of slpkg.
|
||||||
|
|
||||||
|
# Copyright 2014 Dimitris Zlatanidis <d.zlatanidis@gmail.com>
|
||||||
|
# All rights reserved.
|
||||||
|
|
||||||
|
# Utility for easy management packages in Slackware
|
||||||
|
|
||||||
|
# https://github.com/dslackw/slpkg
|
||||||
|
|
||||||
|
# Slpkg 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 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
def md5sum(source):
|
||||||
|
'''
|
||||||
|
Calculate the md5 checksum
|
||||||
|
'''
|
||||||
|
with open(source) as file_to_check:
|
||||||
|
data = file_to_check.read()
|
||||||
|
return hashlib.md5(data).hexdigest()
|
|
@ -76,7 +76,7 @@ def s_user(user):
|
||||||
|
|
||||||
def build_FAILED(sbo_url, prgnam):
|
def build_FAILED(sbo_url, prgnam):
|
||||||
print("\n{0}<-- FAILED{1} to build the package {2}".format(colors.RED, colors.ENDC, prgnam))
|
print("\n{0}<-- FAILED{1} to build the package {2}".format(colors.RED, colors.ENDC, prgnam))
|
||||||
print("See log file in slpkg_Build directory or read README file:")
|
print("See log file in /var/log/slpkg/logs directory or read README file:")
|
||||||
print("{0}{1}\n".format(sbo_url, "README"))
|
print("{0}{1}\n".format(sbo_url, "README"))
|
||||||
|
|
||||||
def template(max):
|
def template(max):
|
||||||
|
|
|
@ -28,8 +28,12 @@ import shutil
|
||||||
import tarfile
|
import tarfile
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from messages import pkg_not_found
|
from colors import colors
|
||||||
|
from checksum import md5sum
|
||||||
from __metadata__ import log_path
|
from __metadata__ import log_path
|
||||||
|
from messages import pkg_not_found, template
|
||||||
|
|
||||||
|
from sbo.greps import sbo_checksum_pkg
|
||||||
|
|
||||||
def build_package(script, sources, path):
|
def build_package(script, sources, path):
|
||||||
'''
|
'''
|
||||||
|
@ -44,7 +48,7 @@ def build_package(script, sources, path):
|
||||||
if not os.path.exists(logs):
|
if not os.path.exists(logs):
|
||||||
os.mkdir(logs)
|
os.mkdir(logs)
|
||||||
log_date = time.strftime("%c")
|
log_date = time.strftime("%c")
|
||||||
template = ("#" * 79 + "\n\n")
|
log_line = ("#" * 79 + "\n\n")
|
||||||
try:
|
try:
|
||||||
if os.path.isfile(logs + log_file):
|
if os.path.isfile(logs + log_file):
|
||||||
os.remove(logs + log_file)
|
os.remove(logs + log_file)
|
||||||
|
@ -52,20 +56,41 @@ def build_package(script, sources, path):
|
||||||
tar.extractall()
|
tar.extractall()
|
||||||
tar.close()
|
tar.close()
|
||||||
for src in sources:
|
for src in sources:
|
||||||
|
sbo_md5 = sbo_checksum_pkg(prgnam)
|
||||||
|
md5 = md5sum(src)
|
||||||
|
if sbo_md5 != md5:
|
||||||
|
template(78)
|
||||||
|
print("| MD5SUM check for {0} [ {1}FAILED{2} ]".format(
|
||||||
|
src, colors.RED, colors.ENDC))
|
||||||
|
template(78)
|
||||||
|
print("| Expected: {0}".format(md5))
|
||||||
|
print("| Found: {0}".format(sbo_md5))
|
||||||
|
template(78)
|
||||||
|
read = raw_input("\nDo you want to continue [Y/n]? ")
|
||||||
|
if read == "Y" or read == "y":
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
sys.exit()
|
||||||
|
else:
|
||||||
|
template(78)
|
||||||
|
print("| MD5SUM check for {0} [ {1}PASS{2} ]".format(
|
||||||
|
src, colors.GREEN, colors.ENDC))
|
||||||
|
template(78)
|
||||||
|
print # new line after pass checksum
|
||||||
shutil.copy2(src, prgnam)
|
shutil.copy2(src, prgnam)
|
||||||
os.chdir(path + prgnam)
|
os.chdir(path + prgnam)
|
||||||
subprocess.call("chmod +x {0}.SlackBuild".format(prgnam), shell=True)
|
subprocess.call("chmod +x {0}.SlackBuild".format(prgnam), shell=True)
|
||||||
with open(logs + log_file, "w") as log: # write headers to log file
|
with open(logs + log_file, "w") as log: # write headers to log file
|
||||||
log.write(template)
|
log.write(log_line)
|
||||||
log.write("File : " + log_file + "\n")
|
log.write("File : " + log_file + "\n")
|
||||||
log.write("Path : " + logs + "\n")
|
log.write("Path : " + logs + "\n")
|
||||||
log.write("Date : " + log_date + "\n\n")
|
log.write("Date : " + log_date + "\n\n")
|
||||||
log.write(template)
|
log.write(log_line)
|
||||||
log.close()
|
log.close()
|
||||||
with open(logs + log_file, "a") as log: # append END tag to a log file
|
with open(logs + log_file, "a") as log: # append END tag to a log file
|
||||||
log.write(template)
|
log.write(log_line)
|
||||||
log.write(" " * 38 + "E N D\n\n")
|
log.write(" " * 38 + "E N D\n\n")
|
||||||
log.write(template)
|
log.write(log_line)
|
||||||
subprocess.Popen("./{0}.SlackBuild 2>&1 | tee -a {1}{2}".format(
|
subprocess.Popen("./{0}.SlackBuild 2>&1 | tee -a {1}{2}".format(
|
||||||
prgnam, logs, log_file), shell=True, stdout=sys.stdout).communicate()
|
prgnam, logs, log_file), shell=True, stdout=sys.stdout).communicate()
|
||||||
log.close()
|
log.close()
|
||||||
|
|
|
@ -78,5 +78,21 @@ def sbo_version_pkg(name):
|
||||||
sbo_name = line[17:].strip()
|
sbo_name = line[17:].strip()
|
||||||
if line.startswith("SLACKBUILD VERSION: "):
|
if line.startswith("SLACKBUILD VERSION: "):
|
||||||
if sbo_name == name:
|
if sbo_name == name:
|
||||||
sbo_url = sbo_search_pkg(name)
|
|
||||||
return line[20:].strip()
|
return line[20:].strip()
|
||||||
|
|
||||||
|
def sbo_checksum_pkg(name):
|
||||||
|
if arch == "x86_64":
|
||||||
|
for line in open(lib_path + "sbo_repo/SLACKBUILDS.TXT", "r"):
|
||||||
|
if arch == "x86_64":
|
||||||
|
if line.startswith("SLACKBUILD NAME: "):
|
||||||
|
sbo_name = line[17:].strip()
|
||||||
|
if line.startswith("SLACKBUILD MD5SUM_x86_64: "):
|
||||||
|
if sbo_name == name:
|
||||||
|
if line[26:].strip():
|
||||||
|
return line[26:].strip()
|
||||||
|
for line in open(lib_path + "sbo_repo/SLACKBUILDS.TXT", "r"):
|
||||||
|
if line.startswith("SLACKBUILD NAME: "):
|
||||||
|
sbo_name = line[17:].strip()
|
||||||
|
if line.startswith("SLACKBUILD MD5SUM: "):
|
||||||
|
if sbo_name == name:
|
||||||
|
return line[19:].strip()
|
||||||
|
|
|
@ -26,6 +26,7 @@ import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from colors import colors
|
from colors import colors
|
||||||
|
from checksum import md5sum
|
||||||
from functions import get_file
|
from functions import get_file
|
||||||
from __metadata__ import tmp, pkg_path, build_path, log_path, sp
|
from __metadata__ import tmp, pkg_path, build_path, log_path, sp
|
||||||
from messages import pkg_not_found, pkg_found, template, build_FAILED
|
from messages import pkg_not_found, pkg_found, template, build_FAILED
|
||||||
|
@ -162,7 +163,7 @@ def sbo_build(name):
|
||||||
print("Total {0} {1}.".format(len(dependencies), msg_ins))
|
print("Total {0} {1}.".format(len(dependencies), msg_ins))
|
||||||
print("{0} {1} will be installed, {2} allready installed and {3} {4}".format(
|
print("{0} {1} will be installed, {2} allready installed and {3} {4}".format(
|
||||||
count_installed, msg_ins, pkg_sum, count_upgraded, msg_upg))
|
count_installed, msg_ins, pkg_sum, count_upgraded, msg_upg))
|
||||||
print("will be upgraded.")
|
print("will be upgraded.\n")
|
||||||
'''
|
'''
|
||||||
Check if package supported by arch
|
Check if package supported by arch
|
||||||
before proceed to install
|
before proceed to install
|
||||||
|
@ -173,7 +174,10 @@ def sbo_build(name):
|
||||||
if item == un:
|
if item == un:
|
||||||
print("\n{0}The package {1}{2}\n".format(colors.RED, item, ENDC))
|
print("\n{0}The package {1}{2}\n".format(colors.RED, item, ENDC))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
read = raw_input("\nDo you want to continue [Y/n]? ")
|
# exit if all packages already installed
|
||||||
|
if pkg_sum == len(dependencies):
|
||||||
|
sys.exit()
|
||||||
|
read = raw_input("Do you want to continue [Y/n]? ")
|
||||||
if read == "Y" or read == "y":
|
if read == "Y" or read == "y":
|
||||||
if not os.path.exists(build_path):
|
if not os.path.exists(build_path):
|
||||||
os.mkdir(build_path)
|
os.mkdir(build_path)
|
||||||
|
|
Loading…
Reference in a new issue