Commit 8cc8b4bd authored by kyodev's avatar kyodev

maj

parent fb14903d
Pipeline #60841 passed with stages
in 23 seconds
# getInfo
![version: 4.15.0](https://img.shields.io/badge/version-4.15.0-blue.svg?longCache=true&style=for-the-badge)
![version: 4.16.0](https://img.shields.io/badge/version-4.16.0-blue.svg?longCache=true&style=for-the-badge)
![bash langage](https://img.shields.io/badge/bash-4-brightgreen.svg?longCache=true&style=for-the-badge)
![license LPRAB / WTFPL](https://img.shields.io/badge/license-LPRAB%20%2F%20WTFPL-blue.svg?longCache=true&style=for-the-badge)
......
# getIp
![version: 2.16.0](https://img.shields.io/badge/version-2.16.0-blue.svg?longCache=true&style=for-the-badge)
![version: 2.17.0](https://img.shields.io/badge/version-2.17.0-blue.svg?longCache=true&style=for-the-badge)
![bash langage](https://img.shields.io/badge/bash-4-brightgreen.svg?longCache=true&style=for-the-badge)
![license LPRAB / WTFPL](https://img.shields.io/badge/license-LPRAB%20%2F%20WTFPL-blue.svg?longCache=true&style=for-the-badge)
......
# ipupdate
![version: 1.5.0](https://img.shields.io/badge/version-1.5.0-blue.svg?longCache=true&style=for-the-badge)
![version: 1.6.0](https://img.shields.io/badge/version-1.6.0-blue.svg?longCache=true&style=for-the-badge)
![bash langage](https://img.shields.io/badge/bash-4-brightgreen.svg?longCache=true&style=for-the-badge)
![license LPRAB / WTFPL](https://img.shields.io/badge/license-LPRAB%20%2F%20WTFPL-blue.svg?longCache=true&style=for-the-badge)
......
# pastit
![version: 0.5.0](https://img.shields.io/badge/version-0.5.0-blue.svg?longCache=true&style=for-the-badge)
![version: 0.7.0](https://img.shields.io/badge/version-0.7.0-blue.svg?longCache=true&style=for-the-badge)
![bash langage](https://img.shields.io/badge/bash-4-brightgreen.svg?longCache=true&style=for-the-badge)
![license LPRAB / WTFPL](https://img.shields.io/badge/license-LPRAB%20%2F%20WTFPL-blue.svg?longCache=true&style=for-the-badge)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/bin/bash
version=2.16.0
date="28/06/2018"
version=2.17.0
date="03/07/2018"
script="getIp"
# contact="IRC ##sdeb@freenode.net ou https://framagit.org/sdeb/getIp/issues"
......@@ -36,11 +36,11 @@ f__color(){ # 29/05/2018
# $1=-c|-l|-lc, $2 répertoire, [$3] motif exclusion sur nom fichier, affiche 0|null si répertoire inexistant
# -c: compte du nombre de fichiers dans un répertoire
# -l: liste inline des noms de fichiers seuls (sans chemin) (similaire ls)
# -ls: liste inline des noms de fichiers seuls (sans chemin) (similaire ls)
# -lc: liste en colonne des noms de fichiers seuls (sans chemin) (similaire ls -1)
# si joker (*?) sur chemin, le motif d'exclusion ne s'applique pas à un répertoire listé, juste sur le nom du fichier
# exemple: f__dir -l $dir "lock|partial" ou "\.list"
f__dir(){ # 05/03/2017
# exemple: f__dir -ls $dir "lock|partial" ou "\.list"
f__dir(){ # 03/07/2017
local i=0 action="-c" stock=''
[[ "$1" =~ - ]] && action="$1" || action="-c" # si option en erreur: -c par défaut
......@@ -54,7 +54,7 @@ f__dir(){ # 05/03/2017
done <<< "$( ls "$2" 2>/dev/null )"
if [ "$action" == "-c" ]; then
echo "$i"
elif [ "$action" == "-l" ]; then
elif [ "$action" == "-ls" ]; then
echo "${stock% }"
elif [ "$action" == "-lc" ]; then
stock=${stock% }
......@@ -127,8 +127,10 @@ f__random(){ # 17/06/2018
# recherche commandes/paquets, $1 liste: cmd1|cmd2[>paquet] (séparées par espaces) ex: "gawk|mawk>gawk wget"
# si manque, return 1 & affiche commandes manquantes (si debian, ajout proposition paquet à installer)
f__requis(){ # 11/06/2018
local ENV_DEBIAN c_echo ireq cmds package commands command commandsMissing packagesMissing
# requiert f__sort_uniq
f__requis(){ # 30/06/2018
local ENV_DEBIAN c_echo ireq cmds package commands command
local commandsMissing packagesMissing t_commandsMissing t_packagesMissing
if type -p dpkg &>/dev/null ; then
ENV_DEBIAN="oui" # debian
......@@ -140,36 +142,76 @@ f__requis(){ # 11/06/2018
fi
for ireq in $1; do
IFS='>' read -r cmds package <<< "$ireq" # ex: "awk|gawk>gawk wget file tar killall>psmisc"
mapfile -t -d '|' commands <<< "${cmds}"
[ -z "$package" ] && package=${commands[0]%$'\n'} # pas de packages dans les options, donc = commands[0]
IFS='|' read -ra commands <<< "${cmds}"
[ -z "$package" ] && package=${commands[0]} # pas de packages dans les options, donc = commands[0]
unset t_commandsMissing t_packagesMissing
for command in "${commands[@]%$'\n'}"; do
if type -p "$command" &>/dev/null ; then
unset commandsMissing packagesMissing
unset t_commandsMissing t_packagesMissing
break
else # inexistant
commandsMissing+="$command "
packagesMissing+="$package "
t_commandsMissing+="$command "
t_packagesMissing="$package "
fi
done
[ "$t_commandsMissing" ] && commandsMissing+="$t_commandsMissing "
[ "$t_packagesMissing" ] && packagesMissing+="$t_packagesMissing "
done
# dédoublonnage & triage
commandsMissing=$( echo "$commandsMissing" | tr ' ' '\n' | sort --unique | tr '\n' ' ' )
packagesMissing=$( echo "$packagesMissing" | tr ' ' '\n' | sort --unique | tr '\n' ' ' )
# suppression éventuel espace final
commandsMissing=${commandsMissing% }
packagesMissing=${packagesMissing% }
# dédoublonnage & tri
commandsMissing=$( f__sort_uniq "$commandsMissing" )
packagesMissing=$( f__sort_uniq "$packagesMissing" )
# affichage final
if [ "$commandsMissing" ] && [ "$ENV_DEBIAN" ]; then
$c_echo "${RED}erreur critique, manquant: $STD$BOLD$commandsMissing" \
"vous devriez exécuter:$GREEN apt install $packagesMissing"
$c_echo "${RED}erreur critique, manquant: $STD$BOLD$commandsMissing$STD" \
"vous devriez exécuter:$GREEN apt install $packagesMissing$STD"
elif [ "$commandsMissing" ]; then
$c_echo "${RED}erreur critique, manquant: $STD$BOLD$commandsMissing"
$c_echo "${RED}erreur critique, manquant: $STD$BOLD$commandsMissing$STD"
fi
[ "$commandsMissing" ] && return 1 || return 0
}
# options: liste à trier [-lf], affiche flat liste (\n enlevés en sortie) ou si -ln liste avec \n à chaque ligne
# des caractères non permis =$/`... sont transformés en ø
f__sort_uniq(){ # 02/07/2018
local lf list array result item
while (( $# )) ; do
case "$1" in
-lf ) lf='yes' ;;
* ) list=${1} ;;
esac
shift
done
while read -r ; do # lecture ligne
[ -z "$REPLY" ] && continue
REPLY=${REPLY# } # trim gauche simple
REPLY=${REPLY% } # trim droite simple
REPLY=${REPLY// /\~} # espace remplacé avec ~
# interdits/remplacés: ()/`; ø utilisé comme indicateur, ~ remplacé pas espace
REPLY=${REPLY//[^a-zA-Z0-9~.,\{\}!\[\]#*%µ£°⇉:_+-]/ø} # caractère <> de autorisé remplacés par ø
if [ "$lf" ]; then
array+=( "${REPLY}" )
else
IFS='~' read -ra array <<< "$REPLY"
fi
done <<< "${list}"
result=$(
for item in "${array[@]}"; do
eval "alias ${item}=ls"
done
alias
)
result=${result//alias }
result=${result//=\'ls\'}
result=${result//\~/ }
[ "$lf" ] && echo "${result}" || echo "${result//$'\n'/ }"
}
# $@=cmd à lancer en root avec su ou sudo. si sudo possible: prioritairesu su
f__sudo(){ # 11/06/2018
......@@ -697,9 +739,10 @@ fi_ip(){ # 16/06/2018
}
# $1=-4|-6|-46 protocole, affichage ip publiques
fi_ip_pub(){ # 15/06/2018 SPÉCIFIQUE
local itest option="$1" ippub
fi_ip_pub(){ # 03/07/2018
local itest ippub option="$1"
option=${option:=-46}
option=${option//-46/-4 -6}
for itest in $option; do
itest=-${itest//-}
......@@ -712,7 +755,7 @@ fi_ip_pub(){ # 15/06/2018 SPÉCIFIQUE
}
# $1=-4|-6, assigne $fg_ip, $fg_gws, $fg_ifn, $fg_mac, fg_ip_deprec (ipv6)
figet_ip(){ # 06/03/2018
figet_ip(){ # 03/07/2018
local target ifn
unset fg_ip fg_ip_deprec fg_gws fg_ifn_prior fg_ifn fg_mac
......@@ -732,14 +775,15 @@ figet_ip(){ # 06/03/2018
sub(/sec/,"s",lft); sub(/preferred_lft/,"lft",lft)
printf "(%s) %s \n",lft,scope }
else printf "\n" }
/fe80::/ {
$4 ~ /^fe..:/ {
sub(/wl.*/,$2" (wifi)",$2)
match($0,/scope .* \\/); scope=substr($0,RSTART,RLENGTH); sub(/scope /,"",scope); sub(/ \\/,"",scope)
link=link"\n"sprintf("%-17s: %-22s %s",$2,$4,scope) }
/ lo / { lo=sprintf("%s (loopback) : %s",$2,$4) }
$2 ~ /lo/ { lo=sprintf("%s (loopback) : %s",$2,$4) }
END { printf "%s\n%s",link,lo }
#~ END { printf "%s",link }
' )
# ipv6, traitemenent adresses dynamiques
# ipv6, traitement adresses dynamiques
if [ "$proto" == "-6" ]; then
fg_ip_deprec=$( sed -n '/temporary deprecated dynamic/p' <<< "$fg_ip" )
fg_ip=$( sed '/temporary deprecated dynamic/d; /preferred_lft 0sec/d' <<< "$fg_ip" )
......@@ -750,25 +794,27 @@ figet_ip(){ # 06/03/2018
BEGIN { if (proto == -6) larg=42; else larg=12 }
/default via/ { printf "%-"larg"s (%s)\n",$3,$5 }
' )
# interface sortante
if [ "$proto" == "-6" ]; then
target=$( ip $proto -o route | awk '/proto ra / { print $1; exit}' )
target=$( ip $proto -o route | awk '/default/ { print $3; exit}' )
if [ "$target" ]; then
fg_ifn_prior=$( ip $proto route get "$target" | sed -En 's/.*dev (.*) proto.*src ([0-9a-f:]+).*/\1 (\2)/p' )
fi
else
fg_ifn_prior=$( ip $proto route get 255.255.255.255 | sed -En 's/.*dev (.*) src ([0-9.]+) .*/\1 (\2)/p' )
fi
# ifnames & mac
fg_ifn="" fg_mac=""
for ifn in $( f__dir -l /sys/class/net/ ) ; do
for ifn in $( f__dir -ls /sys/class/net/ ) ; do
if [ "$ifn" != "lo" ]; then
fg_ifn+="$ifn "
fg_mac+="$ifn: $( cat "/sys/class/net/$ifn/address" )"$'\n'
fg_mac+="$ifn: $( < "/sys/class/net/$ifn/address" )"$'\n'
fi
done
fg_ifn=${fg_ifn% } # suppression dernier espace
fg_mac=${fg_mac%[[:cntrl:]]} # suppression dernier $'\n'
fg_mac=${fg_mac%$'\n'} # suppression dernier $'\n'
}
# anacron hebdomadaire, via cron horaire, $1=upgrade|install|remove
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment