diff --git a/tools/PKGBUILD b/tools/PKGBUILD
index d95f09d..7646865 100644
--- a/tools/PKGBUILD
+++ b/tools/PKGBUILD
@@ -19,7 +19,7 @@ url="https://github.com/Fincer/archtools"
arch=(any)
license=(GPL)
depends=(coreutils bash grep sed
-pacman # listpkg.sh, bininfo.sh, pkginfo.sh, buildpkg.sh, installlocal.sh, missinglibs.sh, nowner.sh, findpkg.sh, findinpkg.sh, pkgdeps.sh, pkgstr.sh, risks.sh, showpkg.sh
+pacman # bininfo.sh, pkginfo.sh, buildpkg.sh, installlocal.sh, missinglibs.sh, nowner.sh, findpkg.sh, findinpkg.sh, pkgdeps.sh, risks.sh, showpkg.sh
perl # findpkg.sh, genmac.sh
wget # getsource.sh
file # nowner.sh
@@ -42,18 +42,14 @@ genmac.sh
getsource.sh # TODO: More implementation needed. See the file for details
nowner.sh # TODO: More implementation needed. See the file for details
pkgdeps.sh # TODO: More implementation needed. See the file for details
-pkgstr.sh
archrisks.sh
showpkg.sh
deltmpfiles.sh
missinglibs.sh
-installlocal.sh
buildpkg.sh
pkginfo.sh
bininfo.sh
-listpkg.sh
killprocess.sh
-rmpkgfiles.sh
specialchars.sh
whichcmd.sh
killns.sh
@@ -69,28 +65,29 @@ if [[ $server_environment == "true" ]]; then
source+=(ssh_timezone.sh)
fi
-sha256sums=('f5455279ae48739b4ce16b10061e898f80cff0c9b24100f499015cae618fb8c6'
- '623b794a8a537649cc434b496dbf1f018aeea99f57f11d0719f80e495ca438b6'
- '568dba0eb0dfe1875980484fe473bbbd4397bdc04622f6177992ee75ca1b065f'
- 'ed4e06ceb5aff36ea66ce9de74f5ff2236ab2f92a9419d79d6fefe5a1b013859'
- '60d859fead290ba0c39502a21eb093aa63b384963bf83b60d93c2fcb74655ef6'
- 'a3cf8e77af8a49935c3e9a579354f761ab7ca8c2f94760012b9e23a196307f8f'
- '6783896c716045da0e38ae11ccaac491b6166b15ef9273118dcbe662b2eca97e'
- 'e25a0d8b425fd3f05414b6f1f6f5fce5832bb842691dad5aff4c7ac5aaa7a9fd'
- '28fe6983f144e41d57589fefac6d60b84ff3b0968cc4b274276b34802ff03dd0'
- '67d5627b20ec75d94cb89f9f193daa8a8018d1453d387e0306c0032f5a9b6b30'
- 'd1427a149f7092fd2ac8e0f81167f7c4eb6a318918f96b2d5301a8b750796c5d'
- 'abc140033891cc4564d71e8487f6cd1e54add761417cc772652542daf7352f44'
- '8b76a175d7cc767519d1e3519d1fd874cc19cc529e08a27138948f8a1907ac6a'
- '6886176293cb3ed131dd83e2ca3aa15f70c559e265534e195fa8848f2d02f659'
- 'ef4574de79c82d52a2cfb57cbf19419362ab702471bd71620e5893f426d150e2'
- 'ac761aa82d3a369a3f5335ad8f38af6cd00181cacf24737080e6d6ed6fff1b18'
- '63a7b50faba7963584519f2800205d853cc02d6386362c9efd9f61154e4c9ddb'
- 'aa0b96ff9f1ff51e1ea3634fa7e17cbffa565c5b2db79ed75bd6aeeb9de9a723'
- 'fc87bd14c0638cd3c803143c371946efe2c96a87d72d2c144fbaf29a815294d3'
- '4baf8c7d1032cafb8535dc4d53c42b7e7f2da6839bde791c31104a3f67eb845b'
- 'e179f9b18d6869558a97530101502ae6b445d3ef430e2e4359d015f214292093'
- '1aae9db8652179e18691fd51c687ab393672f380084e8777145572a5699bf5cf'
+sha256sums=('891d763f852d3a61216a384a15ca01c57178d3a5fea8aa858de0643998e9ba58'
+ '3af9ef2fc156d2c62753f1bf902e31ce84fb5c7ccd3d978b176047ab281e2f08'
+ '7bdfc3ec70ebb91b330f2239a86a6f7394c8c82b51263e5e96839f5f896707da'
+ 'c96b43cc49e6872cdd3b6e51cb490ca8ea2d990f2c3545bed106a21df86648eb'
+ '3bfac88603fe0f19383bc8b1ca7e2bc6795a90e851eaefd0758d515edd916100'
+ '3cf521359e473256a52e2a9fbcbfa3f0d39f42befa2d9a79cb7c51372f925c7b'
+ '43c15b4b18e6c43cab34fe905d2751525a505830e7c6e7286cedb7dfb408f815'
+ '4031b9ffb038ba16dcf188dde3f45af4cd0efff647c1926b7a172a6262ec6bf6'
+ '9993d81f56f526ab8813b268d5b3d3424f4950c05b2fc03c106d71788f043c0a'
+ '6290400b493a6e498ffe4a457274c3c4da4de60f5f3043cb36d08c9ca29cce63'
+ '4a9693bdc1d6a10e54266bf7b3d440e926d66c61ef6d18774a2db951aa4dd478'
+ '8bbcb61e6283bda4988468271cbaee0d7c537342a095466b4ea309bcb782eaf2'
+ 'ca1aae07f32fd9ba2a05ffa107d1ac97638578c9926359b323be56d911b54c17'
+ '845c3f8c0069d7938f800fe6c2e473fd1359c0fd17a5c37cbd89bbcb89c10ae7'
+ 'd3adffd099f5a3018b29cfb3899e5ba8ffe9d3584be5579b0edeae0818684e4d'
+ 'ae13b022053b6a3d2977fac8fbf036b09dfcf107c20f9c97577a573cecc01de0'
+ '434aa1eed4088f9bf86cef1f186b6444166e9d8367d4666a79d5c9edcf8dac2e'
+ 'e5b8a59bcaa430f28bdd6503d4e34e57e44e429000c046d16caddcaa0fa5a30f'
+ '96c0a6093ddc3c6946cd6aa2ce038a046bf658b834c2fe8f4e8a1c40b3149453'
+ '6df52b55e5b7471d07fe2e2a6b40ddb2972bb7ff9e60911bd4f5fcdb0e07c860'
+ 'ded8bbcb0267632bdbeb100468b412911f5b0d32541744acff94a81bc346c17d'
+ '4d5a0fc2b8817f17d9f180a28970dfcd14b5aea2f0164bd6fbfed145bd009d29'
+ '30ec1a5143e9b3353e34427539abd5e5b52e2c43e3e9dd730f566362caff2c9e'
'93ee0e990f36a5641e4f9fb4ba851e3db47ff6f01fdfad8dd169b83c546ecae9'
'40fd211e7b4a21ca61be81a809ee47f58adc6cd220218a20a0c7e65e1534c6ca')
diff --git a/tools/archrisks.sh b/tools/archrisks.sh
index 12f6039..8f0b825 100755
--- a/tools/archrisks.sh
+++ b/tools/archrisks.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
-
-# archrisks - Security information tool for Arch Linux
-# Copyright (C) 2020 Pekka Helenius
+#
+# archrisks - Get security risk severity & count of installed packages on Arch Linux
+# Copyright (C) 2021 Pekka Helenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-######################################################################################################################
+#####################################
red=$'\33[91m'
orange=$'\033[38;5;208m'
@@ -37,8 +37,8 @@ typeset -A ARCH_MANAGERS
#
# "
ARCH_MANAGERS=(
- [0,pacman]="-Syy|-Qi|-Q|-Si|root"
- [1,pacaur]="-Syy|-Qi|-Q|-Si|no_root"
+ [0,/usr/bin/pacman]="-Syy|-Qi|-Q|-Si|root"
+ [1,/usr/bin/pacaur]="-Syy|-Qi|-Q|-Si|no_root"
# [2,yaourt]="-Syy|-Qi|-Q|-Si|no_root"
# [3,pikaur]="-Syy|-Qi|-Q|-Si|no_root"
# [4,pacget]="-Syy|-Qi|-Q|-Si|no_root"
@@ -96,7 +96,7 @@ function inputParser() {
echo "Unknown sorting order selected (${sort_order})."
helpCaller
esac
-
+
if [[ ${input_count} -eq 2 ]]; then
case ${input_2} in
"--reverse")
@@ -271,7 +271,7 @@ function runTool() {
col4="${reset}Newer package installed"
break
fi
-
+
let s++
done
fi
@@ -283,7 +283,7 @@ function runTool() {
let prs_count++
let i++
-
+
done
echo -e "\e[1m"
@@ -312,11 +312,11 @@ function runTool() {
# echo "Unknown sorting order selected. Exiting."
# exit 1
esac
-
+
if [[ ${sort_reverse} == 1 ]]; then
sort_params+=("-r")
fi
-
+
i=0
for line in $(echo "${risk_entries[*]}" | sort ${sort_params[*]} -t'|' ${sort_column}); do
diff --git a/tools/bininfo.sh b/tools/bininfo.sh
index ec0a66b..7c850e5 100755
--- a/tools/bininfo.sh
+++ b/tools/bininfo.sh
@@ -1,6 +1,23 @@
-#!/bin/bash
+#!/usr/bin/env bash
+#
+# bininfo - Show information about an executable in PATH on Arch Linux
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
#####################################
-# Show information about executable on Arch Linux
+
BIN=$(which $1)
-echo -e "$BIN\n$(pacman -Qo $BIN)"
+echo -e "$BIN\n$(/usr/bin/pacman -Qo $BIN)"
diff --git a/tools/buildpkg.sh b/tools/buildpkg.sh
index 73d7065..3d2395d 100755
--- a/tools/buildpkg.sh
+++ b/tools/buildpkg.sh
@@ -1,8 +1,26 @@
-#!/bin/bash
-
-#############################
-# Build local package in PKGBUILD directory on Arch Linux
+#!/usr/bin/env bash
+#
+# buildpkg - Build a local package on the current directory which has PKGBUILD on Arch Linux
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
+
+#####################################
+
+# Requires package: pacman-contrib
+
if [ ! -e ./PKGBUILD ]; then #We check whether PKGBUILD file exists. If no, then...
echo -e "No PKGBUILD file found!\n"
return 1
diff --git a/tools/deltmpfiles.sh b/tools/deltmpfiles.sh
index f981b6a..1045035 100755
--- a/tools/deltmpfiles.sh
+++ b/tools/deltmpfiles.sh
@@ -1,7 +1,23 @@
-#!/bin/bash
+#!/usr/bin/env bash
+#
+# deltmpfiles - Delete current temporary files from pre-defined locations
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
-###########################################################
-# Delete current temporary files
+#####################################
#All tmp files currently being used
TMP_USED=$(lsof +D /tmp/ | awk '{print $9," "}' | sort -u | tail -n+3 | sed 's/[ \t]*$//')
diff --git a/tools/extract.sh b/tools/extract.sh
index 2e644c4..7026a8a 100755
--- a/tools/extract.sh
+++ b/tools/extract.sh
@@ -1,7 +1,24 @@
-#!/bin/bash
+#!/usr/bin/env bash
+#
+# extract - Extract wide range of various archive types with native tools
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
+
+#####################################
-###########################################################
-#Extract wide range of various archive types
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract ."
@@ -12,7 +29,7 @@ else
do
if [ -f "$n" ] ; then
case "${n%,}" in
- *.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
+ *.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
diff --git a/tools/findinpkg.sh b/tools/findinpkg.sh
index 8ac8240..1d736ae 100755
--- a/tools/findinpkg.sh
+++ b/tools/findinpkg.sh
@@ -1,8 +1,23 @@
-#!/bin/bash
-
-##################################################
-# Find line patterns in package files.
-# Print matching file path and matching lines.
+#!/usr/bin/env bash
+#
+# findinpkg - Find text patterns & print occurences with matching lines numbers in Arch Linux package files
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
+
+#####################################
function help() {
echo -e "Usage: findinpkg "
diff --git a/tools/findmatch.sh b/tools/findmatch.sh
index 71b7c90..0ae2251 100755
--- a/tools/findmatch.sh
+++ b/tools/findmatch.sh
@@ -1,7 +1,23 @@
-#!/bin/bash
+#!/usr/bin/env bash
+#
+# findmatch - Grep/List matching strings in a specific folder
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
-###########################################################
-# Grep/List matching strings in a specific folder
+#####################################
if [ -z "$1" ]; then
$1=/ #If folder not specified, then we use root folder as a starting path
diff --git a/tools/findpkg.sh b/tools/findpkg.sh
index d050669..a2eea88 100755
--- a/tools/findpkg.sh
+++ b/tools/findpkg.sh
@@ -1,7 +1,23 @@
-#!/bin/bash
+#!/usr/bin/env bash
+#
+# findpkg - Search package in official Arch Linux repositories
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
-##################################################
-# Search package in online repositories
+#####################################
if [ -z "$1" ] ; then
echo "Usage: findpkg "
@@ -10,8 +26,8 @@ else
#
# pacman: find packages which include/refer to user input string $1 by using online repositories. Verbose order
#
-# Sort the output:
-# 1) sed: remove first 9 lines
+# Sort the output:
+# 1) sed: remove first 9 lines
# 2) sed: remove everything before the first slash in every other line (package names), including the slash itself
# 3) sed: remove version number strings in every other line (all numbers after the first space after package names
# 4) sed: remove bracket mark ) from every other line
@@ -22,6 +38,6 @@ else
# NOTE: More bash colors here: http://misc.flogisoft.com/bash/tip_colors_and_formatting
#
- pacman -Ssv $1 | sed -e '1,9d' | sed -e '1~2s/^.*\///' -e '1~2s/ .*[0-9]//g' -e '1~2s/)//g' | perl -pe '$_ = "\033[1;34m$_\033[0;33m" if($. % 2)' | sed ''/\\[installed\\]/s//$(printf "\033[1;31m\\[installed\\]")/''
+ /usr/bin/pacman -Ssv $1 | sed -e '1,9d' | sed -e '1~2s/^.*\///' -e '1~2s/ .*[0-9]//g' -e '1~2s/)//g' | perl -pe '$_ = "\033[1;34m$_\033[0;33m" if($. % 2)' | sed ''/\\[installed\\]/s//$(printf "\033[1;31m\\[installed\\]")/''
fi
echo -e '\e[0m'
diff --git a/tools/genmac.sh b/tools/genmac.sh
index 3982d50..a1f204b 100755
--- a/tools/genmac.sh
+++ b/tools/genmac.sh
@@ -1,6 +1,24 @@
-#!/bin/bash
+#!/usr/bin/env bash
+#
+# genmac - Generate a random MAC address for a Systemd-configured network interface
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
+
+#####################################
-# Randomize MAC Address
trap ctrl_c INT
function ctrl_c() {
@@ -14,7 +32,7 @@ random_mac() {
insert_mac() {
echo -e "\nChanging MAC address information (root permission required).\n"
-
+
sudo sed -i "/\[Link\]/!b;n;cMACAddress=$MAC" /etc/systemd/network/00-default.link
echo -e "MAC address changed from '$MAC_OLD' to '$MAC' for interface '$MAC_DEVICE'.\n\nPlease restart this interface to apply the changes.\n\nTo restore original MAC address, either delete configuration file '/etc/systemd/network/$linkname' or set real MAC address manually into it.\n"
return 0
@@ -23,11 +41,11 @@ insert_mac() {
geninsert_mac() {
gennew_mac() {
-
+
while true; do
unset response
read -r -p "Generate a new MAC address? [Y/n] " response
-
+
if [[ $(echo $response | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
random_mac
newname_mac
@@ -41,7 +59,7 @@ geninsert_mac() {
newname_mac() {
unset response
read -r -p "New MAC address for '$MAC_DEVICE' will be '$MAC'. Accept? [Y/n] " response
-
+
if [[ $(echo $response | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
insert_mac
else
@@ -56,21 +74,21 @@ gen_mac() {
real_mac() {
AVAILABLE_MACS=$(ip -br link show | sed '/LOOPBACK/d' | awk '{print NR"\t"$1"\t"$3"\t"$2}')
-
+
IFS=$'\n'
echo -e "\nAvailable network interfaces with their MAC addresses are:\n\n${AVAILABLE_MACS[*]}"
-
+
echo -e "\nPlease select the interface which MAC address you want to spoof of\n"
read -r -p "Selection [number]: " number
-
+
if [[ ! $number =~ ^[0-9]+$ ]]; then
echo -e "\nInvalid input value. Aborting.\n"
return 1
fi
-
+
for INTERFACE in $(echo -e "${AVAILABLE_MACS[*]}"); do
-
+
intf_num=$(echo $INTERFACE | awk '{print $1}')
if [[ $number -eq $intf_num ]]; then
@@ -91,8 +109,8 @@ gen_mac() {
real_mac
PREV_CONF=$(grep -Ril "$MAC_REAL" /etc/systemd/network/)
-
- if [[ ! $(echo $PREV_CONF | wc -w) -eq 0 ]]; then
+
+ if [[ ! $(echo $PREV_CONF | wc -w) -eq 0 ]]; then
echo -e "\nUsing existing configuration file for interface '$MAC_DEVICE':\n$PREV_CONF\n"
linkname=$(basename $PREV_CONF)
MAC_OLD=$(awk -F= '/\[Link\]/{getline; print $2}' $PREV_CONF)
@@ -102,14 +120,14 @@ gen_mac() {
read -r -p "Configuration file name? (must follow syntax: 00-default.link, 41-default.link, 98-default.link etc.): " linkname
if [[ $linkname =~ ^[0-9][0-9]-default.link ]]; then
-
+
if [[ ! $(sudo -n true) ]]; then
sudo echo ""
fi
-
+
echo -e "[Match]\nMACAddress=$MAC_REAL\n\n[Link]\nMACAddress=$MAC_REAL\nNamePolicy=kernel database onboard slot path" \
| sudo tee /etc/systemd/network/$linkname > /dev/null
-
+
echo -e "Created new configuration file: /etc/systemd/network/$linkname\n"
else
echo -e "\nInvalid file name given. Aborting.\n"
@@ -125,13 +143,13 @@ gen_mac() {
random_mac
geninsert_mac
else
-
+
if [[ $(echo $response | sed 's/ //g') =~ ^([nN][oO]|[nN])$ ]]; then
read -r -p "Please type a new MAC address (Syntax is e.g. aa:bb:33:zz:f0:4a): " MAC
maxtries=5
while [[ $maxtries -gt 0 ]]; do
- case "$MAC" in
+ case "$MAC" in
[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]])
insert_mac
;;
diff --git a/tools/getsource.sh b/tools/getsource.sh
index 8ab2ebc..ef9af37 100755
--- a/tools/getsource.sh
+++ b/tools/getsource.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
-# getsource - Get build files from Arch Linux official and AUR repositories
+# getsource - Get build files from official Arch Linux repositories and AUR repositories
#
# Copyright (C) 2021 Pekka Helenius
#
@@ -16,7 +16,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-#
+
+#####################################
+
# TODO: Add support for wider range of processor architectures
# TODO: Add directory support (e.g. getsource wine ~/winesource)
# TODO: create subdir for source files automatically to the current main dir
diff --git a/tools/installlocal.sh b/tools/installlocal.sh
deleted file mode 100755
index 21a7eec..0000000
--- a/tools/installlocal.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-
-##############################################
-# Install locally build program on Arch Linux
-
-if [ -e ./PKGBUILD ]; then #We check whether PKGBUILD file exists. If yes, then...
- PACKAGE_NAME=$(cat ./PKGBUILD | grep "pkgname=" | sed -e 's/pkgname=//g') #get package name from PKGBUILD
- PACKAGE=$(echo $PACKAGE_NAME*.pkg.tar.xz) #package name + * + suffix
-
- if [ -e $PACKAGE ]; then # If package has been compiled, then...
- sudo pacman -U $PACKAGE # ...install the package.
- fi
-else
- return 1
-fi
diff --git a/tools/killns.sh b/tools/killns.sh
index 5d3aa45..e4df246 100755
--- a/tools/killns.sh
+++ b/tools/killns.sh
@@ -1,4 +1,23 @@
-#!/bin/env sh
+#!/usr/bin/env bash
+#
+# killns - Send signal to a process running in a specific Linux namespace (see 'man 7 signal')
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
+
+#####################################
if [[ ${1} =~ ^(\-h|\-\-help)$ ]] || [[ -z ${1} ]]; then
echo "
diff --git a/tools/killprocess.sh b/tools/killprocess.sh
index 9f52df5..abd4ce0 100755
--- a/tools/killprocess.sh
+++ b/tools/killprocess.sh
@@ -1,9 +1,9 @@
-#!/bin/bash
+#!/usr/bin/env bash
-# NOT MADE BY ME!
+# Kill a process by its name
+
+#####################################
-###########################################################
-# Kill a process by name
ps aux | grep $1 > /dev/null
mypid=$(pidof $1)
if [ "$mypid" != "" ]; then
diff --git a/tools/listpkg.sh b/tools/listpkg.sh
deleted file mode 100755
index 5142866..0000000
--- a/tools/listpkg.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-###########################################################
-# Show packages named as on Arch Linux
-pacman -Q | grep "$1" | cut -d' ' -f1
diff --git a/tools/missinglibs.sh b/tools/missinglibs.sh
index d90bbd7..95cadb3 100755
--- a/tools/missinglibs.sh
+++ b/tools/missinglibs.sh
@@ -1,6 +1,22 @@
-#!/bin/bash
+#!/usr/bin/env bash
+#
+# missinglibs - List missing package libraries for a local, installed Arch Linux package
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
-###########################################################
-# Missing package libraries
+#####################################
-ldd $(mimetype $(pacman -Ql "${1}") | grep -iE "x\-sharedlib|x\-executable" | sed 's/\:.*//g') | grep -i "not found"
+ldd $(file --mime-type $(/usr/bin/pacman -Qql "${1}") | grep -iE "executable" | sed 's/:.*//') | grep -i "not found"
diff --git a/tools/nowner.sh b/tools/nowner.sh
index 75d1236..30a3713 100755
--- a/tools/nowner.sh
+++ b/tools/nowner.sh
@@ -1,28 +1,31 @@
-#!/bin/bash
-
-# nowner - Find orphan files on various Linux distributions
-# Copyright (C) 2018 Pekka Helenius
+#!/usr/bin/env bash
+#
+# nowner - Find orphan files on various Linux distributions
#
-# This program 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.
+# Copyright (C) 2021 Pekka Helenius
#
-# 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.
+# This program 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 2 of the License, or
+# (at your option) any later version.
#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
+# 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 .
-###########################################################
+#####################################
bash_yellow=$'\033[93m'
bash_red=$'\033[91m'
bash_color_default=$'\033[0m'
-###########################################################
+PACMAN_EXEC="/usr/bin/pacman"
+
+#####################################
#Useful for additional commands:
@@ -30,7 +33,7 @@ bash_color_default=$'\033[0m'
#find /usr/share -maxdepth 1 -type d -exec stat --format "%n: %U" {} \; | grep fincer
-###########################################################
+#####################################
# Check for command dependencies
if [[ $(which --help 2>/dev/null) ]] && [[ $(echo --help 2>/dev/null) ]]; then
@@ -53,7 +56,7 @@ else
exit 1
fi
-###########################################################
+#####################################
# Retrieve our Linux distribution and set the correct
# package manager for this command
@@ -68,12 +71,12 @@ function check_pkgmgr() {
fi
}
-##############################
+#####################################
# Arch Linux
if [[ $DISTRO == "Arch" ]]; then
check_pkgmgr pacman
- function PKGMGR_CMD() { pacman -Qo "$1" &>/dev/null || echo "error" | wc -l ; }
+ function PKGMGR_CMD() { ${PACMAN_EXEC} -Qo "$1" &>/dev/null || echo "error" | wc -l ; }
fi
# Debian, Ubuntu
@@ -94,9 +97,9 @@ fi
# OpenSUSE
# TODO
-###########################################################
+#####################################
# List files and directories which are not owned by any package in the system
-echo -e "\nSearch for files & folders which are not owned by any installed package.\n"
+echo -e "\nSearch for files & folders which are not owned by any installed package.\n"
# Avoid storing log files into root home
REAL_USER=$(who am i | awk '{print $1}')
@@ -151,7 +154,7 @@ else
unset response
-##############################
+#####################################
BASEDIR_OWNER=$(stat --format "%u" "${BASEDIR}")
@@ -168,7 +171,7 @@ else
echo -e "\n${bash_yellow}Warning:${bash_color_default} the main folder belongs to local user '$(id -un $BASEDIR_OWNER)'. Some files or directories may be inaccessible\n"
fi
-##############################
+#####################################
BASEDIR_UNDERLINE="$(echo ${BASEDIR} | sed 's/\//_/g')"
LOGFILE="$REAL_USER_HOME/nowner-${BASEDIR_UNDERLINE}-depth-${DEPTH_NUM}_$(date +%Y-%m-%d).log"
@@ -190,11 +193,11 @@ else
TO_FILE=0
fi
-##############################
+#####################################
echo -e "\nSearching unowned files & folders in $depthstr\n"
-##############################
+#####################################
function data_counter() {
i=0
@@ -241,7 +244,7 @@ else
}
-##############################
+#####################################
function data_check() {
@@ -293,7 +296,7 @@ else
unset VALID_DATASET
}
-##############################
+#####################################
function folders() {
type="folders"
@@ -309,7 +312,7 @@ else
data_check "${find_type}" $data_name
}
-##############################
+#####################################
if [[ $TO_FILE -eq 1 ]]; then
echo -e "Log timestamp: $(date '+%d-%m-%Y, %X') (TZ: $(timedatectl status | grep "Time zone:" | awk '{print $3}'))\nComputer: $(hostname)\nScanning Depth: $depthstr" >> $LOGFILE
diff --git a/tools/pkgdeps.sh b/tools/pkgdeps.sh
index c9fc9c6..8eb1c88 100755
--- a/tools/pkgdeps.sh
+++ b/tools/pkgdeps.sh
@@ -1,7 +1,8 @@
-#!/bin/bash
-
-# Shared library & executable dependency finder for Linux
-# Copyright (C) 2018 Pekka Helenius
+#!/usr/bin/env bash
+#
+# pkgdeps - Recursive shared library & executable dependency finder for Arch Linux
+#
+# Copyright (C) 2021 Pekka Helenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,65 +17,22 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-######################################################################################################################
+#####################################
# TODO print stored dependency packages as red if errors encountered
# TODO check packages themselves, too (not only their dependencies...)
-# TODO
-
-# BUG :
-#
-# Optional dependencies for linux :
-#
-# crda: to set the correct wireless channels of your country
-#
-# Required dependencies for linux :
-#
-# coreutils Found libraries/executables: 102
-# grep: Unmatched [ or [^
-# grep: Invalid regular expression
-
-# TODO
-# Depends on: libtinfo.so.6 Provided by:
-# ei anna oikeaa tulosta...
-# TODO
-#Error: octopi not found. Skipping.
-# Lisää tähän "do you mean...?...logiikka
+# TODO: Does not give a correct result
+# Depends on: libtinfo.so.6 Provided by:
-# -------------------------------------------
-# BUG
-# Ignore rules.d folder since it gives permission denied error
+# TODO: Implement 'Do you mean ?' code logic, when the following occurs:
+# Error: octopi not found. Skipping.
# -------------------------------------------
# BUG
+# Ignore rules.d folder since it gives permission denial errors
-#1/1 (100%) - ncurses
-
-#Required dependencies for ncurses :
-
-# glibc Found libraries/executables: 302
-#ldd: warning: you do not have execution permission for `/usr/lib/libcursesw.so'
-#error: failed to find 'dynamic' in PATH: No such file or directory
-#ldd: warning: you do not have execution permission for `/usr/lib/libform.so'
-#error: failed to find 'dynamic' in PATH: No such file or directory
-#ldd: warning: you do not have execution permission for `/usr/lib/libmenu.so'
-#error: failed to find 'dynamic' in PATH: No such file or directory
-#ldd: warning: you do not have execution permission for `/usr/lib/libncurses++.so'
-#error: failed to find 'dynamic' in PATH: No such file or directory
-# gcc-libs-multilib Found libraries/executables: 17
-
-# -------------------------------------------
-# BUG
-
-# When using command 'pkgdeps wine-git', the following error occurs:
-
-#...
-# lib32-libsm Found libraries/executables: 1
-#error: failed to find 'dynamic' in PATH: No such file or directory
-#error: failed to find 'dynamic' in PATH: No such file or directory
-
-######################################################################################################################
+#####################################
# Look for missing library files for installed packages
red=$'\33[91m'
@@ -85,379 +43,435 @@ blue=$'\033[94m'
bold=$'\033[1m'
reset=$'\033[0m'
+PACMAN_EXEC="/usr/bin/pacman"
+LOGFILE="/var/log/pacman.log"
+
COMMANDS=(sudo pacman date ping package-query)
+
for com in $COMMANDS; do
- if [[ ! $(which $com |grep "which: no $com in" | wc -w) -eq 0 ]]; then
- echo -e "\nCommand $com not found. Can't run the script.\n"
- return
- fi
+ if [[ ! $(which $com |grep "which: no $com in" | wc -w) -eq 0 ]]; then
+ echo -e "\nCommand $com not found. Can't run the script.\n"
+ return
+ fi
done
echo -e "\n${bold}Dependency tracker - Find broken executables & libraries${reset}"
-if [[ $# -eq 1 ]]; then
- pacman -Q $1 2> /dev/null #|| echo 'something' # TODO silent normal output!
- if [[ $? -eq 1 ]]; then
- seterror=1
- else
- seterror=0
+function checklocaldirs() {
+
+ unset PKG
+
+ for filepkgdir in $1; do
+ #echo "Search dir is $filepkgdir Search term is $2"
+ findfile=$(find "$filepkgdir" -maxdepth 1 -type f -iname "*$2*")
+
+ if [[ -f $findfile ]]; then
+ PKG="$(${PACMAN_EXEC} -Qo $findfile | awk '{print $5 " " $6}')"
+ return
fi
-else
- seterror=0
-fi
+
+ done
+}
+
+function checkrepopkgs() {
+
+ unset PKG
+ unset NIPKG
+ REPOPKGS=$(${PACMAN_EXEC} -Fs $1 | sed '2~2d' | awk -F '[/ ]' '{print $2}')
+
+ if [[ ! -z $REPOPKGS ]]; then
+
+ c=0
+
+ for repopkg in $REPOPKGS; do
+ t=0
+
+ for repopkgfile in $(${PACMAN_EXEC} -Fl "$repopkg" | awk '{print "/"$2}'); do
+ if [[ -f $repopkgfile ]]; then
+ REPOPKGFILES[$t]="$repopkgfile"
+ let t++
+ fi
+ done
+
+ if [ ! "${#REPOPKGFILES[@]}" -eq 0 ]; then
+
+ for matchrepofile in "${REPOPKGFILES[@]}"; do
+ if [[ "${matchrepofile}" == "${2}" ]]; then
+ PKG=$repopkg
+ return
+ # else
+ # if [[ $(${PACMAN_EXEC} -Qo $matchrepofile | grep -o "owned by" | wc -w) -eq 2 ]]
+ # PKG=$(echo "${REPOPKGS[*]}?" | tr '\n' ',' | sed 's/\,*$//g')
+ # return
+ fi
+
+ done
+ unset REPOPKGFILES
+
+ else
+ #echo "do we get here $repopkg"
+ if [[ $(${PACMAN_EXEC} -Q $repopkg &>/dev/null || echo "was not found" | wc -l) -eq 1 ]]; then
+ NIPKG[$c]="$repopkg"
+ let c++
+ fi
+ #PKG="${red}N/A${reset}"
+
+ fi
+ done
+ #PKG="${red}N/A${reset}"
+ else
+ PKG="${red}N/A${reset}"
+ fi
+}
function checkconnection() {
- PROVIDER="luna.archlinux.org"
- INTERNET_TEST=$(ping -c 1 $PROVIDER 2>&1 | grep -c "Name or service not known")
- if [[ ! $INTERNET_TEST -eq 0 ]]; then
- echo -e "\n${red}Error:${reset} Can't connect to $PROVIDER. Please check your internet connection.\n"
- else
- echo -e "\nUpdating file databases with pacman (root required)\n"
- sudo pacman -Fy
- fi
+ PROVIDER="luna.archlinux.org"
+
+ INTERNET_TEST=$(ping -c 1 $PROVIDER 2>&1 | grep -c "Name or service not known")
+
+ if [[ ! $INTERNET_TEST -eq 0 ]]; then
+ echo -e "\n${red}Error:${reset} Can't connect to $PROVIDER. Please check your internet connection.\n"
+ else
+ echo -e "\nUpdating file databases with pacman (root required)\n"
+ sudo ${PACMAN_EXEC} -Fy
+ fi
}
-LOGFILE=/var/log/pacman.log
+if [[ $# -eq 1 ]]; then
+ ${PACMAN_EXEC} -Q $1 2> /dev/null #|| echo 'something' # TODO silent normal output!
+ if [[ $? -eq 1 ]]; then
+ seterror=1
+ else
+ seterror=0
+ fi
+else
+ seterror=0
+fi
+
+#####################################
+
+if [[ ${#} -lt 1 ]]; then
+ echo -e "\nPlease give a name of an installed package\n"
+ exit 1
+fi
if [[ -f $LOGFILE ]] && [[ $seterror -ne 1 ]]; then
- LASTRUN=$(date --date="$(awk '/pacman -Fy/ {a=$0} END{print a}' $LOGFILE | awk -F'[][]' '{print $2}')" +"%s")
- if [[ $? -ne 0 ]]; then
- echo -e " ${red}Error:${reset} Can't parse the latest 'pacman -Fy' date value from pacman log file $LOGFILE! Skipping database update.\n"
- else
+ LASTRUN_TIMESTAMP=$(awk '/pacman -Fy/ {a=$0} END{print a}' $LOGFILE | awk -F'[][]' '{print $2}')
+ LASTRUN=$(date --date="${LASTRUN_TIMESTAMP}" +%s)
- if [[ $(echo $LASTRUN | wc -w) -eq 1 ]]; then
-
- CURTIME=$(date +"%s")
- LASTUPDATE=$(( ($CURTIME - $LASTRUN)/60 ))
- TIME_THRESHOLD=180 # 3 hours
-
- if [[ $LASTUPDATE -ge $TIME_THRESHOLD ]]; then
- echo -e "\nPackage databases updated $LASTUPDATE minutes ago.\n" # TODO minutes....hours...days...ago...
-
- read -r -p "Do you want to update databases now? [y/N] " dbupdate
- if [[ $(echo $dbupdate | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
- checkconnection
- else
- echo -e "\nSkipping database update.\n"
- fi
- else
- echo -e "\nPackage databases are updated.\n"
- fi
+ if [[ $? -ne 0 ]]; then
+ echo -e " ${red}Error:${reset} Can't parse the latest 'pacman -Fy' date value from pacman log file $LOGFILE! Skipping database update.\n"
+ else
+
+ if [[ $(echo $LASTRUN | wc -w) -eq 1 ]]; then
+
+ CURTIME=$(date +"%s")
+ LASTUPDATE=$(( ($CURTIME - $LASTRUN)/60 ))
+ TIME_THRESHOLD=180 # 3 hours
+
+ if [[ $LASTUPDATE -ge $TIME_THRESHOLD ]]; then
+ echo -e "\nPackage databases were last updated $LASTUPDATE minutes ago.\n" # TODO minutes....hours...days...ago...
+
+ read -r -p "Do you want to update databases now? [y/N] " dbupdate
+ if [[ $(echo $dbupdate | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
+ checkconnection
else
- echo -e "\nPrevious database update timestamp not found. Updating...\n"
- checkconnection
+ echo -e "\nSkipping database update.\n"
fi
+ else
+ echo -e "\nPackage databases are updated.\n"
+ fi
+ else
+ echo -e "\nPrevious database update timestamp not found. Updating...\n"
+ checkconnection
fi
+ fi
+
elif [[ ! -f $LOGFILE ]]; then
- echo -e "\n ${red}Error:${reset} Pacman log file not found.\n"
+ echo -e "\n ${red}Error:${reset} Pacman log file not found.\n"
fi
pkgcount=$#
curpkgcount=1
typeset -A CHECKEDLIST
+
# Loop through all input arguments (package names)
for p in $(echo "${@}"); do # TODO show how many dependencies this package has if more than 1
- LOCALDIRS=("/usr/lib" "/usr/bin" "/usr/lib/" "/opt/")
-
- w=0
- for dir in $(pacman -Ql $p 2> /dev/null | awk '{print $2}'); do
- if [[ -d $dir ]]; then
- MAINPKGDIRS[$w]="${dir}"
- let w++
- fi
- done
+ LOCALDIRS=("/usr/lib" "/usr/bin" "/usr/lib/" "/opt/")
- echo -e "----------------------------------------"
- echo -e "\n$curpkgcount/$pkgcount ($((100*$curpkgcount/$pkgcount))%) - ${orange}$p${reset}"
+ w=0
+ for dir in $(${PACMAN_EXEC} -Qql $p 2> /dev/null); do
+ if [[ -d $dir ]]; then
+ MAINPKGDIRS[$w]="${dir}"
+ let w++
+ fi
+ done
- # Check that the input package can actually be found
- if [[ $(pacman -Qi $p &>/dev/null || echo "was not found" | wc -l) -eq 1 ]]; then
- echo -e "\n ${red}Error:${reset} ${orange}$p${reset} not found. Skipping.\n"
- else
+ echo -e "----------------------------------------"
+ echo -e "\n$curpkgcount/$pkgcount ($((100*$curpkgcount/$pkgcount))%) - ${orange}$p${reset}"
- # Parse dependencies of the selected package to a string list
- PKGDEPS=$(pacman -Qi $p | grep "Depends On" | sed 's/.*: //g; s/ / /g')
-
- #Parse optional dependencies
- PKGDEPS_OPT=$(pacman -Qi $p | grep "Optional Deps" | sed 's/.*\s: //; s/ / /')
-
- # Loop for each package ([@] means array value X)
- # We circumvent a pacman bug/issue here
- # pacman does a hard fixed listing for packages, meaning it doesn't recognize "provides" option
- # This is mainly a problem of git package versions
- #
- if [[ $PKGDEPS_OPT != "None" ]]; then
- echo -e "\nOptional dependencies for ${orange}$p${reset} :\n\n $PKGDEPS_OPT"
- fi
-
- if [[ $PKGDEPS != "None" ]]; then
- echo -e "\nRequired dependencies for ${orange}$p${reset} :\n" # TODO go even one step deeper with these!
- for i in $(echo "${PKGDEPS[@]}"); do
-
- function parseversion() {
- pattern="[<=>]"
- if [[ $i =~ $pattern ]]; then
- i=$(echo $i | awk -F'[<=>]' '{print $1}')
- # TODO do version check here as done in 'risks' function?
- #i_ver=$(echo $i | awk -F'[<=>]' '{print $3}')
- #return $pkgname $pkgver
- #else
- #return $i
- fi
- }
-
- parseversion
- # Error (package was not found)
- if [[ $(pacman -Qi $i &>/dev/null || echo "was not found" | wc -l) -eq 1 ]]; then
-
- # Get name of the package which provides the dependency
- ALTDEP=$(pacman -Qi | grep -iE "Name|Provides" | grep $i | grep "Name" | sed 's/.*: //')
-
- o=0
- for altdep in $ALTDEP; do
- ALTDEPS[$o]=$altdep
- let o++
- done
-
- function deepscan() {
- MAINPKGFILES=$(pacman -Ql $p | awk '{print $2}')
- for mainpkgfile in $MAINPKGFILES; do
- if [[ $(mimetype "${mainpkgfile}" | grep -iE "x\-sharedlib|x\-executable" | wc -l) -eq 1 ]]; then
- for deepscan in $(ldd "${mainpkgfile}" | awk '{print $3}' | sed '/^\s*$/d'); do
- OWNER_DEEPSCAN=$(pacman -Qo $deepscan | awk '{print $5}')
- for item in "${ALTDEPS[@]}"; do
- if [[ $OWNER_DEEPSCAN == "$item" ]]; then
- i=$OWNER_DEEPSCAN
- return 0
- fi
- done
- done
- fi
- done
- return 1
- }
- deepscan
- if [[ $? -eq 1 ]]; then
- #Get 'provides' from arch package database
- FETCHEDPKGS=$(package-query --qprovides "$i" -Q -f "%n")
- k=0
- for fetch in $FETCHEDPKGS; do
- if [[ ! $(pacman -Q $fetch &>/dev/null || echo "was not found" | wc -l) -eq 1 ]]; then
- i="$fetch"
- break
- # TODO show here the true 'depends on' stuff, not just 'provided by' package? bash <-> sh conversion for example
- else
- echo -e " ${yellow}Warning:${reset} Dependency '$i' not found and not recognized as a provided package"
- i="notfound"
- NOTFOUNDS[$k]=$i
- let k++
- fi
- done
- fi
- fi
-
- if [[ $i != "notfound" ]] && [[ -z ${CHECKEDLIST[$i]} ]]; then
-
- FILES=$(pacman -Ql $i | awk '{print $2}')
- x=0
- printf " %-30s%s\r" "$i" "Searching libraries/executables"
- for mimefile in $FILES; do
- if [[ $(mimetype "${mimefile}" | grep -iE "x\-sharedlib|x\-executable" | wc -l) -eq 1 ]]; then
- MIMEFILES[$x]="${mimefile}"
- let x++
- printf " %-30s%s\r" "$i" "Found libraries/executables: $x " #Yes, the trailing space is meant to be here
- fi
- done
-
- if [[ $x -gt 0 ]]; then
- CHECKEDLIST[$i]=$(printf " %-30s%s\n" "$i" "Found libraries/executables: $x")
- else
- CHECKEDLIST[$i]=$(printf " %-30s%s\n" "$i" "No libraries/executables")
+ # Check that the input package can actually be found
+ if [[ $(${PACMAN_EXEC} -Qi $p &>/dev/null || echo "was not found" | wc -l) -eq 1 ]]; then
+ echo -e "\n ${red}Error:${reset} package ${orange}$p${reset} not found. Skipping.\n"
+ else
+
+ # Parse dependencies of the selected package to a string list
+ PKGDEPS=$(${PACMAN_EXEC} -Qi $p | grep "Depends On" | sed 's/.*: //g; s/ / /g')
+
+ #Parse optional dependencies
+ PKGDEPS_OPT=$(${PACMAN_EXEC} -Qi $p | grep "Optional Deps" | sed 's/.*\s: //; s/ / /')
+
+ # Loop for each package ([@] means array value X)
+ # We circumvent a pacman bug/issue here
+ # pacman does a hard fixed listing for packages, meaning it doesn't recognize "provides" option
+ # This is mainly a problem of git package versions
+ #
+ if [[ $PKGDEPS_OPT != "None" ]]; then
+ echo -e "\nOptional dependencies for ${orange}$p${reset} :\n\n $PKGDEPS_OPT"
+ fi
+
+ if [[ $PKGDEPS != "None" ]]; then
+ echo -e "\nRequired dependencies for ${orange}$p${reset} :\n" # TODO go even one step deeper with these!
+
+ for i in $(echo "${PKGDEPS[@]}"); do
+
+ function parseversion() {
+ pattern="[<=>]"
+ if [[ $i =~ $pattern ]]; then
+ i=$(echo $i | awk -F'[<=>]' '{print $1}')
+ # TODO do version check here as done in 'risks' function?
+ #i_ver=$(echo $i | awk -F'[<=>]' '{print $3}')
+ #return $pkgname $pkgver
+ #else
+ #return $i
+ fi
+ }
+
+ parseversion
+ # Error (package was not found)
+ if [[ $(${PACMAN_EXEC} -Qi $i &>/dev/null || echo "was not found" | wc -l) -eq 1 ]]; then
+
+ # Get name of the package which provides the dependency
+ ALTDEP=$(${PACMAN_EXEC} -Qi | grep -iE "Name|Provides" | grep $i | grep "Name" | sed 's/.*: //')
+
+ o=0
+ for altdep in $ALTDEP; do
+ ALTDEPS[$o]=$altdep
+ let o++
+ done
+
+ function deepscan() {
+ MAINPKGFILES=$(${PACMAN_EXEC} -Qql $p)
+
+ for mainpkgfile in $MAINPKGFILES; do
+
+ if [[ $(mimetype "${mainpkgfile}" | grep -iE "x\-sharedlib|x\-executable" | wc -l) -eq 1 ]]; then
+
+ for deepscan in $(ldd "${mainpkgfile}" | awk '{print $3}' | sed '/^\s*$/d'); do
+ OWNER_DEEPSCAN=$(${PACMAN_EXEC} -Qo $deepscan | awk '{print $5}')
+
+ for item in "${ALTDEPS[@]}"; do
+
+ if [[ $OWNER_DEEPSCAN == "$item" ]]; then
+ i=$OWNER_DEEPSCAN
+ return 0
fi
- # Replace the current line (100 characters) with empty space and fill it with checkedlist value
- echo -e "\r$(for ((i = 0; i < 100; i++)); do echo -n ' '; done)\r${CHECKEDLIST[$i]}"
-
- # Go through all listed library & executable files
- for n in $(echo "${MIMEFILES[@]}"); do
-
- # Get count of all matching lines for a file. If no errors, this should return 1
- # Enable bash debugging with set -x and run it in subshell (otherwise we need to use set +x to disable debugging)
- # As debugging output is considered as STDERR (not default STDOUT), we pipe it with |&
- # Suppress ldd warning messages ("you have no permission") as they are not relevant here and delete empty lines
-
- LDDCMDCNT=$( (set -x; ldd $n |grep -i "not found") |& grep -E "$n|=> not found" | sed 's/.*warning.*//g; /^\s*$/d' | wc -l)
-
- # Get all lines for a file. If no errors, this should return only "++ ldd "
- LDDCMD=$( (set -x; ldd $n |grep -i "not found") |& grep -E "$n" | sed 's/.*warning.*//g; /^\s*$/d')
- LDDCMD_FILE=$(echo "$LDDCMD " | sed 's/++ ldd //g')
-
- # Basename doesn't accept empty/null parameters
- if [[ ! -z "${LDDCMD_FILE// }" ]]; then
- LDDCMD_FILE_BASENAME=$(basename $LDDCMD_FILE) # | sed "s/[-0-9.]*$//"
- fi
-
- # If we have match for "not found" messages, print the output
- if [[ $LDDCMDCNT -gt 1 ]]; then
- LIBNOTFOUND=true
- function checklocaldirs() {
- unset PKG
- for filepkgdir in $1; do
- #echo "Search dir is $filepkgdir Search term is $2"
- findfile=$(find "$filepkgdir" -maxdepth 1 -type f -iname "*$2*")
-
- if [[ -f $findfile ]]; then
- PKG="$(pacman -Qo $findfile | awk '{print $5 " " $6}')"
- return
- fi
- done
- }
-
- function checkrepopkgs() {
- unset PKG
- unset NIPKG
- REPOPKGS=$(pacman -Fs $1 | sed '2~2d' | awk -F '[/ ]' '{print $2}')
- if [[ ! -z $REPOPKGS ]]; then
- c=0
- for repopkg in $REPOPKGS; do
- t=0
- for repopkgfile in $(pacman -Fl "$repopkg" | awk '{print "/"$2}'); do
- if [[ -f $repopkgfile ]]; then
- REPOPKGFILES[$t]="$repopkgfile"
- let t++
- fi
- done
-
- if [ ! "${#REPOPKGFILES[@]}" -eq 0 ]; then
- for matchrepofile in "${REPOPKGFILES[@]}"; do
- if [[ "${matchrepofile}" == "${2}" ]]; then
- PKG=$repopkg
- return
- # else
- # if [[ $(pacman -Qo $matchrepofile | grep -o "owned by" | wc -w) -eq 2 ]]
- # PKG=$(echo "${REPOPKGS[*]}?" | tr '\n' ',' | sed 's/\,*$//g')
- # #return
- fi
- done
- unset REPOPKGFILES
- else
- #echo "do we get here $repopkg"
- if [[ $(pacman -Q $repopkg &>/dev/null || echo "was not found" | wc -l) -eq 1 ]]; then
- NIPKG[$c]="$repopkg"
- let c++
- fi
- #PKG="${red}N/A${reset}"
- fi
- done
- #PKG="${red}N/A${reset}"
- else
- PKG="${red}N/A${reset}"
- fi
- }
-
- checkrepopkgs $LDDCMD_FILE_BASENAME $LDDCMD_FILE
- # MAINPKG=$PKG
- #REPOPKG=$(pacman -Fs $(echo $n | awk '{print $NF}' FS=/) | sed '1!d' | awk -F '[/ ]' '{print $2}')
-
- #if [[ -z ${PKG} ]]; then
- # PKG="${red}N/A${reset}"
- # fi
-
- NOTFOUNDFILES=$( (set -x; ldd $n |grep -i "not found") |& grep -E "=> not found" | sed 's/ => not found//g; s/\s//g' | tr '\n' ' ' | sed 's/.*warning.*//g; /^\s*$/d')
-
- printf "\n %s %s\n" "${red}=>${reset} Missing or broken dependencies for" "${yellow}$LDDCMD_FILE${reset}"
- printf " %-38s%s\n" " Owned by system package:" "$(pacman -Qo $n | sed 's/.* by //g')"
- # if [[ ! $MAINPKG == *"N/A"* ]] || [[ ! -z "${NIPKG}" ]]; then
- # printf " %-38s%s\n" " Provided by..."
- # if [[ ! $MAINPKG == *"N/A"* ]]; then
- # printf " %-38s%s\n" " ...installed repo package(s):" "$MAINPKG"
- # fi
- if [[ ! -z "${NIPKG}" ]]; then
- printf " %-38s%s\n" " Provided by package(s):" "${NIPKG[*]}"
- # printf " %-38s%s\n" " ...non-installed repo package(s):" "${NIPKG[*]}"
- fi
- # fi
- printf "\n"
-
- # Set up a new array for r variables (libary files) and store printf output there.
- # This is just so that we don't need to check these library files again but instead
- # we can use a stored value. This is just to speed up processing.
- # TODO does this really work?
- r_count=0
- typeset -A RLIST
- for r in $(echo ${NOTFOUNDFILES[@]}); do
-
- if [[ ! ${RLIST[$r_count]} ]]; then
- checklocaldirs "${MAINPKGDIRS[*]}" $r #$r_basename
- if [[ -z ${PKG} ]]; then
- checklocaldirs "${LOCALDIRS[*]}" $r #$r_basename
- fi
- LIBPKG=$PKG
- RLIST[$r_count]=$(printf " %-47s%-30s%s\n" " ${red}Depends on${reset}:" "$r" "${blue}Provided by${reset}: $LIBPKG")
- fi
-
- echo "${RLIST[$r_count]}"
-
- #unset MAINPKG
- #unset PKG
- #r_basename=$(echo $r | sed "s/[-0-9.]*$//") # libicui18n.so.58.4 -> libicui18n.so
- #unset PKG
- #if [[ -z ${PKG} ]]; then
- # checkrepopkgs $r_basename
- #if [[ -z ${PKG} ]]; then
- # PKG="${red}N/A${reset}"
- #fi
- # fi
-
- #check_main $r_basename
- #checkrepopkgs $r_basename $r
-
- # if [[ -z ${PKG} ]]; then
- # PKG="N/A"
- # fi
- # for r_providers in $(pacman -Fs $r_basename | sed '2~2d' | awk -F '[/ ]' '{print $2}'); do
- # TODO
-
- #LIBPKG[0]=$(pacman -Fs $(echo $r | awk '{print $NF}' FS=/) | sed '1!d' | awk -F '[/ ]' '{print $2}')
- #LIBPKG=$(pacman -Fs $(echo $r | awk '{print $NF}' FS=/) | sed '1!d' | awk -F '[/ ]' '{print $2}')
- #LIBPKG=$(pacman -Fs $r | sed '1!d' | awk -F '[/ ]' '{print $2}')
- #if [[ "${#LIBPKG[@]}" -eq 0 ]]; then
-
- #if [[ $(echo $LIBPKG | wc -w) -eq 0 ]]; then
- # LIBPKG="N/A"
- #fi
-
- #printf " %-47s%-30s%s\n" " ${red}Depends on${reset}:" "$r" "${blue}Provided by${reset}: $LIBPKG"
-
- #unset LIBPKG
- #unset PKG
- #unset MAINPKG
- let r_count++
- done
- unset RLIST
-
- fi
- done
- unset MIMEFILES #Unset MIMEFILES array for the next dependency check
- else
- printf '%s\n' "${CHECKEDLIST[$i]}"
- fi
+ done
+
+ done
+ fi
done
- else
- echo -e "\n No dependencies for this package."
+ return 1
+ }
+
+ deepscan
+ if [[ $? -eq 1 ]]; then
+ #Get 'provides' from arch package database
+ FETCHEDPKGS=$(package-query --qprovides "$i" -Q -f "%n")
+ k=0
+
+ for fetch in $FETCHEDPKGS; do
+ if [[ ! $(${PACMAN_EXEC} -Q $fetch &>/dev/null || echo "was not found" | wc -l) -eq 1 ]]; then
+ i="$fetch"
+ break
+ # TODO show here the true 'depends on' stuff, not just 'provided by' package? bash <-> sh conversion for example
+ else
+ echo -e " ${yellow}Warning:${reset} Dependency '$i' not found and not recognized as a provided package"
+ i="notfound"
+ NOTFOUNDS[$k]=$i
+ let k++
+ fi
+ done
+ fi
fi
-
- if [[ ! -z "${NOTFOUNDS}" ]] || [[ $LIBNOTFOUND != true ]]; then
- echo -e "\n ${green}=>${reset} Dependencies checked. All ${green}OK${reset}.\n"
+
+ if [[ $i != "notfound" ]] && [[ -z ${CHECKEDLIST[$i]} ]]; then
+
+ FILES=$(${PACMAN_EXEC} -Qql $i)
+ x=0
+ printf " %-30s%s\r" "$i" "Searching libraries/executables"
+
+ for mimefile in $FILES; do
+
+ if [[ $(file --mime-type "${mimefile}" | grep -iE "executable" | wc -l) -eq 1 ]]; then
+ MIMEFILES[$x]="${mimefile}"
+ let x++
+ printf " %-30s%s\r" "$i" "Found libraries/executables: $x " #Yes, the trailing space is meant to be here
+ fi
+ done
+
+ if [[ $x -gt 0 ]]; then
+ CHECKEDLIST[$i]=$(printf " %-30s%s\n" "$i" "Found libraries/executables: $x")
+ else
+ CHECKEDLIST[$i]=$(printf " %-30s%s\n" "$i" "No libraries/executables")
+ fi
+
+ # Replace the current line (100 characters) with empty space and fill it with checkedlist value
+ echo -e "\r$(for ((i = 0; i < 100; i++)); do echo -n ' '; done)\r${CHECKEDLIST[$i]}"
+
+ # Go through all listed library & executable files
+ for n in $(echo "${MIMEFILES[@]}"); do
+
+ # Get count of all matching lines for a file. If no errors, this should return 1
+ # Enable bash debugging with set -x and run it in subshell (otherwise we need to use set +x to disable debugging)
+ # As debugging output is considered as STDERR (not default STDOUT), we pipe it with |&
+ # Suppress ldd warning messages ("you have no permission") as they are not relevant here and delete empty lines
+
+ escapechars="]["
+ n=$(echo "${n}" | sed -r 's/(['"$escapechars"'])/\\\1/g')
+
+ LDDCMDCNT=$( (set -x; ldd "${n}" |grep -i "not found") |& grep -E "${n}|=> not found" | sed 's/.*warning.*//g; /^\s*$/d' | wc -l)
+
+ # Get all lines for a file. If no errors, this should return only "++ ldd "
+ LDDCMD=$( (set -x; ldd "${n}" |grep -i "not found") |& grep -E "${n}" | sed 's/.*warning.*//g; /^\s*$/d')
+ LDDCMD_FILE=$(echo "$LDDCMD " | sed 's/++ ldd //g')
+
+ # Basename doesn't accept empty/null parameters
+ if [[ ! -z "${LDDCMD_FILE// }" ]]; then
+ LDDCMD_FILE_BASENAME=$(basename $LDDCMD_FILE) # | sed "s/[-0-9.]*$//"
+ fi
+
+ # If we have match for "not found" messages, print the output
+ if [[ $LDDCMDCNT -gt 1 ]]; then
+ LIBNOTFOUND=true
+
+ checkrepopkgs $LDDCMD_FILE_BASENAME $LDDCMD_FILE
+ # MAINPKG=$PKG
+ # REPOPKG=$(${PACMAN_EXEC} -Fs $(echo $n | awk '{print $NF}' FS=/) | sed '1!d' | awk -F '[/ ]' '{print $2}')
+
+ # if [[ -z ${PKG} ]]; then
+ # PKG="${red}N/A${reset}"
+ # fi
+
+ NOTFOUNDFILES=$( (set -x; ldd "${n}" |grep -i "not found") |& grep -E "=> not found" | sed 's/ => not found//g; s/\s//g' | tr '\n' ' ' | sed 's/.*warning.*//g; /^\s*$/d')
+
+ printf "\n %s %s\n" "${red}=>${reset} Missing or broken dependencies for" "${yellow}$LDDCMD_FILE${reset}"
+ printf " %-38s%s\n" " Owned by system package:" "$(${PACMAN_EXEC} -Qo "${n}" | sed 's/.* by //g')"
+
+ # if [[ ! $MAINPKG == *"N/A"* ]] || [[ ! -z "${NIPKG}" ]]; then
+
+ # printf " %-38s%s\n" " Provided by..."
+ # if [[ ! $MAINPKG == *"N/A"* ]]; then
+ # printf " %-38s%s\n" " ...installed repo package(s):" "$MAINPKG"
+ # fi
+
+ if [[ ! -z "${NIPKG}" ]]; then
+ printf " %-38s%s\n" " Provided by package(s):" "${NIPKG[*]}"
+ # printf " %-38s%s\n" " ...non-installed repo package(s):" "${NIPKG[*]}"
+ fi
+ # fi
+ printf "\n"
+
+ # Set up a new array for r variables (libary files) and store printf output there.
+ # This is just so that we don't need to check these library files again but instead
+ # we can use a stored value. This is just to speed up processing.
+ # TODO does this really work?
+
+ r_count=0
+ typeset -A RLIST
+
+ for r in $(echo ${NOTFOUNDFILES[@]}); do
+
+ if [[ ! ${RLIST[$r_count]} ]]; then
+ checklocaldirs "${MAINPKGDIRS[*]}" $r #$r_basename
+
+ if [[ -z ${PKG} ]]; then
+ checklocaldirs "${LOCALDIRS[*]}" $r #$r_basename
+ fi
+
+ LIBPKG=$PKG
+ RLIST[$r_count]=$(printf " %-47s%-30s%s\n" " ${red}Depends on${reset}:" "$r" "${blue}Provided by${reset}: $LIBPKG")
+
+ fi
+
+ echo "${RLIST[$r_count]}"
+
+ # unset MAINPKG
+ # unset PKG
+
+ # r_basename=$(echo $r | sed "s/[-0-9.]*$//") # libicui18n.so.58.4 -> libicui18n.so
+ # unset PKG
+
+ # if [[ -z ${PKG} ]]; then
+ # checkrepopkgs $r_basename
+ # if [[ -z ${PKG} ]]; then
+ # PKG="${red}N/A${reset}"
+ # fi
+ # fi
+
+ # check_main $r_basename
+ # checkrepopkgs $r_basename $r
+
+ # if [[ -z ${PKG} ]]; then
+ # PKG="N/A"
+ # fi
+
+ # for r_providers in $(${PACMAN_EXEC} -Fs $r_basename | sed '2~2d' | awk -F '[/ ]' '{print $2}'); do
+ # TODO
+
+ # LIBPKG[0]=$(${PACMAN_EXEC} -Fs $(echo $r | awk '{print $NF}' FS=/) | sed '1!d' | awk -F '[/ ]' '{print $2}')
+ # LIBPKG=$(${PACMAN_EXEC} -Fs $(echo $r | awk '{print $NF}' FS=/) | sed '1!d' | awk -F '[/ ]' '{print $2}')
+ # LIBPKG=$(${PACMAN_EXEC} -Fs $r | sed '1!d' | awk -F '[/ ]' '{print $2}')
+ # if [[ "${#LIBPKG[@]}" -eq 0 ]]; then
+
+ # if [[ $(echo $LIBPKG | wc -w) -eq 0 ]]; then
+ # LIBPKG="N/A"
+ # fi
+
+ # printf " %-47s%-30s%s\n" " ${red}Depends on${reset}:" "$r" "${blue}Provided by${reset}: $LIBPKG"
+
+ # unset LIBPKG
+ # unset PKG
+ # unset MAINPKG
+
+ let r_count++
+ done
+
+ unset RLIST
+
+ fi
+ done
+ unset MIMEFILES #Unset MIMEFILES array for the next dependency check
else
- echo -e "\n ${red}=>${reset} Dependency problems discovered. See above messages for details.\n"
+ printf '%s\n' "${CHECKEDLIST[$i]}"
fi
- unset NOTFOUNDS
- unset LIBNOTFOUND
-
+ done
+ else
+ echo -e "\n No dependencies for this package."
fi
-let curpkgcount++
+
+ if [[ ! -z "${NOTFOUNDS}" ]] || [[ $LIBNOTFOUND != true ]]; then
+ echo -e "\n ${green}=>${reset} Dependencies checked. All ${green}OK${reset}.\n"
+ else
+ echo -e "\n ${red}=>${reset} Dependency problems discovered. See above messages for details.\n"
+ fi
+ unset NOTFOUNDS
+ unset LIBNOTFOUND
+
+ fi
+ let curpkgcount++
done
diff --git a/tools/pkginfo.sh b/tools/pkginfo.sh
index 00856cc..79d41c1 100755
--- a/tools/pkginfo.sh
+++ b/tools/pkginfo.sh
@@ -1,28 +1,45 @@
-#!/bin/bash
+#!/usr/bin/env bash
+#
+# pkginfo - Gather package information with pacman on Arch Linux
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
-#################################
-# Gather some package information with pacman on Arch Linux
+#####################################
FILETHRESHOLD=100
+PACMAN_EXEC="/usr/bin/pacman"
if [[ $2 == "local" ]]; then
- pacman -Qi $1
+ ${PACMAN_EXEC} -Qi $1
if [[ $3 == "files" ]]; then
- if [[ $(pacman -Ql $1 | wc -l) -gt $FILETHRESHOLD ]]; then
- echo "Package $1 has $(pacman -Ql $1 | wc -l) files/dirs"
+ if [[ $(${PACMAN_EXEC} -Qql $1 | wc -l) -gt $FILETHRESHOLD ]]; then
+ echo "Package $1 has $(pacman -Qql $1 | wc -l) files/dirs"
sleep 3
- pacman -Ql $1 | less
+ ${PACMAN_EXEC} -Qql $1 | less
fi
fi
elif [[ $2 == "remote" ]]; then
- pacman -Si $1
+ ${PACMAN_EXEC} -Si $1
if [[ $3 == "files" ]]; then
- if [[ $(pacman -Ql $1 | wc -l) -gt $FILETHRESHOLD ]]; then
- echo "Package $1 has $(pacman -Ql $1 | wc -l) files/dirs"
+ if [[ $(${PACMAN_EXEC} -Qql $1 | wc -l) -gt $FILETHRESHOLD ]]; then
+ echo "Package $1 has $(pacman -Qql $1 | wc -l) files/dirs"
sleep 3
- pacman -Ql $1 | less
+ ${PACMAN_EXEC} -Qql $1 | less
fi
fi
else
- echo -e "Input: sh pkginfo.sh [local/remote] [files]\n"
+ echo -e "Input: sh pkginfo.sh [local/remote] [optional arg:files]\n"
fi
diff --git a/tools/pkgstr.sh b/tools/pkgstr.sh
deleted file mode 100755
index 5154a9b..0000000
--- a/tools/pkgstr.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/bash
-
-###########################################################
-# Search a text pattern inside package files
-read -r -p "Enter search pattern: " TEXT
-
-if [[ -z $TEXT ]]; then
- echo -e "\nInvalid input\n"
- exit
-else
-
- for p in $(echo "${@}"); do
-
- echo -e " \033[1m\033[92m=>\033[39m\033[0m Files of package '$p' containing pattern '$TEXT':\n"
-
- for i in $(pacman -Ql $p | awk -F ' ' '{print $NF}' | sed '/\/*.*\/$/d'); do
- sudo grep -Ril "$TEXT" $i
- done
- done
-fi
diff --git a/tools/psns.sh b/tools/psns.sh
index 0166571..ba26fd7 100755
--- a/tools/psns.sh
+++ b/tools/psns.sh
@@ -1,4 +1,23 @@
-#!/bin/env sh
+#!/usr/bin/env bash
+#
+# psns - List processes, their users and PIDs and their namespace name in current Linux namespaces
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
+
+#####################################
NAMESPACES=( $(ls /run/netns) )
diff --git a/tools/rmpkgfiles.sh b/tools/rmpkgfiles.sh
deleted file mode 100755
index 072c9bc..0000000
--- a/tools/rmpkgfiles.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/bash
-
-################################
-# Remove build-time files after program compilation on Arch Linux
-#
-if [ ! -e ./PKGBUILD ] && [ ! -d ./{src,pkg} ]; then #We check whether PKGBUILD file and src,pkg directories exist. If no, then...
- echo -e "Nothing to be removed\n"
- exit
-else
- rm -Rf ./{src,pkg,packages,community,*tar.xz} #tar.xz file may or may not exist
-fi
diff --git a/tools/showpkg.sh b/tools/showpkg.sh
index cb09254..c17c769 100755
--- a/tools/showpkg.sh
+++ b/tools/showpkg.sh
@@ -1,16 +1,33 @@
-#!/bin/bash
+#!/usr/bin/env bash
+#
+# showpkg - Show specific package version - installed and available version
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
+
+#####################################
-###########################################################
-# Show specific package, installed and available version
echo ""
-PKGMGR="pacman"
+PACMAN_EXEC="/usr/bin/pacman"
for p in $(echo "${@}"); do
-
- INSTALLDATE=$($PKGMGR -Qi $p | grep "Install Date" | awk -F ': ' '{print $2}')
- NEWDATE=$($PKGMGR -Si $p | grep "Build Date" | awk -F ': ' '{print $2}')
- echo "Installed: $($PKGMGR -Q $p) ($INSTALLDATE)"
- echo $($PKGMGR -Si $p | grep -E "Version.*:|Build Date.*:" | awk -F ': ' '{print $2}') | awk -v pkg=$p -F ' ' '{print "Available: " pkg " " $1 " ("substr($0,length($1)+1)")"}' | sed 's/( /(/g'
+
+ INSTALLDATE=$(${PACMAN_EXEC} -Qi $p | grep "Install Date" | awk -F ': ' '{print $2}')
+ NEWDATE=$(${PACMAN_EXEC} -Si $p | grep "Build Date" | awk -F ': ' '{print $2}')
+ echo "Installed: $(${PACMAN_EXEC} -Q $p) ($INSTALLDATE)"
+ echo $(${PACMAN_EXEC} -Si $p | grep -E "Version.*:|Build Date.*:" | awk -F ': ' '{print $2}') | awk -v pkg=$p -F ' ' '{print "Available: " pkg " " $1 " ("substr($0,length($1)+1)")"}' | sed 's/( /(/g'
echo ""
#echo -e "Available: $p $($PKGMGR -Si $p | grep "Version.*:" | awk -F ' ' '{print $3}')\n"
done
diff --git a/tools/specialchars.sh b/tools/specialchars.sh
index f433582..d26354e 100755
--- a/tools/specialchars.sh
+++ b/tools/specialchars.sh
@@ -1,4 +1,12 @@
-#!/bin/bash
+#!/usr/bin/env bash
+
+# specialchars - Show special characters which need to be escaped in shell
+
+# Author: codeforester
+# https://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-in-bash-how-do-we-know-it/44581064#44581064
+
+#####################################
+
special=$'`!@#$%^&*()-_+={}|[]\\;\':",.<>?/ '
for ((i=0; i < ${#special}; i++)); do
char="${special:i:1}"
@@ -9,6 +17,3 @@ for ((i=0; i < ${#special}; i++)); do
printf 'No - character %s does not need to be escaped\n' "$char"
fi
done | sort
-
-# Author: codeforester
-# https://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-in-bash-how-do-we-know-it/44581064#44581064
diff --git a/tools/ssh_timezone.sh b/tools/ssh_timezone.sh
index 578d301..7f47fae 100755
--- a/tools/ssh_timezone.sh
+++ b/tools/ssh_timezone.sh
@@ -1,6 +1,7 @@
-#!/bin/bash
-
-# SSH timezone - Retrieve timezone information for SSH users
+#!/usr/bin/env bash
+#
+# SSH timezone - Automatically retrieve timezone information for SSH users
+#
# Copyright (C) 2018 Pekka Helenius
#
# This program is free software: you can redistribute it and/or modify
@@ -16,16 +17,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-##############################################################################
+#####################################
# This script is meant to be used as a part of provided 'bash.custom' file
-##############################################################################
+#####################################
REQ_PKGS=(geoip2-database mmdblookup systemd openssh bind-tools)
+PACMAN_EXEC="/usr/bin/pacman"
for pkg in ${REQ_PKGS[*]}; do
- if [[ ! $(pacman -Q | grep $pkg) ]]; then
+ if [[ ! $("${PACMAN_EXEC}" -Q | grep $pkg) ]]; then
echo -e "\nMissing package $pkg\n"
kill -INT $$
fi
diff --git a/tools/tputcolors.sh b/tools/tputcolors.sh
index 2050f77..bf95861 100755
--- a/tools/tputcolors.sh
+++ b/tools/tputcolors.sh
@@ -1,8 +1,11 @@
-#!/bin/bash
+#!/usr/bin/env bash
-# Source: https://unix.stackexchange.com/questions/269077/tput-setaf-color-table-how-to-determine-color-codes
+# tputcolors - Display shell colors
# Author: user79743
+# Source: https://unix.stackexchange.com/questions/269077/tput-setaf-color-table-how-to-determine-color-codes
+
+#####################################
color(){
for c; do
diff --git a/tools/whichcmd.sh b/tools/whichcmd.sh
index b630b1b..8212dba 100755
--- a/tools/whichcmd.sh
+++ b/tools/whichcmd.sh
@@ -1,4 +1,23 @@
-#!/bin/env sh
+#!/usr/bin/env sh
+#
+# whichcmd - Find available commands in PATH by input syntax
+#
+# Copyright (C) 2021 Pekka Helenius
+#
+# This program 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 2 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 .
+
+#####################################
if [[ ${1} == "-h" ]] || [[ ${1} == "--help" ]] || [[ -z ${1} ]]; then
echo "
diff --git a/tools/whichport.c b/tools/whichport.c
index e0928df..93f7253 100644
--- a/tools/whichport.c
+++ b/tools/whichport.c
@@ -1,3 +1,22 @@
+/*
+ whichport - Which TCP/UDP port number is associated with an application protocol
+
+ Copyright (C) 2021 Pekka Helenius
+
+ This program 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 2 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 .
+*/
+
#include
#include
#include
diff --git a/tools/whichservice.c b/tools/whichservice.c
index 2cded1d..32848ce 100644
--- a/tools/whichservice.c
+++ b/tools/whichservice.c
@@ -1,3 +1,22 @@
+/*
+ whichservice - Which application protocol is associated with a TCP/UDP port number
+
+ Copyright (C) 2021 Pekka Helenius
+
+ This program 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 2 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 .
+*/
+
#include
#include
#include