Browse Source

Update tools: add headers, minor fixes, refactor stuff

master
Pekka Helenius 3 years ago
parent
commit
61167b4ce8
29 changed files with 854 additions and 601 deletions
  1. +24
    -27
      tools/PKGBUILD
  2. +11
    -11
      tools/archrisks.sh
  3. +20
    -3
      tools/bininfo.sh
  4. +22
    -4
      tools/buildpkg.sh
  5. +19
    -3
      tools/deltmpfiles.sh
  6. +21
    -4
      tools/extract.sh
  7. +20
    -5
      tools/findinpkg.sh
  8. +19
    -3
      tools/findmatch.sh
  9. +22
    -6
      tools/findpkg.sh
  10. +36
    -18
      tools/genmac.sh
  11. +4
    -2
      tools/getsource.sh
  12. +0
    -15
      tools/installlocal.sh
  13. +20
    -1
      tools/killns.sh
  14. +4
    -4
      tools/killprocess.sh
  15. +0
    -5
      tools/listpkg.sh
  16. +20
    -4
      tools/missinglibs.sh
  17. +32
    -29
      tools/nowner.sh
  18. +405
    -391
      tools/pkgdeps.sh
  19. +29
    -12
      tools/pkginfo.sh
  20. +0
    -20
      tools/pkgstr.sh
  21. +20
    -1
      tools/psns.sh
  22. +0
    -11
      tools/rmpkgfiles.sh
  23. +26
    -9
      tools/showpkg.sh
  24. +9
    -4
      tools/specialchars.sh
  25. +8
    -6
      tools/ssh_timezone.sh
  26. +5
    -2
      tools/tputcolors.sh
  27. +20
    -1
      tools/whichcmd.sh
  28. +19
    -0
      tools/whichport.c
  29. +19
    -0
      tools/whichservice.c

+ 24
- 27
tools/PKGBUILD View File

@ -19,7 +19,7 @@ url="https://github.com/Fincer/archtools"
arch=(any) arch=(any)
license=(GPL) license=(GPL)
depends=(coreutils bash grep sed 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 perl # findpkg.sh, genmac.sh
wget # getsource.sh wget # getsource.sh
file # nowner.sh file # nowner.sh
@ -42,18 +42,14 @@ genmac.sh
getsource.sh # TODO: More implementation needed. See the file for details getsource.sh # TODO: More implementation needed. See the file for details
nowner.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 pkgdeps.sh # TODO: More implementation needed. See the file for details
pkgstr.sh
archrisks.sh archrisks.sh
showpkg.sh showpkg.sh
deltmpfiles.sh deltmpfiles.sh
missinglibs.sh missinglibs.sh
installlocal.sh
buildpkg.sh buildpkg.sh
pkginfo.sh pkginfo.sh
bininfo.sh bininfo.sh
listpkg.sh
killprocess.sh killprocess.sh
rmpkgfiles.sh
specialchars.sh specialchars.sh
whichcmd.sh whichcmd.sh
killns.sh killns.sh
@ -69,28 +65,29 @@ if [[ $server_environment == "true" ]]; then
source+=(ssh_timezone.sh) source+=(ssh_timezone.sh)
fi 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' '93ee0e990f36a5641e4f9fb4ba851e3db47ff6f01fdfad8dd169b83c546ecae9'
'40fd211e7b4a21ca61be81a809ee47f58adc6cd220218a20a0c7e65e1534c6ca') '40fd211e7b4a21ca61be81a809ee47f58adc6cd220218a20a0c7e65e1534c6ca')


