Initial implementation of non-interactive packaging script

This commit is contained in:
2022-09-12 15:21:55 -04:00
parent b27f4cb805
commit 7e29a9ba9e
+165 -148
View File
@@ -1,32 +1,79 @@
#!/usr/bin/env bash
# This script packages sshyp (from source) for various UNIX(-like) environments.
# Dependencies (Arch Linux): dpkg (packaging for Debian/Termux), freebsd-pkg (packaging for FreeBSD)
# Dependencies (Fedora) (can only package for self): rpmdevtools
# Dependencies (Alpine): xz (not part of a basic installation, needed for generic package creation and unpacking for abuild), alpine-sdk (required to build the .apk file from the generated APKBUILD), bash
# NOTE It is recommended to instead use the latest officially packaged and tagged release.
echo -e '\nOptions (please enter the number only):'
echo -e '\nPackage Formats:\n\n1. Haiku\n2. Debian&Ubuntu Linux\n3. Fedora Linux\n4. FreeBSD\n5. Termux\n6. Generic (used for PKGBUILD/APKBUILD)'
echo -e '\nBuild Scripts:\n\n7. Arch Linux (PKGBUILD)\n8. Alpine Linux (APKBUILD)'
echo -e '\nOther:\n\n9. All (generates all distribution packages (excluding Haiku, Fedora, and Alpine, as these must be packaged on their respective distributions) and build scripts)\n'
read -n 1 -r -p "Distribution: " distro
echo -e '\n\nThe value entered in this field will only affect the version reported to the package manager. The latest source is used regardless.\n'
read -r -p "Version number: " version
echo -e '\nThe value entered in this field will only affect the revision number for build scripts.\n'
read -r -p "Revision number: " revision
if [ "$distro" == "7" ] || [ "$distro" == "8" ] || [ "$distro" == "9" ]; then
source='https://github.com/rwinkhart/sshyp/releases/download/v$pkgver/sshyp-$pkgver.tar.xz'
version=$(sed -n '1{p;q}' share/doc/sshyp/changelog | cut -c8-)
if [ -z "$2" ]; then
revision=1
else
revision="$2"
fi
mkdir -p packages
_create_generic() {
echo -e '\npackaging as generic...\n'
mkdir -p output/generictemp/usr/share/{man/man1,bash-completion/completions}
cp -r bin output/generictemp/usr/
ln -s /usr/bin/sshyp.py output/generictemp/usr/bin/sshyp
cp -r share output/generictemp/usr/
cp extra/sshyp-completion.bash output/generictemp/usr/share/bash-completion/completions/sshyp
cp extra/manpage output/generictemp/usr/share/man/man1/sshyp.1
gzip output/generictemp/usr/share/man/man1/sshyp.1
tar -C output/generictemp -cvJf output/sshyp-"$version".tar.xz usr/
rm -rf output/generictemp
sha512="$(sha512sum output/sshyp-"$version".tar.xz | awk '{print $1;}')"
echo -e "\nsha512 sum:\n$sha512"
echo -e "\ngeneric packaging complete\n"
} &&
if [ "$distro" == "1" ]; then
echo -e '\nPackaging for Haiku...\n'
mkdir -p packages/haikutemp/documentation/{man/man1,packages/sshyp}
_create_pkgbuild() {
source='https://github.com/rwinkhart/sshyp/releases/download/v$pkgver/sshyp-$pkgver.tar.xz'
echo -e '\ngenerating PKGBUILD...'
echo "# Maintainer: Randall Winkhart <idgr at tutanota dot com>
pkgname=sshyp
pkgver="$version"
pkgrel="$revision"
pkgdesc='A light-weight, self-hosted, synchronized password manager'
url='https://github.com/rwinkhart/sshyp'
arch=('any')
license=('GPL3')
depends=(python gnupg openssh xclip wl-clipboard)
source=(\""$source"\")
sha512sums=('"$sha512"')
package() {
tar xf sshyp-"\"\$pkgver\"".tar.xz -C "\"\${pkgdir}\""
}
" > output/PKGBUILD
echo -e "\nPKGBUILD generated\n"
} &&
_create_apkbuild() {
echo -e '\ngenerating APKBUILD...'
echo "# Maintainer: Randall Winkhart <idgr@tutanota.com>
pkgname=sshyp
pkgver="$version"
pkgrel="$((revision-1))"
pkgdesc='A light-weight, self-hosted, synchronized password manager'
options=!check
url='https://github.com/rwinkhart/sshyp'
arch='noarch'
license='GPL-3.0-or-later'
depends='python3 gnupg openssh xclip wl-clipboard'
source=\""$source"\"
package() {
mkdir -p "\"\$pkgdir\""
cp -r "\"\$srcdir/usr/"\" "\"\$pkgdir\""
}
sha512sums=\"
"$sha512' 'sshyp-\"\$pkgver\".tar.xz"
\"
" > output/APKBUILD
echo -e "\nAPKBUILD generated\n"
} &&
_create_hpkg() {
echo -e '\npackaging for Haiku...\n'
mkdir -p output/haikutemp/{boot/system/data/bash-completion/completions,documentation/{man/man1,packages/sshyp}}
echo "name sshyp
version "$version"-"$revision"
architecture any
@@ -52,28 +99,29 @@ requires {
urls {
\"https://github.com/rwinkhart/sshyp\"
}
" > packages/haikutemp/.PackageInfo
cp -r bin packages/haikutemp/
sed -i '1 s/.*/#!\/bin\/env\ python3/' packages/haikutemp/bin/sshync.py
sed -i '1 s/.*/#!\/bin\/env\ python3/' packages/haikutemp/bin/sshyp.py
sed -i '1 s/.*/#!\/bin\/env\ python3/' packages/haikutemp/bin/sshypRemote.py
ln -s /bin/sshyp.py packages/haikutemp/bin/sshyp
cp -r share/doc/sshyp/ packages/haikutemp/documentation/packages/
cp -r share/licenses/sshyp/ packages/haikutemp/documentation/packages/
cp extra/manpage packages/haikutemp/documentation/man/man1/sshyp.1
gzip packages/haikutemp/documentation/man/man1/sshyp.1
cd packages/haikutemp
" > output/haikutemp/.PackageInfo
cp -r bin output/haikutemp/
sed -i '1 s/.*/#!\/bin\/env\ python3/' output/haikutemp/bin/sshync.py
sed -i '1 s/.*/#!\/bin\/env\ python3/' output/haikutemp/bin/sshyp.py
sed -i '1 s/.*/#!\/bin\/env\ python3/' output/haikutemp/bin/sshypRemote.py
ln -s /bin/sshyp.py output/haikutemp/bin/sshyp
cp -r share/doc/sshyp/ output/haikutemp/documentation/packages/
cp -r share/licenses/sshyp/ output/haikutemp/documentation/packages/
cp extra/sshyp-completion.bash output/haikutemp/boot/system/data/bash-completion/completions/sshyp
cp extra/manpage output/haikutemp/documentation/man/man1/sshyp.1
gzip output/haikutemp/documentation/man/man1/sshyp.1
cd output/haikutemp
package create -b sshyp-"$version"-"$revision"_all.hpkg
package add sshyp-"$version"-"$revision"_all.hpkg bin documentation
cd ../..
mv packages/haikutemp/sshyp-"$version"-"$revision"_all.hpkg packages/
rm -rf packages/haikutemp
echo -e "\nHaiku packaging complete.\n"
fi
mv output/haikutemp/sshyp-"$version"-"$revision"_all.hpkg output/
rm -rf output/haikutemp
echo -e "\nHaiku packaging complete\n"
} &&
if [ "$distro" == "2" ] || [ "$distro" == "9" ]; then
echo -e '\nPackaging for Debian...\n'
mkdir -p packages/debiantemp/sshyp_"$version"-"$revision"_all/{DEBIAN,usr/share/man/man1}
_create_deb() {
echo -e '\npackaging for Debian/Ubuntu...\n'
mkdir -p output/debiantemp/sshyp_"$version"-"$revision"_all/{DEBIAN,usr/share/{bash-completion/completions,man/man1}}
echo "Package: sshyp
Version: $version
Section: utils
@@ -83,21 +131,22 @@ Description: A light-weight, self-hosted, synchronized password manager
Depends: python3, gnupg, openssh-client, xclip, wl-clipboard
Priority: optional
Installed-Size: 185
" > packages/debiantemp/sshyp_"$version"-"$revision"_all/DEBIAN/control
cp -r bin packages/debiantemp/sshyp_"$version"-"$revision"_all/usr/
ln -s /usr/bin/sshyp.py packages/debiantemp/sshyp_"$version"-"$revision"_all/usr/bin/sshyp
cp -r share packages/debiantemp/sshyp_"$version"-"$revision"_all/usr/
cp extra/manpage packages/debiantemp/sshyp_"$version"-"$revision"_all/usr/share/man/man1/sshyp.1
gzip packages/debiantemp/sshyp_"$version"-"$revision"_all/usr/share/man/man1/sshyp.1
dpkg-deb --build --root-owner-group packages/debiantemp/sshyp_"$version"-"$revision"_all/
mv packages/debiantemp/sshyp_"$version"-"$revision"_all.deb packages/
rm -rf packages/debiantemp
echo -e "\nDebian packaging complete.\n"
fi
" > output/debiantemp/sshyp_"$version"-"$revision"_all/DEBIAN/control
cp -r bin output/debiantemp/sshyp_"$version"-"$revision"_all/usr/
ln -s /usr/bin/sshyp.py output/debiantemp/sshyp_"$version"-"$revision"_all/usr/bin/sshyp
cp -r share output/debiantemp/sshyp_"$version"-"$revision"_all/usr/
cp extra/sshyp-completion.bash output/debiantemp/sshyp_"$version"-"$revision"_all/usr/share/bash-completion/completions/sshyp
cp extra/manpage output/debiantemp/sshyp_"$version"-"$revision"_all/usr/share/man/man1/sshyp.1
gzip output/debiantemp/sshyp_"$version"-"$revision"_all/usr/share/man/man1/sshyp.1
dpkg-deb --build --root-owner-group output/debiantemp/sshyp_"$version"-"$revision"_all/
mv output/debiantemp/sshyp_"$version"-"$revision"_all.deb output/
rm -rf output/debiantemp
echo -e "\nDebian/Ubuntu packaging complete\n"
} &&
if [ "$distro" == "5" ] || [ "$distro" == "9" ]; then
echo -e '\nPackaging for Termux...\n'
mkdir -p packages/termuxtemp/sshyp_"$version"-"$revision"_all_termux/{data/data/com.termux/files/usr/share/man/man1,DEBIAN}
_create_termux() {
echo -e '\npackaging for Termux...\n'
mkdir -p output/termuxtemp/sshyp_"$version"-"$revision"_all_termux/{data/data/com.termux/files/usr/share/{bash-completion/completions,man/man1},DEBIAN}
echo "Package: sshyp
Version: $version
Section: utils
@@ -107,76 +156,57 @@ Description: A light-weight, self-hosted, synchronized password manager
Depends: python, gnupg, openssh, termux-api, termux-am
Priority: optional
Installed-Size: 185
" > packages/termuxtemp/sshyp_"$version"-"$revision"_all_termux/DEBIAN/control
cp -r bin packages/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/
ln -s /data/data/com.termux/files/usr/bin/sshyp.py packages/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/bin/sshyp
cp -r share packages/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/
cp extra/manpage packages/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/share/man/man1/sshyp.1
gzip packages/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/share/man/man1/sshyp.1
dpkg-deb --build --root-owner-group packages/termuxtemp/sshyp_"$version"-"$revision"_all_termux/
mv packages/termuxtemp/sshyp_"$version"-"$revision"_all_termux.deb packages/
rm -rf packages/termuxtemp
echo -e "\nTermux packaging complete.\n"
fi
" > output/termuxtemp/sshyp_"$version"-"$revision"_all_termux/DEBIAN/control
cp -r bin output/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/
ln -s /data/data/com.termux/files/usr/bin/sshyp.py output/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/bin/sshyp
cp -r share output/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/
cp extra/sshyp-completion.bash output/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/share/bash-completion/completions/sshyp
cp extra/manpage output/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/share/man/man1/sshyp.1
gzip output/termuxtemp/sshyp_"$version"-"$revision"_all_termux/data/data/com.termux/files/usr/share/man/man1/sshyp.1
dpkg-deb --build --root-owner-group output/termuxtemp/sshyp_"$version"-"$revision"_all_termux/
mv output/termuxtemp/sshyp_"$version"-"$revision"_all_termux.deb output/
rm -rf output/termuxtemp
echo -e "\nTermux packaging complete\n"
} &&
if [ "$distro" == "3" ] || [ "$distro" == "4" ] || [ "$distro" == "6" ] || [ "$distro" == "7" ] || [ "$distro" == "8" ] || [ "$distro" == "9" ]; then
echo -e '\nPackaging as generic...\n'
mkdir -p packages/generictemp/usr/share/man/man1
cp -r bin packages/generictemp/usr/
ln -s /usr/bin/sshyp.py packages/generictemp/usr/bin/sshyp
cp -r share packages/generictemp/usr/
cp extra/manpage packages/generictemp/usr/share/man/man1/sshyp.1
gzip packages/generictemp/usr/share/man/man1/sshyp.1
tar -C packages/generictemp -cvJf packages/sshyp-"$version".tar.xz usr/
rm -rf packages/generictemp
sha512="$(sha512sum packages/sshyp-"$version".tar.xz | awk '{print $1;}')"
echo -e "\nsha512 sum:\n$sha512"
echo -e "\nGeneric packaging complete.\n"
fi
if [ "$distro" == "3" ]; then
echo -e '\nPackaging for Fedora...\n'
_create_rpm() {
echo -e '\npackaging for Fedora...\n'
rm -rf ~/rpmbuild
rpmdev-setuptree
cp packages/sshyp-"$version".tar.xz ~/rpmbuild/SOURCES
cp output/sshyp-"$version".tar.xz ~/rpmbuild/SOURCES
echo "Name: sshyp
Version: "$version"
Release: "$revision"
Summary: A light-weight, self-hosted, synchronized password manager
BuildArch: noarch
License: GPLv3
URL: https://github.com/rwinkhart/sshyp
Source0: sshyp-"$version".tar.xz
Requires: python gnupg openssh wl-clipboard
%description
sshyp is a password-store compatible CLI password manager available for UNIX(-like) systems - its primary goal is to make syncing passwords and notes across devices as easy as possible via CLI.
%install
tar xf %{_sourcedir}/sshyp-"$version".tar.xz -C %{_sourcedir}
cp -r %{_sourcedir}/usr %{buildroot}
%files
/usr/bin/sshyp
/usr/bin/sshyp.py
/usr/bin/sshync.py
/usr/bin/sshypRemote.py
/usr/share/bash-completion/completions/sshyp
%license /usr/share/licenses/sshyp/license
%doc /usr/share/doc/sshyp/changelog
%doc /usr/share/man/man1/sshyp.1.gz
" > ~/rpmbuild/SPECS/sshyp.spec
rpmbuild -bb ~/rpmbuild/SPECS/sshyp.spec
mv ~/rpmbuild/RPMS/noarch/* packages/
mv ~/rpmbuild/RPMS/noarch/* output/
rm -rf ~/rpmbuild
echo -e "\nFedora packaging complete.\n"
fi
echo -e "\nFedora packaging complete\n"
} &&
if [ "$distro" == "4" ] || [ "$distro" == "9" ]; then
echo -e '\nPackaging for FreeBSD...\n'
mkdir -p packages/FreeBSDtemp/bin
tar xf packages/sshyp-"$version".tar.xz -C packages/FreeBSDtemp
_create_freebsd_pkg() {
echo -e '\npackaging for FreeBSD...'
mkdir -p output/freebsdtemp/usr/share/{bash-completion/completions,man/man1}
echo "name: sshyp
version: \""$version"\"
abi = \"FreeBSD:13:*\";
@@ -201,63 +231,50 @@ prefix: /
\"origin\" : \"x11/wl-clipboard\"
},
},
" > packages/FreeBSDtemp/+MANIFEST
" > output/freebsdtemp/+MANIFEST
echo "/usr/bin/sshync.py
/usr/bin/sshyp
/usr/bin/sshyp.py
/usr/bin/sshypRemote.py
/usr/share/bash-completion/completions/sshyp
/usr/share/doc/sshyp/changelog
/usr/share/licenses/sshyp/license
/usr/share/man/man1/sshyp.1.gz
" > packages/FreeBSDtemp/plist
pkg create -m packages/FreeBSDtemp/ -r packages/FreeBSDtemp/ -p packages/FreeBSDtemp/plist -o packages/
rm -rf packages/FreeBSDtemp
echo -e "\nFreeBSD packaging complete.\n"
fi
" > output/freebsdtemp/plist
cp -r bin output/freebsdtemp/usr/
ln -s /usr/bin/sshyp.py output/freebsdtemp/usr/bin/sshyp
cp -r share output/freebsdtemp/usr/
cp extra/sshyp-completion.bash output/freebsdtemp/usr/share/bash-completion/completions/sshyp
cp extra/manpage output/freebsdtemp/usr/share/man/man1/sshyp.1
gzip output/freebsdtemp/usr/share/man/man1/sshyp.1
pkg create -m output/freebsdtemp/ -r output/freebsdtemp/ -p output/freebsdtemp/plist -o output/
rm -rf output/freebsdtemp
echo -e "\nFreeBSD packaging complete\n"
} &&
if [ "$distro" == "7" ] || [ "$distro" == "9" ]; then
echo -e '\nGenerating PKGBUILD...'
echo "# Maintainer: Randall Winkhart <idgr at tutanota dot com>
pkgname=sshyp
pkgver="$version"
pkgrel="$revision"
pkgdesc='A light-weight, self-hosted, synchronized password manager'
url='https://github.com/rwinkhart/sshyp'
arch=('any')
license=('GPL3')
depends=(python gnupg openssh xclip wl-clipboard)
source=(\""$source"\")
sha512sums=('"$sha512"')
package() {
tar xf sshyp-"\"\$pkgver\"".tar.xz -C "\"\${pkgdir}\""
}
" > packages/PKGBUILD
echo -e "\nPKGBUILD generated.\n"
fi
if [ "$distro" == "8" ] || [ "$distro" == "9" ]; then
echo -e '\nGenerating APKBUILD...'
echo "# Maintainer: Randall Winkhart <idgr@tutanota.com>
pkgname=sshyp
pkgver="$version"
pkgrel="$((revision-1))"
pkgdesc='A light-weight, self-hosted, synchronized password manager'
options=!check
url='https://github.com/rwinkhart/sshyp'
arch='noarch'
license='GPL-3.0-or-later'
depends='python3 gnupg openssh xclip wl-clipboard'
source=\""$source"\"
package() {
mkdir -p "\"\$pkgdir\""
cp -r "\"\$srcdir/usr/"\" "\"\$pkgdir\""
}
sha512sums=\"
"$sha512' 'sshyp-\"\$pkgver\".tar.xz"
\"
" > packages/APKBUILD
echo -e "\nAPKBUILD generated.\n"
if [ "$1" == "generic" ]; then # build scripts
_create_generic
elif [ "$1" == "pkgbuild" ]; then
_create_generic
_create_pkgbuild
elif [ "$1" == "apkbuild" ]; then
_create_generic
_create_apkbuild
elif [ "$1" == "scripts" ]; then
_create_generic
_create_pkgbuild
_create_apkbuild
elif [ "$1" == "haiku" ]; then # distribution packages
_create_hpkg
elif [ "$1" == "debian" ]; then
_create_deb
elif [ "$1" == "termux" ]; then
_create_termux
elif [ "$1" == "fedora" ]; then
_create_generic
_create_rpm
elif [ "$1" == "freebsd" ]; then
_create_freebsd_pkg
else
echo -e '\nusage: package.sh [target] <revision>\n\ntargets:\n mainline: pkgbuild apkbuild haiku fedora debian termux\n experimental: freebsd\n coming soon: appimage(mainline) openbsd(mainline) macos(experimental)\n'
fi