kyopages/scripts/getInfo

325 lines
9.8 KiB
Plaintext
Raw Normal View History

2017-07-30 17:08:05 +02:00
#!/bin/bash
2017-08-02 01:16:24 +02:00
version=0.4.0
date="08/2017"
projet="simpledeb"
2017-07-30 17:08:05 +02:00
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues"
script="getInfo"
urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/getInfo"
urlNotice=""
##### license LPRAB/WTFPL
# auteur: simpledebian
# contributeurs: kyodev
#####
2017-08-02 01:16:24 +02:00
PATH='/bin:/usr/bin:/sbin' ; IFS=' '
2017-07-30 17:08:05 +02:00
f__affichage(){
# définition couleurs
YELLOW="$(printf "\033[0;33m")" # ?
GREEN="$(printf "\033[0;32m")" # ok
BLUE="$(printf "\033[0;34m")" # info
RED="$(printf "\033[0;31m")" # alerte
COLOR="$(printf "\033[0m")" # standard
# clear
printf "$BLUE"
cat << 'EOF'
_ ___ __
__ _ ___| |_|_ _|_ __ / _| ___
/ _' |/ _ \ __|| || '_ \| |_ / _ \
| (_| | __/ |_ | || | | | _| (_) |
\__, |\___|\__|___|_| |_|_| \___/
|___/
EOF
echo -e "$YELLOW version $version - $date$COLOR\n"
}
# affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur
f__error() {
echo -e "\n$RED Erreur critique: $1 $COLOR"
for (( i=2 ; i<=$# ; i++ )); do echo -e " $BLUE${!i}"; done
echo "$COLOR"
exit 1
}
# affichage des paramètres en bleu, ligne vide à la fin
f__info() {
for (( i=1 ; i<=$# ; i++ )); do echo -e " $BLUE${!i}"; done
echo "$COLOR"
}
# detect system architecture, assign $architecture : i386 | x86_64, return 1 on unknown architecture
# remarque, debian: dpkg --print-architecture affiche i386
f__architecture(){
case "$(uname -m)" in
amd64 | x86_64 )
architecture="x86_64";;
i?86 | x86 )
architecture="i686";;
* )
case "$(getconf LONG_BIT)" in
64 )
architecture="x86_64";;
32 )
architecture="i686";;
*)
return 1
esac ;;
esac
}
# test dépendances (commandes disponibles), $1 liste commandes ou $1...$x, si manquant, avertissement des paquets manquants
f__requis(){
local dependsFail
for i in $@; do
if [ ! "$(which $i)" ]; then
dependsFail+="$i "
fi
done
[ -z "$dependsFail" ] || f__error "paquet(s) manquant(s)" \
"vous devez avoir le(s) paquet(s) $i pour exploiter ce script, installation,$RED en root$COLOR:" \
"apt install $dependsFail"
}
trim_quotes() { # thanks neofetch
trim_output="${1//\'}"
trim_output="${trim_output//\"}"
printf "%s" "$trim_output"
}
2017-08-02 01:16:24 +02:00
get_de() { # thanks neofetch, assigne $de
2017-07-30 17:08:05 +02:00
de="${XDG_CURRENT_DESKTOP/i3}"
de="${de/'X-'}"
de="${de/Budgie:GNOME/Budgie}"
# Fallback to using xprop.
[[ -n "$DISPLAY" && -z "$de" ]] && de="$(xprop -root | awk '/KDE_SESSION_VERSION|^_MUFFIN|xfce4|xfce5/')"
# Format strings
case "$de" in
"KDE_SESSION_VERSION"*) de="KDE${de/* = }" ;;
*"TDE_FULL_SESSION"*) de="Trinity" ;;
*"MUFFIN"* | "Cinnamon") de="$(cinnamon --version)"; de="${de:-Cinnamon}" ;;
*"xfce4"*) de="XFCE4" ;;
*"xfce5"*) de="XFCE5" ;;
esac
}
2017-08-02 01:16:24 +02:00
get_distro() { # thanks neofetch, assigne $distro
2017-07-30 17:08:05 +02:00
[[ "$distro" ]] && return
case "$os" in
"Linux" | "GNU")
if type -p lsb_release >/dev/null; then
case "$distro_shorthand" in
"on") lsb_flags="-sir" ;;
"tiny") lsb_flags="-si" ;;
*) lsb_flags="-sd" ;;
esac
distro="$(lsb_release $lsb_flags)"
elif type -p guix >/dev/null; then
distro="GuixSD"
elif type -p crux >/dev/null; then
distro="$(crux)"
case "$distro_shorthand" in
"on") distro="${distro//version}" ;;
"tiny") distro="${distro//version*}" ;;
esac
else
# Source the os-release file
for file in /etc/os-release /usr/lib/os-release /etc/*release /usr/lib/*release; do
source "$file" && break
done
# Format the distro name.
case "$distro_shorthand" in
"on") distro="${NAME:-${DISTRIB_ID}} ${VERSION_ID:-${DISTRIB_RELEASE}}" ;;
"tiny") distro="${NAME:-${DISTRIB_ID:-${TAILS_PRODUCT_NAME}}}" ;;
"off") distro="${PRETTY_NAME:-${DISTRIB_DESCRIPTION}} ${UBUNTU_CODENAME}" ;;
esac
# Workarounds for distros that go against the os-release standard.
[[ -z "${distro// }" ]] && distro="$(awk '/BLAG/ {print $1; exit}' /etc/*ease /usr/lib/*ease)"
[[ -z "${distro// }" ]] && distro="$(awk -F '=' '{print $2; exit}' /etc/*ease /usr/lib/*ease)"
fi
2017-08-01 01:48:22 +02:00
# for debian, add version
2017-07-30 17:08:05 +02:00
grep -qi 'Debian' /etc/issue && distro="$(echo $distro | sed 's/"//g') $(cat /etc/debian_version)"
distro="$(trim_quotes "$distro")"
;;
esac
[[ -z "$distro" ]] && distro="$os (Unknown)"
}
2017-08-02 01:16:24 +02:00
fi_systeme(){
local uname=$(uname -rmo)
#dépend de apt install lsb-release, debian standard juste : lsb-base
[ -x "/usr/bin/lsb_release" ] && local description=$(lsb_release -ds)
local uptime=$(uptime -p)
local lastboot=$(last -R -n 1 --time-format iso reboot | head -n 1 | grep -o '[0-9:T+-]*' | sed 's/T/ /')
local bootImage=$(sed 's/root=[^ ]*//;s/[ ]\+/, /g' /proc/cmdline)
get_de
get_distro
local text="\n## système\n\n"
text+="$distro \n"
text+="$bootImage \n"
text+="dernier boot: $lastboot, uptime: $uptime \n"
[ $description ] && text+="description: $description \n"
text+="uname: $uname \n"
text+="Desktop: $de \n"
echo -e "$text" >> "$fileOutput"
}
fi_reseau(){
local netcards=$(lspci -nnk | grep -iEA 3 'network|ethernet')
local ifconfig=$(ip address show)
local iwconfig=$(iwconfig 2>/dev/null | grep -v 'no wireless extensions')
local interfaces=$(sed '/^#/d;s/^wpa-psk [[:graph:]]\+/wpa-psk <WPA key removed>/;/^$/d;s/\(.*\)/\1 /' /etc/network/interfaces)
local route=$(ip route show)
local resolv=$(grep -v '^#' /etc/resolv.conf)
NETMGRPATHS=("/usr/sbin/NetworkManager" "/usr/sbin/wicd" "/usr/sbin/connmand")
NETMGRNAMES=("NetworkManager" "Wicd" "ConnMan")
for ii in "${!NETMGRPATHS[@]}"; do
if [ -f "${NETMGRPATHS[$ii]}" ]; then NETMGRINST+="${NETMGRNAMES[$ii]}"; fi
if [ "$(ps -ef | grep -c ${NETMGRPATHS[$ii]})" -ge 2 ]; then netmgrrun+=$(ps -ef | grep -o "${NETMGRPATHS[$ii]}.*$" | head -n 1); fi
done
local text="\n## réseau\n\n"
text+="**lspci -nnk | grep -iEA 3 'network|ethernet'** \n"
text+='```\n'
text+="$netcards \n"
text+='```\n'
text+="**ip address show** \n"
text+='```\n'
text+="$ifconfig \n"
text+='```\n'
text+="**iwconfig** \n"
text+='```\n'
text+="$iwconfig \n"
text+='```\n'
text+="**/etc/network/interfaces** \n"
text+='```\n'
text+="$interfaces \n"
text+='```\n'
text+="**ip route show** \n"
text+='```\n'
text+="$route \n"
text+='```\n'
text+="**grep -v '^#' /etc/resolv.conf** \n"
text+='```\n'
text+="$resolv \n"
text+='```\n'
text+="**network managers** \n"
2017-08-02 01:20:23 +02:00
[ "$NETMGRINST" ] && text+="installé(s): $NETMGRINST \n" || text+="non trouvé parmi: ${NETMGRNAMES[@]} \n"
2017-08-02 01:16:24 +02:00
text+="en fonctionnement: "
[ "$netmgrrun" ] && text+="$netmgrrun" || text+="non trouvé\n"
echo -e "$text" >> "$fileOutput"
}
fi_modules(){ # thanks wireless-info, $1 net|all
[ "$1" == "net" ] && local text="\n## modules réseau\n\nliste non garantie complète \n" || \
local text="\n\n## tous les modules\n\n**lsmod** \n"
if [ "$1" == "net" ]; then
local MODMATCHES="(air|ar5|at7|ath[^3]?|b43|bcma|brcm|carl|ipw|iwl|ndis|r(818|8192[eu]|871|92su)|8(188|189|192|723|812)[acde][esu]|rt[23567]|rtl|ssb|wl|(cfg|mac)80211)"
local LSMODMATCHES="(wmi|(dell|ideapad)[-_]laptop)"
local modules=$(lsmod | grep -E "(^|[[:punct:] ])($MODMATCHES|$LSMODMATCHES)[^[:punct:] ]*([[:punct:] ]|$)")
else local modules=$(lsmod); fi
text+='```\n'
text+="$modules \n"
text+='```\n'
echo -e "$text" >> "$fileOutput"
}
2017-08-01 01:48:22 +02:00
fi_curl_markdownshare(){
[ -e "$1" ] || f__error "fichier $1 inexistant"
curl -H "Accept: application/json" -X POST -F "text=<$1" https://markdownshare.com/create/
2017-07-30 17:08:05 +02:00
#-A, --user-agent and -e, --referer options
#If you wish to allow a post to expire then add an expire= parameter too:
#expire=Nh Expire in N hours.
#expire=Nd Expire in N days.
2017-08-01 01:48:22 +02:00
#-d expire ? ou --data expire
}
fi_curl_pastery(){
[ -e "$1" ] || f__error "fichier $1 inexistant"
local testCurl
# curl -X POST "https://www.pastery.net/api/paste/?title=getInfo&language=markdown" -F file=@$1
#curl -X POST "https://www.pastery.net/api/paste/?title=getInfo_$version&language=markdown&duration=$((7*1440))" --data-binary @$1
2017-08-02 01:16:24 +02:00
testCurl=$(curl --silent -X POST "https://www.pastery.net/api/paste/?title=getInfo_$version&language=markdown&duration=$((1*1440))" --data-binary @$1)
2017-08-01 01:48:22 +02:00
local id=$(echo $testCurl | cut -d '"' -f 4)
f__info "\n\n votre paste:" "https://www.pastery.net/$id/"
2017-08-02 01:16:24 +02:00
2017-08-01 01:48:22 +02:00
#?api_key=<api_key>
#&duration=<duration> en mn, 1 jour par défaut
#&title=<title>
#&language=<language>
#&max_views=<max_views>
2017-08-02 01:20:23 +02:00
#100ko max
2017-07-30 17:08:05 +02:00
}
# initialisation
f__affichage
2017-08-02 01:16:24 +02:00
f__architecture || f__error "Architecture non supportée" \
"vous pouvez contacter contacter $projet $contact pour parfaire le script"
2017-08-01 01:48:22 +02:00
f__requis "curl"
2017-08-02 01:16:24 +02:00
fileOutput="getInfo_rapport.md"
2017-07-30 17:08:05 +02:00
2017-08-02 01:16:24 +02:00
os=$(uname -s)
hote=$(uname -n)
dateRapport=$(date +"%d %b %Y %H:%M %z")
2017-07-30 17:08:05 +02:00
2017-08-02 01:16:24 +02:00
echo -e "# getInfo $version sur $hote / $os \n" > "$fileOutput"
echo -e "Rapport au $dateRapport" >> "$fileOutput"
2017-07-30 17:08:05 +02:00
2017-08-02 01:16:24 +02:00
fi_systeme
fi_reseau
fi_modules "net"
2017-08-01 01:48:22 +02:00
2017-08-02 01:20:23 +02:00
#cat $fileOutput
#exit
2017-08-01 01:48:22 +02:00
fi_curl_pastery "$fileOutput"
2017-08-02 01:16:24 +02:00
#fi_curl_markdownshare "$fileOutput"
2017-07-30 17:08:05 +02:00
echo
exit
2017-08-01 01:48:22 +02:00
{
"raw":"https://markdownshare.com/raw/b837c09d-d5ec-4d0b-afb8-a01efe31f350",
"delete":"https://markdownshare.com/delete/cb43e94336dd5cae2d5b2b8a077f700b",
"edit":"https://markdownshare.com/edit/cb43e94336dd5cae2d5b2b8a077f700b",
"link":"https://markdownshare.com/view/b837c09d-d5ec-4d0b-afb8-a01efe31f350",
"id":"b837c09d-d5ec-4d0b-afb8-a01efe31f350",
"auth":"cb43e94336dd5cae2d5b2b8a077f700b"
}
{
"id": "ndtrys",
"title": "getInfo_0.3.0",
"url": "https://www.pastery.net/ndtrys/",
"language": "markdown",
"duration": 10079
2017-07-30 17:08:05 +02:00
}
2017-08-01 01:48:22 +02:00
cut -d '"' -f 4 getInfo_retour
2017-07-30 17:08:05 +02:00
bug markdownshare:
2017-08-01 01:48:22 +02:00
'```' pas interprêté en <pre><code>
2017-07-30 17:08:05 +02:00
style.css ligne 167
pre {
2017-08-01 01:48:22 +02:00
padding:10px;
margin:0 0px 20px 0px;
font-size:0.8em
2017-07-30 17:08:05 +02:00
}
2017-08-01 01:48:22 +02:00
toc auto markdown:
http://ndossougbe.github.io/strapdown/
à voir:
https://www.pastery.net/api/
mais license non libre? et pas de depot
mais ça marche
2017-08-02 01:16:24 +02:00
wget https://framagit.org/kyodev/kyopages/raw/master/scripts/getInfo
chmod +x getInfo && ./getInfo