From 1ad28aa1317a2c7695a2d5956788f3f52e2acca2 Mon Sep 17 00:00:00 2001 From: juko Date: Mon, 27 Apr 2020 00:42:32 +0000 Subject: [PATCH 1/2] quick Dynamic installation for debian-based distributions by creating a .deb package based always on the latest bashtop script --- DEB/DEBIAN/control | 10 ++++ DEB/DEBIAN/postinst | 4 ++ DEB/DEBIAN/postrm | 4 ++ DEB/DEBIAN/preinst | 4 ++ DEB/DEBIAN/prerm | 4 ++ DEB/build | 114 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 14 ++++++ 7 files changed, 154 insertions(+) create mode 100644 DEB/DEBIAN/control create mode 100755 DEB/DEBIAN/postinst create mode 100755 DEB/DEBIAN/postrm create mode 100755 DEB/DEBIAN/preinst create mode 100755 DEB/DEBIAN/prerm create mode 100755 DEB/build diff --git a/DEB/DEBIAN/control b/DEB/DEBIAN/control new file mode 100644 index 0000000..72a6b8a --- /dev/null +++ b/DEB/DEBIAN/control @@ -0,0 +1,10 @@ +Package: bashtop +Version: 0.0.0 +Section: base +Priority: optional +Architecture: all +Depends: bash (>= 4.4),curl (>= 7.16.2), coreutils, sed, awk, grep +Maintainer: your_name +Description: Resource monitor that shows usage + and stats for processor, memory, disks, network and processes +Homepage: https://github.com/aristocratos/bashtop diff --git a/DEB/DEBIAN/postinst b/DEB/DEBIAN/postinst new file mode 100755 index 0000000..5c79ea1 --- /dev/null +++ b/DEB/DEBIAN/postinst @@ -0,0 +1,4 @@ +#!/bin/bash + + +echo -e "[\033[1;32m done \033[0m]" diff --git a/DEB/DEBIAN/postrm b/DEB/DEBIAN/postrm new file mode 100755 index 0000000..018758e --- /dev/null +++ b/DEB/DEBIAN/postrm @@ -0,0 +1,4 @@ +#!/bin/bash + + +echo -e "[\033[1;32m successfully removed \033[0m]" diff --git a/DEB/DEBIAN/preinst b/DEB/DEBIAN/preinst new file mode 100755 index 0000000..124ee07 --- /dev/null +++ b/DEB/DEBIAN/preinst @@ -0,0 +1,4 @@ +#!/bin/bash + + +echo -e "[\033[1;32m starting intallation \033[0m]" diff --git a/DEB/DEBIAN/prerm b/DEB/DEBIAN/prerm new file mode 100755 index 0000000..c11154b --- /dev/null +++ b/DEB/DEBIAN/prerm @@ -0,0 +1,4 @@ +#!/bin/bash + + +echo -e "[\033[1;33m removing packet from the system \033[0m]" diff --git a/DEB/build b/DEB/build new file mode 100755 index 0000000..6741218 --- /dev/null +++ b/DEB/build @@ -0,0 +1,114 @@ +#!/bin/bash + + +# this little script is just to automate the creation of the .deb package under debian and also the automatic installation of the bashtop program in the system. +# How does it work? +# ---- +# It parses the bashtop file to retrieve the last version specified in the script to allow a fresh creation of the .deb package +# +by also retrieving the most recent version of the script then it proceeds to the installation ... + +set -o errexit +#set -x # just for debuging + +readonly file_src_location=../bashtop # bashtop location ^ +readonly ubin=usr/bin/ +readonly file_name=${file_src_location##*/} +readonly ctrl_file=DEBIAN/control +readonly architecture=amd64 # for all architectures +readonly root_uid=0 +declare version build_version + +[[ ROOT::PERMISSION ]] +{ + [[ $UID -ne ${root_uid} ]] && { + echo -e "require root user" + exit $UID + } +} + +[[ ARGUMENTS::HANDLER ]] +{ + if [[ -n $1 ]] ; then + case $1 in + "--remove") + [[ -x /${ubin}/${file_name} ]] && { + dpkg --remove ${file_name} + test $? -eq 0 && exit 0 + }||{ + echo -e "~ nothing todo: bashtop is removed " + exit 0 + } + ;; + esac + fi +} + +echo -e "+ building package ..." +sleep 1 +[[ FILECHECK ]] +{ + #+ require bashtop file to read inside + [[ ! -f ${file_src_location} ]] && { + echo -e "undefine ${file_name}" + exit 3 # just a basic exit + }|| { + echo -e "+ populate DEB folder " + `cp $file_src_location $ubin` + } + + #+ require control file to write inside + [[ ! -f ${ctrl_file} ]] && { + echo -e "undefined ${ctrl_file##*/}" + exit 3 + } +} +[[ IO::SEMVERS ]] +{ + echo -e "+ fetching the lastest version of ${file_name}" + + get_current_version () { + local watch_version=`grep -i "declare version" ${file_src_location}` + local semvers=${watch_version##*=} + echo ${semvers:1:-1} + } + + set_new_version_ctrl() { + local catch_package_version=`grep -i version ${ctrl_file}` + version=${catch_package_version%%:*} + build_version=${catch_package_version##*:} + [[ -n $1 ]] && build_version=$1 + version+=": ${build_version}" + + echo -e "+ set new version control" + `sed -i "s/$catch_package_version/${version}/g" ${ctrl_file}` + } + +set_new_version_ctrl $(get_current_version) +} + +[[ PACKAGER_BUILD::DEB ]] +{ + build_for_debian_base (){ + local debian_package_name=${file_name}_${build_version}-${architecture}.deb + #echo ${debian_package_name} + dpkg-deb --build ../DEB ${debian_package_name} + test $? -eq 0 && { + if [[ -f ${debian_package_name} ]] ;then + dpkg -i ${debian_package_name} + [[ $? -eq 0 ]] && { + exit $? + }||{ + echo -e "Installation failed" + exit $? + } + fi + }||{ + echo -e "build failed" + exit 5 + } + } + +build_for_debian_base +} + + diff --git a/README.md b/README.md index eaa9ce5..31aa107 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,20 @@ Also available in the AUR as [bashtop-git](https://aur.archlinux.org/packages/ba Also available for debian/ubuntu from [Azlux's repository](http://packages.azlux.fr/) +Or use quick installation + +>quick install go to DEB folder and type + +``` + sudo ./build +``` + +>to uninstall it go to DEB folder and type + +``` + sudo ./build --remove +``` + ## Configurability All options changeable from within UI. From 0e5f84c0932b098231d0cfa02c354630a2f8445e Mon Sep 17 00:00:00 2001 From: juko Date: Mon, 27 Apr 2020 05:58:02 +0000 Subject: [PATCH 2/2] avoid missing dir --- DEB/build | 1 + 1 file changed, 1 insertion(+) diff --git a/DEB/build b/DEB/build index 6741218..e329ffd 100755 --- a/DEB/build +++ b/DEB/build @@ -53,6 +53,7 @@ sleep 1 exit 3 # just a basic exit }|| { echo -e "+ populate DEB folder " + [[ -d $ubin ]] || mkdir -p $ubin `cp $file_src_location $ubin` }