From bf043a623e8645f3817c816c03725beab0b741a2 Mon Sep 17 00:00:00 2001 From: kyodev Date: Sun, 30 Jul 2017 17:08:05 +0200 Subject: [PATCH] 0.0.2a --- scripts/getInfo | 224 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100755 scripts/getInfo diff --git a/scripts/getInfo b/scripts/getInfo new file mode 100755 index 0000000..08bdaf5 --- /dev/null +++ b/scripts/getInfo @@ -0,0 +1,224 @@ +#!/bin/bash + +version=0.0.2 +date="07/2017" +projet="simpledebian" +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 +##### + +PATH='/bin:/usr/bin' ; IFS=' ' + +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" +} + +fi_divers(){ + 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/ /') + #dépend de apt install lsb-release, debian standard juste : lsb-base + [ -x "/usr/bin/lsb_release" ] && local description=$(lsb_release -ds) + local uname=$(uname -rmo) + local parametreKernel=$(sed 's/root=[^ ]*//;s/[ ]\+/, /g;s/^BOOT_IMAGE=[^ ]*//' /proc/cmdline) + echo "dernier boot: $lastboot, uptime: $uptime""$rcmd" + [ $description ] && echo "description: $description""$rcmd" + echo "uname: $uname""$rcmd" + echo "parametreKernel: $parametreKernel""$rcmd" +} + +fi_carte_reseau(){ + netcards="$(lspci -nnk | grep -iEA 3 'network|ethernet')" +} + +trim_quotes() { # thanks neofetch + trim_output="${1//\'}" + trim_output="${trim_output//\"}" + printf "%s" "$trim_output" +} + +get_de() { # thanks neofetch + 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 +} + +get_distro() { # thanks neofetch + [[ "$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 + 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)" +} + + +fi_pastebinit(){ + pastebinit -b http://markdownshare.com/ -i "$fileOutput" +} + +fi__curl(){ + curl -H "Accept: application/json" -X POST -F "text=<$fileOutput" https://markdownshare.com/create/ +#-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. +} + + # initialisation +f__affichage +f__architecture || f__error "Architecture non supportée" "vous pouvez contacter contacter $projet $contact pour parfaire le script" +fileOutput="getInfo_rapport.md" +rcmd=" " # retour ligne markdown +f__requis "pastebinit" +os="$(uname -s)" +fileLogs="/var/log/sdeb_getFinfo.log" +dateRapport=$(date +"%d %b %Y %H:%M %z") + +rm "$fileOutput" &>/dev/null + +echo -e "# getInfo $version\n" > "$fileOutput" +echo -e "Rapport au $dateRapport sur $(uname -n)\n" >> "$fileOutput" + +echo -e "## système" >> "$fileOutput" +fi_divers | tee -a "$fileOutput" +get_de && echo "DE: $de""$rcmd" | tee -a "$fileOutput" +get_distro && echo "distro: $distro""$rcmd" | tee -a "$fileOutput" +echo -e "## réseau" >> "$fileOutput" +fi_carte_reseau && echo "$netcards""$rcmd" | tee -a "$fileOutput" + +fi__curl +echo +exit + +{"link":"https://markdownshare.com/view/5b934dde-473e-4d34-b1e4-7d624cedca40", + "raw":"https://markdownshare.com/raw/5b934dde-473e-4d34-b1e4-7d624cedca40", + "edit":"https://markdownshare.com/edit/af25b45a5b945963223f8aeb773decf8", + "delete":"https://markdownshare.com/delete/af25b45a5b945963223f8aeb773decf8", + "id":"5b934dde-473e-4d34-b1e4-7d624cedca40", + "auth":"af25b45a5b945963223f8aeb773decf8" +} + +bug markdownshare: + "```" n'est pas interprété en
 
+
+	style.css ligne 167
+pre {
+padding:10px;
+margin:0 0px 20px 0px;
+font-size:0.8em
+}