This commit is contained in:
kyodev 2017-08-18 20:15:13 +02:00
parent 616e430934
commit cd22af6b59
2 changed files with 38 additions and 35 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
version=1.0.4
version=1.0.5
date="18/08/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues"
@ -85,7 +85,7 @@ f__log(){ # v08/2017
}
# test dépendances/paquets, $1 liste commande[>paquet] (ex: killall>psmisc)
# si manque, info commandes manquantes, si debian, proposition paquet à installer et SORTIE
# si manque, SORTIE & info commandes manquantes, si debian, SORTIE & proposition paquet à installer
# si $2=debOnly et si paquets manquants: return 1 et $debOnlyPackages ( $1=liste paquets )
# si $2=debOnly et si paquets présent: return 0 et $debOnlyPresents ( $1=liste paquets )
# attention priorité $debOnlyPackages sur $debOnlyPresents
@ -150,18 +150,18 @@ f__wget_test(){ # v07/2017
}
# inscription dans tache upgrade en anacron hebdomadaire, via cron horaire
fscript_cronAnacron(){ # v18/08/2017
fscript_cronAnacron(){ # v18/08/2017-2
local dirAnacron="/home/$user_/.config/anacron"
local dirSpool="$dirAnacron/spool"
local fileAnacron="$dirAnacron/$script.anacrontab"
sed -i "/$script.anacrontab/d" /etc/crontab
[ $EUID -eq 0 ] && sed -i "/$script.anacrontab/d" /etc/crontab
case "$1" in
install | upgrade )
mkdir -p "$dirAnacron"
# table anacron
echo "7 01 $script nice /opt/bin/$script --upgrade" > "$fileAnacron"
## dev: anacron journalier:
[ "$LOGNAME" == "$lognameDev" ] && echo "1 01 $script test nice /opt/bin/$script --upgrade 1>/dev/null" >> "$fileAnacron"
[ "$user_" == "$lognameDev" ] && echo "1 01 $script""Dev nice /opt/bin/$script --upgrade 1>/dev/null" >> "$fileAnacron"
# création spool anacron utilisateur
mkdir -p "$dirSpool"
chown -R "$user_": "$dirAnacron" "$dirSpool"
@ -183,11 +183,11 @@ fscript_cronAnacron(){ # v18/08/2017
}
# mise à jour script si dispo
fscript_dl(){ # v17/08/2017
fscript_dl(){ # v18/08/2017
f__requis "wget"
if [ "$script_aJour" == "ok" ]; then return 0; fi
local dirTemp="/tmp/$script-$RANDOM/"
mkdir -p "$dirTemp"
opType="upgrade"
wget -q --show-progress --tries=2 --timeout=15 -O "$dirTemp$script" "$urlScript"
if [ "$?" != "0" ]; then f__wget_test "$urlScript"; fi
chmod 755 "$dirTemp$script"
@ -197,12 +197,12 @@ fscript_dl(){ # v17/08/2017
fscript_cronAnacron "upgrade"
f__info "\n $script mis à jour en version $versionScript"
f__log "$script mis à jour en version $versionScript"
$0 upgrade # spécifique getFlash, script mis à jour, on relance le script en upgrade pour le plugin
exit 0
}
# version script en ligne, assigne $versionScript, $script_aJour=ok|ko
fscript_get_version(){ # v08/2017
fscript_get_version(){ # v18/08/2017
f__requis "wget"
versionScript="$(wget -q --tries=2 --timeout=15 -O - "$urlScript" | grep '^version=' | cut -d '=' -f 2)"
if [ "$versionScript" ]; then
if [ "$version" != "$versionScript" ]; then
@ -216,12 +216,13 @@ fscript_get_version(){ # v08/2017
}
# installation du script dans le système
fscript_install(){ # v08/2017
fscript_install(){ # v18/08/2017
if dirname "$0" | grep -q 'bin' ; then
f__info "$script $version est déjà installé"
return 1
fi
[ $EUID -eq 0 ] || f__error "vous devez être ROOT pour installer ce script dans le système"
f__requis "wget anacron cron"
# install /opt
mkdir -p /opt/bin/
cp -d "$(basename $0)" "/opt/bin/$script"
@ -412,18 +413,17 @@ get_gpu() { # thanks neofetch, assigne $gpu
}
get_ip() { # $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type, $ifname, $ifname_type
# ip_local="$(ip route | awk '/proto.*src/ {print $9, "pour",$3}')"
[ -z "$(which ip)" ] && return 1
ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print $4,"(",$2,")"}')"
ip_local_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local)"
ifname="$(ip -4 route | awk '/proto kernel/ {print $3}')"
ifname_type="$(sed -E 's/(^wl.*)/\1 (wifi)/;s/(^en.*|^eth.*)/\1 (ethernet)/' <<< $ifname)"
# gateway="$(ip route | awk '/default.*via/ {print $3, "pour", $5}')"
gateway="$(LC_ALL=C ip -4 route | awk '/default via/ {print $3,"(",$5,")"}'; LC_ALL=C ip -6 route | awk '/default via/ {print $3,"(",$5,")"}')"
gateway_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.µ)/\1 (ethernet)/' <<< $gateway)"
gateway_one="$(head -n 1 <<< $gateway | awk '{print $1}')"
ifname="$(ip -4 route | awk '/proto kernel/ {print $3}')"
ifname_type="$(sed -E 's/(^wl.*)/\1 (wifi)/;s/(^en.*|^eth.*)/\1 (ethernet)/' <<< $ifname)"
}
get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public
get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public # v18/08/2017
list_ip4(){
ip_test+=" http://whatismyip.akamai.com"
@ -474,14 +474,14 @@ get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public
ip_telnet=6.ifcfg.me
else return 1; fi
if which dig &>/dev/null && [ -z "$ip_public" ]; then
if [ "$(which dig)" ] && [ -z "$ip_public" ]; then
for ii in $dig_test ; do
ip_public="$(dig +short $(sed 's;/; ;g' <<< $ii))"
[ "$ip_public" ] && break
done
fi
if which wget &>/dev/null && [ -z "$ip_public" ]; then
if [ "$(which wget)" ] && [ -z "$ip_public" ]; then
cmd="wget --quiet --tries=1 --timeout=5 -O - "
for ii in $ip_test ; do
ip_public="$($cmd $ii)"
@ -489,7 +489,7 @@ get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public
done
fi
if which curl &>/dev/null && [ -z "$ip_public" ]; then
if [ "$(which curl)" ] && [ -z "$ip_public" ]; then
cmd="curl --silent --location --retry 0 --max-time 5" #--location pour aider redirections
for ii in $ip_test ; do
ip_public="$($cmd $ii)"
@ -497,11 +497,11 @@ get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public
done
fi
if which telnet &>/dev/null && [ -z "$ip_public" ]; then
if [ "$(which telnet)" ] && [ -z "$ip_public" ]; then
ip_public="$(telnet $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4)"
fi
if which nc &>/dev/null && [ -z "$ip_public" ] && [ "$1" != "IPv6" ]; then
if [ "$(which nc)" ] && [ -z "$ip_public" ] && [ "$1" != "IPv6" ]; then
ip_public="$(nc $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4)"
fi
@ -721,7 +721,7 @@ fi_dmesg(){ # root only, si $1=dmesg rapport dmesg only
fi_gpu(){
# local graphCards="$(lspci -nnk | grep -iEA 3 'vga|display|3d')"
local graphCards="$(lspci -nnvvv | grep -iEA 13 '^[0-9]+.*vga|display|3d')"
which glxinfo &>/dev/null && local openGl="$(glxinfo | grep 'OpenGL version string:')"
[ "$(which glxinfo)" ] && local openGl="$(glxinfo | grep 'OpenGL version string:')"
local extraitXorg="$(grep -E '\(WW\)|\(EE\)|\(NI\)|\(\?\?\)' /var/log/Xorg.*.log /home/$user_/.local/share/xorg/Xorg.*.log 2>/dev/null)"
local resolutions="$(xrandr --query | grep '^ *[0-9]' | head -n 10)"
@ -845,7 +845,7 @@ fi_reseau(){
if [ "$(ps -ef | grep -c ${netmgrpaths[$ii]})" -ge 2 ]; then netmgrrun+="$(ps -ef | grep -o "${netmgrpaths[$ii]}.*$" | head -n 1)"; fi
done
local text="## réseau \n\n"
if which iwlist &>/dev/null; then # liste canaux wifi paquet wireless-tools requis
if [ "$(which iwlist)" ]; then # liste canaux wifi paquet wireless-tools requis
local liste_canaux_wifi="$(iwlist chan 2>&1 | grep -vE 'no frequency information|^$')"
fi
###
@ -906,7 +906,7 @@ fi_reseau(){
}
fi_sources(){
which apt &>/dev/null || return 0 # retour si pas d'apt ? et aptitude...????
[ "$(which apt)" ] || return 0 # retour si pas d'apt ? et aptitude...????
local sources="$(grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null | sed 's/ / /g; s/:/: /')"
local dateMaj="$(date -r /var/cache/apt/archives/)"
local httpredir="$(grep 'httpredir' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null)"
@ -993,7 +993,7 @@ fi_systeme(){
get_cpu; text+="CPU: **$cpu** \n"
get_gpu; text+="GPU: **$gpu** \n"
text+="type de boot: $mbr \n"
get_distro; text+="**$distro** \n\n"
get_distro; text+="distribution: **$distro** \n\n"
f__architecture || f__info "Architecture non supportée" "vous pouvez contacter contacter $projet $contact si vous voulez aider à parfaire le script"
text+='```\n'
text+="architecture: $architecture \n"
@ -1042,7 +1042,7 @@ fileLogs="/var/log/sdeb_$script.log"
PasteDuration=7 # durée conservation du paste en jours
f__affichage
f__user || ( [ "$?" -eq 2 ] && noHome="true" )
f__requis "gawk wget curl"
f__requis "gawk wget curl ip>iproute2" # pour fonctionnement programme
fi__context
prg_1(){ # début programme
@ -1055,11 +1055,11 @@ prg_1(){ # début programme
echo -e "# getInfo $version sur $hote / $os \n" > "$fileOutput"
echo -e "Rapport au $dateRapport \n" >> "$fileOutput"
}
prg_2test(){ # traitements tests
prg_2(){ # traitements tests
printf "."
fi_reseau; printf "."
}
prg_2(){ # traitements principaux
prg_2H(){ # traitements principaux
printf "."
fi_systeme; printf "."
fi_cpu; printf "."
@ -1102,11 +1102,12 @@ for i in "$options"; do
fi ;; # programme
--ip )
get_ip_public "IPv4"
f__info "raw" "$GREEN ip4: $ip_public"
[ "$ip_public" ] && f__info "raw" "$GREEN ip4: $ip_public"
get_ip_public "IPv6"
f__info "$BLUE""ip6: $ip_public" ;; # affiche ip public
[ "$ip_public" ] && f__info "raw" "$BLUE""ip6: $ip_public"
;; # affiche ip public
--upgrade | -u )
f__log "test mise à jour"
opType="upgrade"
fscript_get_version
fscript_dl ;; # upgrade script si maj possible
--help | -h | * ) fi_help ;; # affichage help

View File

@ -2,16 +2,18 @@
## todo
* if which iwlist &>/dev/null; --> if [ "$(which iwlist)" ]; plus court
* ifconfig au lieu de iproute2
* adresses MAC?
## 1.0.4 18/08/2017
## 1.0.5 18/08/2017
* maj fscript_cronAnacron pour dev
* maj fscript_cronAnacron lors upgrade et spécial pour dev
* fix affichage ipv6, filtre sur inet6 & scope global & adr MAC
* adresse MAC non affichée
* révision ip locale, système et réseau
* révision ip locales, système et réseau
* protection absence iproute
* révision test sur which
* vérification requis pour fonctionnement script
* maj fscript_get_version, fscript_dl, fscript_install
## 1.0.3 17/08/2017