diff options
27 files changed, 382 insertions, 276 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..b27cf80 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +### Overview +keepalive is a python script that keeps the system logged into an http proxy using kerberos. Only kerberos-joined systems (e.g., AD domain computers) can use this package. +For a description of the package itself, view <a href="usr/share/keepalive/docs/README.txt" target="_blank">usr/share/keepalive/docs/README.txt</a>. + +### Building +The recommended way to build an rpm is: + + mkdir -p ~/rpmbuild/SOURCES ~/rpmbuild/RPMS ~/rpmbuild/SPECS ~/rpmbuild/BUILD ~/rpmbuild/BUILDROOT + mkdir -p ~/rpmbuild/SOURCES/keepalive-1.0-7/ + cd ~/rpmbuild/SOURCES/bgscripts-1.0-7 + git init + git pull https://github.com/bgstack15/keepalive + usr/share/bgscripts/inc/pack rpm + diff --git a/etc/keepalive/docs/debian/postinst b/etc/keepalive/docs/debian/postinst deleted file mode 100755 index 4c3092b..0000000 --- a/etc/keepalive/docs/debian/postinst +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -systemctl daemon-reload 1>/dev/null 2>&1 -systemctl enable keepalive 1>/dev/null 2>&1 -systemctl start keepalive 1>/dev/null 2>&1 diff --git a/etc/keepalive/docs/debian/postrm b/etc/keepalive/docs/debian/postrm deleted file mode 100755 index 2c475d8..0000000 --- a/etc/keepalive/docs/debian/postrm +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -# whether removing an updated package or just removing it entirely, this is a good idea: -systemctl daemon-reload 1>/dev/null 2>&1 diff --git a/etc/keepalive/docs/debian/preinst b/etc/keepalive/docs/debian/preinst deleted file mode 100755 index 75ff571..0000000 --- a/etc/keepalive/docs/debian/preinst +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -#https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html -thisservice=keepalive.service - -case "${1}" in - upgrade) - # This preinst is being run before an upgrade. - # $2 is old-version-number - systemctl stop keepalive.service 1>/dev/null 2>&1 - ;; - install) - # Brand new installation of the package. - [ ] - ;; -esac - -exit 0 diff --git a/etc/keepalive/docs/debian/prerm b/etc/keepalive/docs/debian/prerm deleted file mode 100755 index 99a4f6a..0000000 --- a/etc/keepalive/docs/debian/prerm +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -thisservice=keepalive.service - -case "${1}" in - upgrade) - # This prerm upgrade is running because a newer version of this package is being installed. - # $2 is new-version-number - [ ] - ;; - remove) - # No new package being installed. Just remove it. - systemctl stop "${thisservice}" 1>/dev/null 2>&1 - systemctl disable "${thisservice}" 1>/dev/null 2>&1 - ;; -esac - -exit 0 diff --git a/etc/keepalive/docs/keepalive.spec b/etc/keepalive/docs/keepalive.spec deleted file mode 100644 index 0df5e3a..0000000 --- a/etc/keepalive/docs/keepalive.spec +++ /dev/null @@ -1,82 +0,0 @@ -# -# spec file for keepalive compiled by hand -Summary: Keepalive -Name: keepalive -Version: 1.0 -Release: 6 -License: CC BY-SA 4.0 -Group: Applications/System -Source: keepalive.tgz -URL: bgstack15@gmail.com -#Distribution: -#Vendor: -Packager: Bgstack15 <bgstack15@gmail.com> -Buildarch: noarch -PreReq: bgscripts >= 1.1-17 -PreReq: python34 - -%description -Keepalive uses a system kerbors ticket (generating one if necessary) to stay authenticated to the http proxy. -The user defines http_proxy and https_proxy. Keepalive assumes the system joined to an AD domain. - -%prep -%setup - -%build - -%install -rsync -a . %{buildroot}/ - -%clean -rm -rf ${buildroot} - -%pre -if [ $1 = "1" ]; -then - # first version being installed - find /tmp/foo >/dev/null 2>&1 -else - # not the first version being installed - systemctl stop keepalive >/dev/null 2>&1 -fi -exit 0 - -%post -systemctl enable keepalive -systemctl start keepalive - -%preun -if [[ "$1" = "0" ]]; -then - # last version of package is being erased - systemctl disable keepalive >/dev/null 2>&1 - systemctl stop keepalive >/dev/null 2>&1 -else - # not last version being erased - find /tmp/foo >/dev/null 2>&1 -fi -exit 0 - -%files -/etc/logrotate.d/keepalive -%config /etc/rsyslog.d/keepalivelog.conf -%doc %attr(444, -, -) /etc/keepalive/README.txt -%verify(link) /etc/keepalive/bin/keepalive.sh -%verify(link) /etc/keepalive/bin/keepalive -/etc/keepalive/docs/keepalive.spec -/etc/keepalive/docs/debian/postinst -/etc/keepalive/docs/debian/conffiles -/etc/keepalive/docs/debian/md5sums -/etc/keepalive/docs/debian/prerm -/etc/keepalive/docs/debian/postrm -/etc/keepalive/docs/debian/control -/etc/keepalive/docs/debian/preinst -%config /etc/keepalive/keepalive.conf -/etc/keepalive/inc/scrub.py -/etc/keepalive/inc/scrub.pyc -/etc/keepalive/inc/scrub.pyo -/etc/keepalive/inc/localize_git.sh -%doc %attr(444, -, -) /etc/keepalive/inc/scrub.txt -%doc %attr(444, -, -) /etc/keepalive/packaging.txt -/usr/lib/systemd/system/keepalive.service -%verify(link) /usr/bin/keepalive diff --git a/etc/keepalive/inc/scrub.py b/etc/keepalive/inc/scrub.py deleted file mode 100755 index afa81a1..0000000 --- a/etc/keepalive/inc/scrub.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/env python3 -# Filename: scrub.py -# Location: Various -# Author: bgstack15@gmail.com -# Startdate: 2016-09-28 -# Title: Script that Simultaneously Copies and Scrubs a Directory -# Purpose: Prepare projects for publication by removing private information like usernames and hostnames -# Package: Various -# History: -# 2016-10-03 working on batch rename files -# 2016-10-20 added not ".tgz" in source.name -# 2016-10-27 Fixed error when trying chmod on a symlink -# Usage: -# Store this file with any package that gets published. Adjust scrub.txt in local directory. -# # First line: source directory Second line: target directory. WILL BE OVERWRITTEN! -# /etc/ansible -# /home/bjones/ansible.clean -# # Rest of the lines are "OLD WORD" "NEW WORD" -# bjones bgstack15 -# rsmith rmstack15 -# Reference: -# http://stackoverflow.com/questions/79968/split-a-string-by-spaces-preserving-quoted-substrings-in-python/524796#524796 -# http://stackoverflow.com/questions/6706953/python-using-subprocess-to-call-sed#6707003 -# http://stackoverflow.com/questions/6584871/remove-last-character-if-its-a-backslash/6584893#6584893 -# http://stackoverflow.com/questions/2212643/python-recursive-folder-read/2212728#2212728 -# parallel lists: http://stackoverflow.com/questions/1663807/how-can-i-iterate-through-two-lists-in-parallel-in-python -# file renames http://stackoverflow.com/questions/225735/batch-renaming-of-files-in-a-directory/7917798#7917798 -# Improve: -# Add option to specify scrub file -# Add exclude option to scrub file, such as .git and so on -# Accept CLI options like source, destination, even exclusions? -# Add flag for performing file renames as well, or file renames only -import re, shlex, os, sys, shutil -from pathlib import Path - -# scrubpy version -scrubpyversion = "2016-10-27a" - -# Define functions - -def removeComments(string): - #string = re.sub(re.compile("/\*.*?\*/",re.DOTALL ) ,"", string) - #string = re.sub(re.compile("//.*?\n" ) ,"" ,string) - pattern = r"(\".*?\"|\'.*?\')|(/\*.*?\*/|(//|#)[^\r\n]*$)" - regex = re.compile(pattern, re.MULTILINE|re.DOTALL) - def _replacer(match): - if match.group(2) is not None: - return "" - else: - return match.group(1) - return regex.sub(_replacer, string) - -# Main code -stringfile = open('scrub.txt','r') -count=0 -thisdir="" -newdir="" -oldstrings=[] -newstrings=[] - -while True: - x = stringfile.readline().rstrip() - count += 1 - if not x: break - x = removeComments(x) - #print("x=" + x) - y = shlex.split (x) - if len(y) >= 1: - if thisdir == "": - thisdir = y[0] - elif newdir == "": - newdir = y[0] - if len(y) >= 2: - #print("y[0]=" + y[0] + "\t and y[1]=" + y[1]) - oldstrings.append(y[0]) - newstrings.append(y[1]) - -# After the file is done -stringfile.close() -#newdir = thisdir.rstrip('\/') + ".scrubbed/" - -if False: - print("\nthisdir=" + thisdir) - print("newdir=" + newdir + '\n') - print("oldstrings are:") - print(oldstrings) - print("newstrings are:") - print(newstrings) - -# Clean scrubbed directory -try: - shutil.rmtree(newdir) -except: - foo=1 - -shutil.copytree(thisdir,newdir,symlinks=True) - -# Execute substitutions -for rootfolder, subdirs, files in os.walk(thisdir): - for filename in files: - sourcepath = os.path.join(rootfolder, filename) - with open( sourcepath, "r" ) as source: - if not ".swp" in source.name and not ".git" in source.name and not ".tgz" in source.name: - destdir = rootfolder.replace(thisdir.rstrip('\/'),newdir.rstrip('\/')) - destfile = os.path.join(destdir, filename) - #print("sourcefile=" + source.name) - #print("destfile=" + destfile + '\n') - if not os.path.islink( destfile ): - with open( destfile, "w") as target: - data = source.read() - for oldword, newword in zip(oldstrings, newstrings): - data = data.replace(oldword,newword) - changed = data - target.write(changed) - -# Execute file renames -# Used "file renames" reference, as well as the structure of directory traversal used earlier, which was from a different source. -for rootfolder, subdirs, files in os.walk(newdir): - for filename in files: - oldpath = os.path.join(rootfolder, filename) - for oldword, newword in zip(oldstrings, newstrings): - if oldword in oldpath: - #print("oldword=" + oldword + "\toldpath=" + oldpath) - os.rename(oldpath, oldpath.replace(oldword,newword)) diff --git a/etc/keepalive/inc/scrub.txt b/etc/keepalive/inc/scrub.txt deleted file mode 100644 index a27aff1..0000000 --- a/etc/keepalive/inc/scrub.txt +++ /dev/null @@ -1,14 +0,0 @@ -# First line: source directory Second line: target directory. WILL BE OVERWRITTEN! -/home/bgstack15/rpmbuild/SOURCES/keepalive-1.0-6 -/home/work/keepalive.clean -# rest of the lines are "OLD WORD" "NEW WORD" -BGSTACK15 BGSTACK15 -Bgstack15 Bgstack15 -bgstack15 bgstack15 -example example -EXAMPLE EXAMPLE -".com" ".com" -"203.0." "203.0." -one one -Alice Alice -User1 User1 diff --git a/usr/bin/keepalive b/usr/bin/keepalive index cd303b0..41bdd43 120000 --- a/usr/bin/keepalive +++ b/usr/bin/keepalive @@ -1 +1 @@ -/etc/keepalive/bin/keepalive
\ No newline at end of file +../share/keepalive/keepalive
\ No newline at end of file diff --git a/usr/lib/systemd/system/keepalive.service b/usr/lib/systemd/system/keepalive.service index 117dbd5..8b31775 100644 --- a/usr/lib/systemd/system/keepalive.service +++ b/usr/lib/systemd/system/keepalive.service @@ -14,11 +14,11 @@ ConditionPathExists=/usr/bin/keepalive [Service] Type=simple User=root -ExecStart=/etc/keepalive/bin/keepalive +ExecStart=/usr/share/keepalive/keepalive Restart=on-abort StandardOutput=syslog StandardError=syslog -ExecStopPost=/etc/keepalive/bin/keepalive --clean +ExecStopPost=/usr/share/keepalive/keepalive --clean [Install] WantedBy=multi-user.target diff --git a/etc/keepalive/README.txt b/usr/share/keepalive/docs/README.txt index 84479c7..416c5d9 100644 --- a/etc/keepalive/README.txt +++ b/usr/share/keepalive/docs/README.txt @@ -1,5 +1,5 @@ File: etc/keepalive/README.txt -Package: keepalive 1.0-6 +Package: keepalive 1.0-7 Author: bgstack15@gmail.com Startdate: 2016-06-07 Title: Readme file for keepalive @@ -14,6 +14,8 @@ Document: Below this line To use the keepalive program, start the service. systemctl start keepalive.service +### REFERENCE + ### CHANGELOG keepalive 1.0-4 2016-06-07 Changed packaging so bgscripts is a prerequisite, not a corequisite package so framework.sh exists before keepalive service is started for the first time. @@ -26,5 +28,3 @@ Rewrote the application in python3 2016-10-27 keepalive 1.0-6 Added scrub.py subpackage Modified to be suitable for sharing on github - -### REFERENCE diff --git a/etc/keepalive/docs/debian/conffiles b/usr/share/keepalive/docs/debian/conffiles index 8dafbff..8dafbff 100644 --- a/etc/keepalive/docs/debian/conffiles +++ b/usr/share/keepalive/docs/debian/conffiles diff --git a/etc/keepalive/docs/debian/control b/usr/share/keepalive/docs/debian/control index 8d42833..e79a841 100644 --- a/etc/keepalive/docs/debian/control +++ b/usr/share/keepalive/docs/debian/control @@ -1,5 +1,5 @@ Package: keepalive -Version: 1.0-6 +Version: 1.0-7 Architecture: all Essential: no Priority: extra @@ -9,5 +9,6 @@ Installed-Size: 350 Homepage: https://bgstack15.wordpress.com/ Source: keepalive.tgz Pre-Depends: bgscripts (>= 1.1-17), sssd, python3 +Depends: curl Description: Keepalive uses a system kerberos ticket (generating one if necessary) to stay authenticated to the http proxy. The user defines http_proxy and https_proxy. Keepalive assumes the system joined to an AD domain. diff --git a/etc/keepalive/docs/debian/md5sums b/usr/share/keepalive/docs/debian/md5sums index 3307807..3307807 100644 --- a/etc/keepalive/docs/debian/md5sums +++ b/usr/share/keepalive/docs/debian/md5sums diff --git a/usr/share/keepalive/docs/debian/postinst b/usr/share/keepalive/docs/debian/postinst new file mode 100755 index 0000000..eae6cd5 --- /dev/null +++ b/usr/share/keepalive/docs/debian/postinst @@ -0,0 +1,9 @@ +#!/bin/sh +# deb postinst 2017-01-26 +thisservice=keepalive.service +{ +systemctl daemon-reload +systemctl enable ${thisservice} +systemctl start ${thisservice} +} 1>/dev/null 2>&1 +exit 0 diff --git a/usr/share/keepalive/docs/debian/postrm b/usr/share/keepalive/docs/debian/postrm new file mode 100755 index 0000000..f35ae34 --- /dev/null +++ b/usr/share/keepalive/docs/debian/postrm @@ -0,0 +1,3 @@ +# deb postrm 2017-01-26 +systemctl daemon-reload 1>/dev/null 2>&1 +exit 0 diff --git a/usr/share/keepalive/docs/debian/preinst b/usr/share/keepalive/docs/debian/preinst new file mode 100755 index 0000000..afa9350 --- /dev/null +++ b/usr/share/keepalive/docs/debian/preinst @@ -0,0 +1,17 @@ +#!/bin/sh +# deb pre 2017-01-26 +#https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html +thisservice=keepalive.service +{ +case "${1}" in + upgrade) + # Upgrade. $2 is old-version-number. + systemctl stop ${thiservice} + ;; + install) + # New install. + : + ;; +esac +} 1>/dev/null 2>&1 +exit 0 diff --git a/usr/share/keepalive/docs/debian/prerm b/usr/share/keepalive/docs/debian/prerm new file mode 100755 index 0000000..84e2bbd --- /dev/null +++ b/usr/share/keepalive/docs/debian/prerm @@ -0,0 +1,16 @@ +# deb prerm 2017-01-26 +thisservice=keepalive.service +{ +case "${1}" in + remove) + # Final removal. + systemctl stop "${thisservice}" + systemctl disable "${thisservice}" + ;; + upgrade) + # Upgrade. $2 is new-version-number + : + ;; +esac +} 1>/dev/null 2>&1 +exit 0 diff --git a/usr/share/keepalive/docs/files-for-versioning.txt b/usr/share/keepalive/docs/files-for-versioning.txt new file mode 100644 index 0000000..4494135 --- /dev/null +++ b/usr/share/keepalive/docs/files-for-versioning.txt @@ -0,0 +1,6 @@ +inc/localize_git.sh +inc/scrub.txt +docs/README.txt +docs/packaging.txt +docs/keepalive.spec +docs/debian/control diff --git a/usr/share/keepalive/docs/keepalive.spec b/usr/share/keepalive/docs/keepalive.spec new file mode 100644 index 0000000..764bcc8 --- /dev/null +++ b/usr/share/keepalive/docs/keepalive.spec @@ -0,0 +1,118 @@ +# +# spec file for keepalive compiled by hand +Summary: Keepalive keeps you logged in to an http proxy via kerberos tickets +Name: keepalive +Version: 1.0 +Release: 7 +License: CC BY-SA 4.0 +Group: Applications/System +Source: keepalive.tgz +URL: https://bgstack15.wordpress.com/ +#Distribution: +#Vendor: +Packager: Bgstack15 <bgstack15@gmail.com> +Buildarch: noarch +Requires(pre): bgscripts-core >= 1.1-31 +Requires(pre): python34 +Requires: curl + +%description +Keepalive uses a system kerberos ticket (generating one if necessary) to stay authenticated to the http proxy. +The user defines http_proxy and https_proxy. Keepalive assumes the system joined to an AD domain. + +%prep +%setup + +%build + +%install +rsync -a . %{buildroot}/ + +%clean +rm -rf ${buildroot} + +%pre +# rpm pre 2017-01-26 +thisservice=%{name}.service +{ +case "${1}" in + 2) + # Upgrade. + systemctl stop ${thisservice} + ;; + 1) + # New install. + : + ;; +esac +} 1>/dev/null 2>&1 +exit 0 + +%post +# rpm post 2017-01-26 +thisservice=%{name}.service +{ +systemctl daemon-reload +systemctl enable ${thisservice} +systemctl start ${thisservice} +} 1>/dev/null 2>&1 +exit 0 + +%preun +# rpm preun 2017-01-26 +thisservice=%{name}.service +{ +case "${1}" in + 0) + # Final removal. + systemctl stop ${thisservice} + systemctl disable ${thisservice} + ;; + 1) + # Upgrade. + : + ;; +esac +} 1>/dev/null 2>&1 +exit 0 + +%postun +# rpm postun 2017-01-26 +systemctl daemon-reload 1>/dev/null 2>&1 +exit 0 + +%files +%dir /etc/keepalive +%dir /usr/share/keepalive +%dir /usr/share/keepalive/docs +%dir /usr/share/keepalive/docs/debian +%dir /usr/share/keepalive/inc +/etc/logrotate.d/keepalive +%config /etc/rsyslog.d/keepalivelog.conf +%config /etc/keepalive/keepalive.conf +/usr/share/keepalive/keepalive.sh +/usr/share/keepalive/docs/keepalive.spec +/usr/share/keepalive/docs/debian/postinst +/usr/share/keepalive/docs/debian/conffiles +/usr/share/keepalive/docs/debian/md5sums +/usr/share/keepalive/docs/debian/prerm +/usr/share/keepalive/docs/debian/postrm +/usr/share/keepalive/docs/debian/control +/usr/share/keepalive/docs/debian/preinst +%doc %attr(444, -, -) /usr/share/keepalive/docs/README.txt +%doc %attr(444, -, -) /usr/share/keepalive/docs/packaging.txt +%doc %attr(444, -, -) /usr/share/keepalive/docs/files-for-versioning.txt +/usr/share/keepalive/inc/get-files +/usr/share/keepalive/inc/pack +/usr/share/keepalive/inc/localize_git.sh +%doc %attr(444, -, -) /usr/share/keepalive/inc/scrub.txt +/usr/share/keepalive/keepalive +/usr/lib/systemd/system/keepalive.service +%verify(link) /usr/bin/keepalive + +%changelog +* Thu Jan 26 2017 B Stack <bgstack15@gmail.com> 1.0-7 +- Rearranged package to be compliant with FHS 3.0 +- Updated dependency to bgscripts-core +- Added ./pack script +- Added changelog to spec file diff --git a/etc/keepalive/packaging.txt b/usr/share/keepalive/docs/packaging.txt index 77f3b10..7610649 100644 --- a/etc/keepalive/packaging.txt +++ b/usr/share/keepalive/docs/packaging.txt @@ -12,7 +12,7 @@ Document: Below this line ### PACKAGING for rhel/centos package=keepalive -version=1.0-6 +version=1.0-7 shortversion=1.0 rpmbuilddir=~/rpmbuild/ packagespecfile="${package}-${version}/etc/${package}/docs/${package}.spec" @@ -31,7 +31,7 @@ rpmbuild -bb "${rpmbuilddir}"/SPECS/"${package}".spec ### PACKAGING for debian # You need package dpkg-dev to build packages. package=keepalive -version=1.0-6 +version=1.0-7 packagedebfilesdir="${package}-${version}/etc/keepalive/docs/debian" cd ~/deb/"${package}-${version}" find . -type f ! -regex '.*.hg.*' ! -regex '.*?debian-binary.*' ! -regex '.*?DEBIAN.*' ! -regex '.*?.swp' ! -regex '.*\.git.*' -printf '%P ' | xargs md5sum > DEBIAN/md5sums @@ -48,6 +48,6 @@ mv ~/deb/"${package}-${version}.a" ~/deb/"${package}-${version}" ### PACKAGING in a master.tgz cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES package=keepalive -version=1.0-6 +version=1.0-7 rm -rf ./"${package}-${version}".master.tgz tar -zcf "${package}-${version}".master.tgz "${package}-${version}"/ diff --git a/usr/share/keepalive/inc/get-files b/usr/share/keepalive/inc/get-files new file mode 100755 index 0000000..ab75e63 --- /dev/null +++ b/usr/share/keepalive/inc/get-files @@ -0,0 +1,45 @@ +#!/bin/sh +# File: get-files +case "${1}" in + rpm) + +### for rpm +find * -type d \ + \( \ + -regex 'usr\/share\/keepalive.*' -o \ + -regex '.*\/keepalive$' \ + \) \ + | sed -e 's/^/%dir \//;' +find * -mindepth 1 ! -type d ! -regex '.*?.swp' \ + ! -regex '.*?DEBIAN.*?' \ + | sed -e ' +s/^/\//; +s/\(.*\.txt\)/%doc %attr(444, -, -) \1/; +s/\(.*\.conf\)/%config \1/; +s/\(.*bin.*\)/%verify(link) \1/; +s/\(.*\)\.py$/\1\.py\n\1\.pyc\n\1\.pyo/; +' + + ;; + deb) + +### for deb +# will be redirected to md5sum +# WORKHERE: this is the bgscripts one +find . -mindepth 1 \ + ! -type d \ + ! -regex '.*.hg.*' ! -regex '.*?debian-binary.*' \ + ! -regex '.*?DEBIAN.*' ! -regex '.*?.swp' ! -regex '.*\.git.*' \ + \( \ + -regex '.*rdp.*' -o \ + -regex '.*get-files$' -o \ + -regex '.*icons.*' \ + \) \ + -printf '%P ' + + ;; + *) + echo "FATAL ERROR: check ./pack or get-files. Please use [ rpm | deb ] option. Aborted." 1>&2 + exit 1 + ;; +esac diff --git a/etc/keepalive/inc/localize_git.sh b/usr/share/keepalive/inc/localize_git.sh index ade84d4..d4f1ae0 100755 --- a/etc/keepalive/inc/localize_git.sh +++ b/usr/share/keepalive/inc/localize_git.sh @@ -1,2 +1,2 @@ #!/bin/sh -\cp -pRf /home/work/keepalive.clean/.git /home/bgstack15/rpmbuild/SOURCES/keepalive-1.0-6/ +\cp -pRf /home/work/keepalive.clean/.git /home/bgstack15/rpmbuild/SOURCES/keepalive-1.0-7/ diff --git a/usr/share/keepalive/inc/pack b/usr/share/keepalive/inc/pack new file mode 100755 index 0000000..448a98c --- /dev/null +++ b/usr/share/keepalive/inc/pack @@ -0,0 +1,118 @@ +#!/bin/bash + +# DETERMINE LOCATION OF FRAMEWORK +while read flocation; do if test -x ${flocation} && test "$( ${flocation} --fcheck )" -ge 20170111; then frameworkscript="${flocation}"; break; fi; done <<EOFLOCATIONS +/usr/share/bgscripts/framework.sh +../framework.sh +usr/share/bgscripts/framework.sh +~/rpmbuild/SOURCES/bgscripts-1.1-31/usr/share/bgscripts/framework.sh +EOFLOCATIONS +test -z "${frameworkscript}" && echo "$0: framework not found. Aborted." 1>&2 && exit 4 + +. ${frameworkscript} || echo "$0: framework did not run properly. Continuing..." 1>&2 + +type=""; + +case "${thisflavor}" in + redhat|rhel|centos|fedora|korora) type=rpm;; + debian|ubuntu) type=dpkg;; + *) type=targz;; +esac + +echo " $@ " | grep -qiE -- "help|usage|\s-h\s|\s-\?" 1>/dev/null 2>&1 && { + # display help and exit + less -F <<EOF +pack utility version 2017-01-26a-keepalive +usage: pack [ rpm | deb | tar | scrub ] [ --debug | -d {0-10} ] +Provides a single command for building a package. This script is customized to each package. +optional arguments: + [ rpm | deb | tar | scrub ] Build that type of package. Scrub calls the scrub.py script. + The default depends on the local os flavor. This system is "${thisflavor}" + [ --debug {0-10} | -d {0-10} ] Display package type to build and exit. Debuglev not implemented here. +EOF +exit 1 +} + +# Derive package name and version number, for my simple package versions only. +fullname="$( pwd | sed -e 's/.*\(SOURCES\|deb\)\///;s/\/.*//;' )" +version="$( echo "${fullname}" | grep -oiE -- "-[0-9]{0,3}\.[0-9a-zA-Z]{0,5}-[0-9]{0,4}" | sed -e 's/^-//;' )" +shortversion="$( echo "${version}" | sed -e 's/-.*//;' )" +package="$( echo "${fullname}" | sed -e "s/-${version}//;" )" + +echo " $@ " | grep -qiE -- "rpm|rhel|redhat|centos|fedora|korora" 1>/dev/null 2>&1 && type=rpm +echo " $@ " | grep -qiE -- "debian|ubuntu|deb\s|dpkg" 1>/dev/null 2>&1 && type=dpkg +echo " $@ " | grep -qiE -- "tar|tgz|gz" 1>/dev/null 2>&1 && type=targz +echo " $@ " | grep -qiE -- "scrub" 1>/dev/null 2>&1 && type=scrub + +# Display information +echo "packaging ${package}-${version} as ${type}" +echo " $@ " | grep -qiE -- "debug|\s-d[ 0-9]{0,3}\s" 1>/dev/null 2>&1 && exit 0 + +case "${type}" in + rpm) + +########## PACKAGING for rhel/centos +# if you copy-paste this, be sure to define package, version, shortversion +rpmbuilddir=~/rpmbuild/ +packagespecfile="${package}-${version}/usr/share/${package}/docs/${package}.spec" +sed -n -e '1,/^\%files$/p;' "${rpmbuilddir}/SOURCES/${packagespecfile}" > "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" # removes files and changelog +cd "${rpmbuilddir}/SOURCES/${package}-${version}" +"${rpmbuilddir}/SOURCES/${package}-${version}/usr/share/${package}/inc/get-files" rpm >> "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" +{ printf '\n'; sed -n -e '/^\%changelog/,$p' "${rpmbuilddir}/SOURCES/${packagespecfile}"; } >> "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" +mv -f "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" "${rpmbuilddir}/SOURCES/${packagespecfile}" +rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}"; cp -prf "${rpmbuilddir}/SOURCES/${package}-${version}" "${rpmbuilddir}/SOURCES/${package}-${shortversion}" +rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}/DEBIAN" +cd "${rpmbuilddir}/SOURCES" +rm -rf "${package}.tgz"; tar -zc --exclude='.git' --exclude='README.md' -f "${package}.tgz" "${package}-${shortversion}" +cp -p "${rpmbuilddir}/SOURCES/${packagespecfile}" "${rpmbuilddir}/SPECS" +mkdir -p "${rpmbuilddir}/RPMS/noarch"; cd "${rpmbuilddir}/RPMS/noarch" +rpmbuild -bb "${rpmbuilddir}/SPECS/${package}.spec" +rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}/" "${rpmbuilddir}/SOURCES/${package}.tgz" + + ;; + dpkg) + +########## PACKAGING for ubuntu +# You need package dpkg-dev to build packages. +# if you copy-paste this, be sure to define package, version +debdir=~/deb +debiandirmain="${package}-${version}/usr/share/${package}/docs/debian-${package}" +cd "${debdir}/${package}-${version}/usr/bin" +for word in beep bup fl lecho newscript plecho rdp send treesize; do ln -sf ../share/bgscripts/${word}.sh ${word}; done +for word in dli updateval; do ln -sf ../share/bgscripts/${word}.py ${word}; done +ln -sf ../share/bgscripts/bgscripts.bashrc bp +cd "${debdir}/${package}-${version}" +"${debdir}/${package}-${version}/usr/share/${package}/inc/get-files" deb | xargs md5sum > "${debdir}/${debiandirmain}/md5sums" +cd ~/deb +mv "${debdir}/${package}-${version}/.git" "${debdir}/.git$$" + +# main +rm -rf "${debdir}/${package}-${version}/DEBIAN/" 2>/dev/null; mkdir -p "${debdir}/${package}-${version}/DEBIAN/" +cp -pf "${debdir}/${debiandirmain}"/* "${debdir}/${package}-${version}/DEBIAN/" +fakeroot dpkg-deb -b "${debdir}/${package}-${version}" + +mv "${debdir}/.git$$" "${debdir}/${package}-${version}/.git" + + ;; + targz) + +########## PACKAGING in a master.tgz +# if you copy-paste this, be sure to define package, version +cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES +rm -rf ./"${package}-${version}".master.tgz +tar -zcf "${package}-${version}".master.tgz "${package}-${version}"/ + + ;; + scrub) + +########## SCRUB for publication +# if you copy-paste this, be sure to define package, version +cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES +cd "$( find . -name "*scrub.txt" | grep -iE "${package}-${version}\/" | xargs dirname )" +/usr/share/bgscripts/scrub.py + + ;; + unknown) + echo "error: check $0 for errors on type ${type}." 1>&2 + ;; +esac diff --git a/usr/share/keepalive/inc/scrub.txt b/usr/share/keepalive/inc/scrub.txt new file mode 100644 index 0000000..534bdf8 --- /dev/null +++ b/usr/share/keepalive/inc/scrub.txt @@ -0,0 +1,22 @@ +# for scrubpyversion 2016-11-16a or newer +source /home/bgstack15/rpmbuild/SOURCES/keepalive-1.0-7 +target /home/work/keepalive.clean +ignore "tgz png gif jpg pyc pyo git swp ico" +# rest of the lines are "OLD WORD" "NEW WORD" +BGSTACK15 BGSTACK15 +Bgstack15 Bgstack15 +bgstack15 bgstack15 +Bname Bname +bname bname +Stack15 Stack15 +stack15 stack15 +EXAMPLE EXAMPLE +example example +".com" ".com" +"203.0." "203.0." +one one +Alice Alice +User1 User1 +SMITH123 SMITH123 +Smith123 Smith123 +smith123 smith123 diff --git a/etc/keepalive/bin/keepalive b/usr/share/keepalive/keepalive index b603135..0191691 100755 --- a/etc/keepalive/bin/keepalive +++ b/usr/share/keepalive/keepalive @@ -5,6 +5,7 @@ # Title: Keepalive Script in Python # Purpose: To perform keepalive functionality in python. This is mostly a learning exercise in python. # History: 2016-07-21 Basic, hard-coded functionality working +# 2017-01-26 moved main package contents to /usr/share/keepalive to be FHS 3.0-compliant # Usage: # Reference: # keepalive-1.0-4 /etc/keepalive/bin/keepalive (shell script) @@ -28,7 +29,7 @@ import signal, atexit import argparse, configparser from collections import OrderedDict -keepaliveversion="2016-07-22b" +keepaliveversion="2017-01-26a" class MultiOrderedDict(OrderedDict): def __setitem__(self, key, value): diff --git a/etc/keepalive/bin/keepalive.sh b/usr/share/keepalive/keepalive.sh index d0a7714..d0a7714 100644 --- a/etc/keepalive/bin/keepalive.sh +++ b/usr/share/keepalive/keepalive.sh |