+ 11
- 11
tools/archrisks.sh View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/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 # 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 # 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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
######################################################################################################################
#####################################
red=$'\33[91m' red=$'\33[91m'
orange=$'\033[38;5;208m' orange=$'\033[38;5;208m'
@ -37,8 +37,8 @@ typeset -A ARCH_MANAGERS
# <root=requires root, no_root=does not require root> # <root=requires root, no_root=does not require root>
# " # "
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" # [2,yaourt]="-Syy|-Qi|-Q|-Si|no_root"
# [3,pikaur]="-Syy|-Qi|-Q|-Si|no_root" # [3,pikaur]="-Syy|-Qi|-Q|-Si|no_root"
# [4,pacget]="-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})." echo "Unknown sorting order selected (${sort_order})."
helpCaller helpCaller
esac esac
if [[ ${input_count} -eq 2 ]]; then if [[ ${input_count} -eq 2 ]]; then
case ${input_2} in case ${input_2} in
"--reverse") "--reverse")
@ -271,7 +271,7 @@ function runTool() {
col4="${reset}Newer package installed" col4="${reset}Newer package installed"
break break
fi fi
let s++ let s++
done done
fi fi
@ -283,7 +283,7 @@ function runTool() {
let prs_count++ let prs_count++
let i++ let i++
done done
echo -e "\e[1m" echo -e "\e[1m"
@ -312,11 +312,11 @@ function runTool() {
# echo "Unknown sorting order selected. Exiting." # echo "Unknown sorting order selected. Exiting."
# exit 1 # exit 1
esac esac
if [[ ${sort_reverse} == 1 ]]; then if [[ ${sort_reverse} == 1 ]]; then
sort_params+=("-r") sort_params+=("-r")
fi fi
i=0 i=0
for line in $(echo "${risk_entries[*]}" | sort ${sort_params[*]} -t'|' ${sort_column}); do for line in $(echo "${risk_entries[*]}" | sort ${sort_params[*]} -t'|' ${sort_column}); do


+ 20
- 3
tools/bininfo.sh View File

@ -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 <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
##################################### #####################################
# Show information about executable on Arch Linux
BIN=$(which $1) BIN=$(which $1)
echo -e "$BIN\n$(pacman -Qo $BIN)"
echo -e "$BIN\n$(/usr/bin/pacman -Qo $BIN)"

+ 22
- 4
tools/buildpkg.sh View File

@ -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 <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
#####################################
# Requires package: pacman-contrib
if [ ! -e ./PKGBUILD ]; then #We check whether PKGBUILD file exists. If no, then... if [ ! -e ./PKGBUILD ]; then #We check whether PKGBUILD file exists. If no, then...
echo -e "No PKGBUILD file found!\n" echo -e "No PKGBUILD file found!\n"
return 1 return 1


+ 19
- 3
tools/deltmpfiles.sh View File

@ -1,7 +1,23 @@
#!/bin/bash
#!/usr/bin/env bash
#
# deltmpfiles - Delete current temporary files from pre-defined locations
#
# Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
###########################################################
# Delete current temporary files
#####################################
#All tmp files currently being used #All tmp files currently being used
TMP_USED=$(lsof +D /tmp/ | awk '{print $9," "}' | sort -u | tail -n+3 | sed 's/[ \t]*$//') TMP_USED=$(lsof +D /tmp/ | awk '{print $9," "}' | sort -u | tail -n+3 | sed 's/[ \t]*$//')


+ 21
- 4
tools/extract.sh View File

@ -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 <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
#####################################
###########################################################
#Extract wide range of various archive types
if [ -z "$1" ]; then if [ -z "$1" ]; then
# display usage if no parameters given # display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>" echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
@ -12,7 +29,7 @@ else
do do
if [ -f "$n" ] ; then if [ -f "$n" ] ; then
case "${n%,}" in 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" ;; tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;; *.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;; *.bz2) bunzip2 ./"$n" ;;


+ 20
- 5
tools/findinpkg.sh View File

@ -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 <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
#####################################
function help() { function help() {
echo -e "Usage: findinpkg <pkgname> <pattern-to-search>" echo -e "Usage: findinpkg <pkgname> <pattern-to-search>"


+ 19
- 3
tools/findmatch.sh View File

@ -1,7 +1,23 @@
#!/bin/bash
#!/usr/bin/env bash
#
# findmatch - Grep/List matching strings in a specific folder
#
# Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
###########################################################
# Grep/List matching strings in a specific folder
#####################################
if [ -z "$1" ]; then if [ -z "$1" ]; then
$1=/ #If folder not specified, then we use root folder as a starting path $1=/ #If folder not specified, then we use root folder as a starting path


+ 22
- 6
tools/findpkg.sh View File

@ -1,7 +1,23 @@
#!/bin/bash
#!/usr/bin/env bash
#
# findpkg - Search package in official Arch Linux repositories
#
# Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
##################################################
# Search package in online repositories
#####################################
if [ -z "$1" ] ; then if [ -z "$1" ] ; then
echo "Usage: findpkg <string>" echo "Usage: findpkg <string>"
@ -10,8 +26,8 @@ else
# #
# pacman: find packages which include/refer to user input string $1 by using online repositories. Verbose order # 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 # 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 # 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 # 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 # 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 fi
echo -e '\e[0m' echo -e '\e[0m'

+ 36
- 18
tools/genmac.sh View File

@ -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 <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
#####################################
# Randomize MAC Address
trap ctrl_c INT trap ctrl_c INT
function ctrl_c() { function ctrl_c() {
@ -14,7 +32,7 @@ random_mac() {
insert_mac() { insert_mac() {
echo -e "\nChanging MAC address information (root permission required).\n" echo -e "\nChanging MAC address information (root permission required).\n"
sudo sed -i "/\[Link\]/!b;n;cMACAddress=$MAC" /etc/systemd/network/00-default.link 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" 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 return 0
@ -23,11 +41,11 @@ insert_mac() {
geninsert_mac() { geninsert_mac() {
gennew_mac() { gennew_mac() {
while true; do while true; do
unset response unset response
read -r -p "Generate a new MAC address? [Y/n] " response read -r -p "Generate a new MAC address? [Y/n] " response
if [[ $(echo $response | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then if [[ $(echo $response | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
random_mac random_mac
newname_mac newname_mac
@ -41,7 +59,7 @@ geninsert_mac() {
newname_mac() { newname_mac() {
unset response unset response
read -r -p "New MAC address for '$MAC_DEVICE' will be '$MAC'. Accept? [Y/n] " 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 if [[ $(echo $response | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
insert_mac insert_mac
else else
@ -56,21 +74,21 @@ gen_mac() {
real_mac() { real_mac() {
AVAILABLE_MACS=$(ip -br link show | sed '/LOOPBACK/d' | awk '{print NR"\t"$1"\t"$3"\t"$2}') AVAILABLE_MACS=$(ip -br link show | sed '/LOOPBACK/d' | awk '{print NR"\t"$1"\t"$3"\t"$2}')
IFS=$'\n' IFS=$'\n'
echo -e "\nAvailable network interfaces with their MAC addresses are:\n\n${AVAILABLE_MACS[*]}" 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" echo -e "\nPlease select the interface which MAC address you want to spoof of\n"
read -r -p "Selection [number]: " number read -r -p "Selection [number]: " number
if [[ ! $number =~ ^[0-9]+$ ]]; then if [[ ! $number =~ ^[0-9]+$ ]]; then
echo -e "\nInvalid input value. Aborting.\n" echo -e "\nInvalid input value. Aborting.\n"
return 1 return 1
fi fi
for INTERFACE in $(echo -e "${AVAILABLE_MACS[*]}"); do for INTERFACE in $(echo -e "${AVAILABLE_MACS[*]}"); do
intf_num=$(echo $INTERFACE | awk '{print $1}') intf_num=$(echo $INTERFACE | awk '{print $1}')
if [[ $number -eq $intf_num ]]; then if [[ $number -eq $intf_num ]]; then
@ -91,8 +109,8 @@ gen_mac() {
real_mac real_mac
PREV_CONF=$(grep -Ril "$MAC_REAL" /etc/systemd/network/) 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" echo -e "\nUsing existing configuration file for interface '$MAC_DEVICE':\n$PREV_CONF\n"
linkname=$(basename $PREV_CONF) linkname=$(basename $PREV_CONF)
MAC_OLD=$(awk -F= '/\[Link\]/{getline; print $2}' $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 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 [[ $linkname =~ ^[0-9][0-9]-default.link ]]; then
if [[ ! $(sudo -n true) ]]; then if [[ ! $(sudo -n true) ]]; then
sudo echo "" sudo echo ""
fi fi
echo -e "[Match]\nMACAddress=$MAC_REAL\n\n[Link]\nMACAddress=$MAC_REAL\nNamePolicy=kernel database onboard slot path" \ 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 | sudo tee /etc/systemd/network/$linkname > /dev/null
echo -e "Created new configuration file: /etc/systemd/network/$linkname\n" echo -e "Created new configuration file: /etc/systemd/network/$linkname\n"
else else
echo -e "\nInvalid file name given. Aborting.\n" echo -e "\nInvalid file name given. Aborting.\n"
@ -125,13 +143,13 @@ gen_mac() {
random_mac random_mac
geninsert_mac geninsert_mac
else else
if [[ $(echo $response | sed 's/ //g') =~ ^([nN][oO]|[nN])$ ]]; then 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 read -r -p "Please type a new MAC address (Syntax is e.g. aa:bb:33:zz:f0:4a): " MAC
maxtries=5 maxtries=5
while [[ $maxtries -gt 0 ]]; do while [[ $maxtries -gt 0 ]]; do
case "$MAC" in
case "$MAC" in
[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]) [[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]])
insert_mac insert_mac
;; ;;


+ 4
- 2
tools/getsource.sh View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/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 <pekka.helenius@fjordtek.com> # Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
# #
@ -16,7 +16,9 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################
# TODO: Add support for wider range of processor architectures # TODO: Add support for wider range of processor architectures
# TODO: Add directory support (e.g. getsource wine ~/winesource) # TODO: Add directory support (e.g. getsource wine ~/winesource)
# TODO: create subdir for source files automatically to the current main dir # TODO: create subdir for source files automatically to the current main dir


+ 0
- 15
tools/installlocal.sh View File

@ -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

+ 20
- 1
tools/killns.sh View File

@ -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 <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
#####################################
if [[ ${1} =~ ^(\-h|\-\-help)$ ]] || [[ -z ${1} ]]; then if [[ ${1} =~ ^(\-h|\-\-help)$ ]] || [[ -z ${1} ]]; then
echo " echo "


+ 4
- 4
tools/killprocess.sh View File

@ -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 ps aux | grep $1 > /dev/null
mypid=$(pidof $1) mypid=$(pidof $1)
if [ "$mypid" != "" ]; then if [ "$mypid" != "" ]; then


+ 0
- 5
tools/listpkg.sh View File

@ -1,5 +0,0 @@
#!/bin/bash
###########################################################
# Show packages named as <input> on Arch Linux
pacman -Q | grep "$1" | cut -d' ' -f1

+ 20
- 4
tools/missinglibs.sh View File

@ -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 <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
###########################################################
# 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"

+ 32
- 29
tools/nowner.sh View File

@ -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 <pekka.helenius@fjordtek.com>
# #
# 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 <https://www.gnu.org/licenses/>.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###########################################################
#####################################
bash_yellow=$'\033[93m' bash_yellow=$'\033[93m'
bash_red=$'\033[91m' bash_red=$'\033[91m'
bash_color_default=$'\033[0m' bash_color_default=$'\033[0m'
###########################################################
PACMAN_EXEC="/usr/bin/pacman"
#####################################
#Useful for additional commands: #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 #find /usr/share -maxdepth 1 -type d -exec stat --format "%n: %U" {} \; | grep fincer
###########################################################
#####################################
# Check for command dependencies # Check for command dependencies
if [[ $(which --help 2>/dev/null) ]] && [[ $(echo --help 2>/dev/null) ]]; then if [[ $(which --help 2>/dev/null) ]] && [[ $(echo --help 2>/dev/null) ]]; then
@ -53,7 +56,7 @@ else
exit 1 exit 1
fi fi
###########################################################
#####################################
# Retrieve our Linux distribution and set the correct # Retrieve our Linux distribution and set the correct
# package manager for this command # package manager for this command
@ -68,12 +71,12 @@ function check_pkgmgr() {
fi fi
} }
##############################
#####################################
# Arch Linux # Arch Linux
if [[ $DISTRO == "Arch" ]]; then if [[ $DISTRO == "Arch" ]]; then
check_pkgmgr pacman 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 fi
# Debian, Ubuntu # Debian, Ubuntu
@ -94,9 +97,9 @@ fi
# OpenSUSE # OpenSUSE
# TODO # TODO
###########################################################
#####################################
# List files and directories which are not owned by any package in the system # 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 # Avoid storing log files into root home
REAL_USER=$(who am i | awk '{print $1}') REAL_USER=$(who am i | awk '{print $1}')
@ -151,7 +154,7 @@ else
unset response unset response
##############################
#####################################
BASEDIR_OWNER=$(stat --format "%u" "${BASEDIR}") 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" 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 fi
##############################
#####################################
BASEDIR_UNDERLINE="$(echo ${BASEDIR} | sed 's/\//_/g')" BASEDIR_UNDERLINE="$(echo ${BASEDIR} | sed 's/\//_/g')"
LOGFILE="$REAL_USER_HOME/nowner-${BASEDIR_UNDERLINE}-depth-${DEPTH_NUM}_$(date +%Y-%m-%d).log" LOGFILE="$REAL_USER_HOME/nowner-${BASEDIR_UNDERLINE}-depth-${DEPTH_NUM}_$(date +%Y-%m-%d).log"
@ -190,11 +193,11 @@ else
TO_FILE=0 TO_FILE=0
fi fi
##############################
#####################################
echo -e "\nSearching unowned files & folders in $depthstr\n" echo -e "\nSearching unowned files & folders in $depthstr\n"
##############################
#####################################
function data_counter() { function data_counter() {
i=0 i=0
@ -241,7 +244,7 @@ else
} }
##############################
#####################################
function data_check() { function data_check() {
@ -293,7 +296,7 @@ else
unset VALID_DATASET unset VALID_DATASET
} }
##############################
#####################################
function folders() { function folders() {
type="folders" type="folders"
@ -309,7 +312,7 @@ else
data_check "${find_type}" $data_name data_check "${find_type}" $data_name
} }
##############################
#####################################
if [[ $TO_FILE -eq 1 ]]; then 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 echo -e "Log timestamp: $(date '+%d-%m-%Y, %X') (TZ: $(timedatectl status | grep "Time zone:" | awk '{print $3}'))\nComputer: $(hostname)\nScanning Depth: $depthstr" >> $LOGFILE


+ 405
- 391
tools/pkgdeps.sh View File

@ -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 <pekka.helenius@fjordtek.com>
# #
# This program is free software: you can redistribute it and/or modify # 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 # 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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
######################################################################################################################
#####################################
# TODO print stored dependency packages as red if errors encountered # TODO print stored dependency packages as red if errors encountered
# TODO check packages themselves, too (not only their dependencies...) # 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...<package>?...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 <package>?' code logic, when the following occurs:
# Error: octopi not found. Skipping.
# ------------------------------------------- # -------------------------------------------
# BUG # 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 # Look for missing library files for installed packages
red=$'\33[91m' red=$'\33[91m'
@ -85,379 +43,435 @@ blue=$'\033[94m'
bold=$'\033[1m' bold=$'\033[1m'
reset=$'\033[0m' reset=$'\033[0m'
PACMAN_EXEC="/usr/bin/pacman"
LOGFILE="/var/log/pacman.log"
COMMANDS=(sudo pacman date ping package-query) COMMANDS=(sudo pacman date ping package-query)
for com in $COMMANDS; do 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 done
echo -e "\n${bold}Dependency tracker - Find broken executables & libraries${reset}" 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 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() { 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 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 else
echo -e "\nPrevious database update timestamp not found. Updating...\n"
checkconnection
echo -e "\nSkipping database update.\n"
fi fi
else
echo -e "\nPackage databases are updated.\n"
fi
else
echo -e "\nPrevious database update timestamp not found. Updating...\n"
checkconnection
fi fi
fi
elif [[ ! -f $LOGFILE ]]; then 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 fi
pkgcount=$# pkgcount=$#
curpkgcount=1 curpkgcount=1
typeset -A CHECKEDLIST typeset -A CHECKEDLIST
# Loop through all input arguments (package names) # Loop through all input arguments (package names)
for p in $(echo "${@}"); do # TODO show how many dependencies this package has if more than 1 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 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 <filename>"
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 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 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 <filename>"
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 else
echo -e "\n ${red}=>${reset} Dependency problems discovered. See above messages for details.\n"
printf '%s\n' "${CHECKEDLIST[$i]}"
fi fi
unset NOTFOUNDS
unset LIBNOTFOUND
done
else
echo -e "\n No dependencies for this package."
fi 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 done

+ 29
- 12
tools/pkginfo.sh View File

@ -1,28 +1,45 @@
#!/bin/bash
#!/usr/bin/env bash
#
# pkginfo - Gather package information with pacman on Arch Linux
#
# Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
#################################
# Gather some package information with pacman on Arch Linux
#####################################
FILETHRESHOLD=100 FILETHRESHOLD=100
PACMAN_EXEC="/usr/bin/pacman"
if [[ $2 == "local" ]]; then if [[ $2 == "local" ]]; then
pacman -Qi $1
${PACMAN_EXEC} -Qi $1
if [[ $3 == "files" ]]; then 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 sleep 3
pacman -Ql $1 | less
${PACMAN_EXEC} -Qql $1 | less
fi fi
fi fi
elif [[ $2 == "remote" ]]; then elif [[ $2 == "remote" ]]; then
pacman -Si $1
${PACMAN_EXEC} -Si $1
if [[ $3 == "files" ]]; then 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 sleep 3
pacman -Ql $1 | less
${PACMAN_EXEC} -Qql $1 | less
fi fi
fi fi
else else
echo -e "Input: sh pkginfo.sh <package> [local/remote] [files]\n"
echo -e "Input: sh pkginfo.sh <package> [local/remote] [optional arg:files]\n"
fi fi

+ 0
- 20
tools/pkgstr.sh View File

@ -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

+ 20
- 1
tools/psns.sh View File

@ -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 <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
#####################################
NAMESPACES=( $(ls /run/netns) ) NAMESPACES=( $(ls /run/netns) )


+ 0
- 11
tools/rmpkgfiles.sh View File

@ -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

+ 26
- 9
tools/showpkg.sh View File

@ -1,16 +1,33 @@
#!/bin/bash
#!/usr/bin/env bash
#
# showpkg - Show specific package version - installed and available version
#
# Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
#####################################
###########################################################
# Show specific package, installed and available version
echo "" echo ""
PKGMGR="pacman"
PACMAN_EXEC="/usr/bin/pacman"
for p in $(echo "${@}"); do 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 ""
#echo -e "Available: $p $($PKGMGR -Si $p | grep "Version.*:" | awk -F ' ' '{print $3}')\n" #echo -e "Available: $p $($PKGMGR -Si $p | grep "Version.*:" | awk -F ' ' '{print $3}')\n"
done done

+ 9
- 4
tools/specialchars.sh View File

@ -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=$'`!@#$%^&*()-_+={}|[]\\;\':",.<>?/ ' special=$'`!@#$%^&*()-_+={}|[]\\;\':",.<>?/ '
for ((i=0; i < ${#special}; i++)); do for ((i=0; i < ${#special}; i++)); do
char="${special:i:1}" 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" printf 'No - character %s does not need to be escaped\n' "$char"
fi fi
done | sort done | sort
# Author: codeforester
# https://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-in-bash-how-do-we-know-it/44581064#44581064

+ 8
- 6
tools/ssh_timezone.sh View File

@ -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 # Copyright (C) 2018 Pekka Helenius
# #
# This program is free software: you can redistribute it and/or modify # 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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
##############################################################################
#####################################
# This script is meant to be used as a part of provided 'bash.custom' file # This script is meant to be used as a part of provided 'bash.custom' file
##############################################################################
#####################################
REQ_PKGS=(geoip2-database mmdblookup systemd openssh bind-tools) REQ_PKGS=(geoip2-database mmdblookup systemd openssh bind-tools)
PACMAN_EXEC="/usr/bin/pacman"
for pkg in ${REQ_PKGS[*]}; do 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" echo -e "\nMissing package $pkg\n"
kill -INT $$ kill -INT $$
fi fi


+ 5
- 2
tools/tputcolors.sh View File

@ -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 # Author: user79743
# Source: https://unix.stackexchange.com/questions/269077/tput-setaf-color-table-how-to-determine-color-codes
#####################################
color(){ color(){
for c; do for c; do


+ 20
- 1
tools/whichcmd.sh View File

@ -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 <pekka.helenius@fjordtek.com>
#
# 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 <http://www.gnu.org/licenses/>.
#####################################
if [[ ${1} == "-h" ]] || [[ ${1} == "--help" ]] || [[ -z ${1} ]]; then if [[ ${1} == "-h" ]] || [[ ${1} == "--help" ]] || [[ -z ${1} ]]; then
echo " echo "


+ 19
- 0
tools/whichport.c View File

@ -1,3 +1,22 @@
/*
whichport - Which TCP/UDP port number is associated with an application protocol
Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h> #include <stdio.h>
#include <stddef.h> #include <stddef.h>
#include <netdb.h> #include <netdb.h>


+ 19
- 0
tools/whichservice.c View File

@ -1,3 +1,22 @@
/*
whichservice - Which application protocol is associated with a TCP/UDP port number
Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h> #include <stdio.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>


Loading…
Cancel
Save