Created
February 9, 2016 05:08
-
-
Save Ara4Sh/0abc4f72e8688282b733 to your computer and use it in GitHub Desktop.
archinfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (C) 2015 Arash Shams <[email protected]>. | |
# | |
# 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. | |
# | |
# 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/>. | |
# Treat unset variables as an error | |
set -o nounset | |
#Getting OS Information | |
getOS (){ | |
echo $(sed -n '/^.\+$/p' /etc/issue | awk -vFS='\' '{gsub(/ .*$/,"",$1);print tolower($1)}') | |
exit $? | |
} | |
GraphicCard (){ | |
echo "===Graphic Cards Details===" | |
lspci | awk '/(VGA|3D)/{$1="";printf("%02d :%s\n",(++i),$0)}' | |
} | |
DiskInfo (){ | |
echo "===Home Capacity===" | |
local here=$(echo ${HOME##*/}) | |
local scaleFactor=1000 | |
local moreInfo=1 | |
if [ $# -eq 1 ];then | |
case $1 in | |
-H) scaleFactor=1024;shift ;; | |
*) shift ;; | |
esac | |
fi | |
size=$(du -b --max-depth=0 ${HOME} | awk '{printf("%.6f",$1/(1024*1024))}') | |
tmpSize=$(echo $size | sed 's/\..*$//') | |
if [ $tmpSize -gt 1000 ];then | |
size=$(echo $size | awk -vSFACTOR=$scaleFactor '{printf("%.6f\n",$1/SFACTOR)}') | |
echo -e "Size Of \033[1m$here\033[0m Directory : \033[1m$size GiB\033[0m \033[0m" | |
elif [ $tmpSize -eq 0 ];then | |
size=$(echo $size | awk -vSFACTOR=$scaleFactor '{printf("%.6f\n",$1*SFACTOR)}') | |
echo -e "Size Of \033[1m$here\033[0m Directory : \033[1m$size KiB\033[0m \033[0m" | |
else | |
echo -e "Size Of \033[1m$here\033[0m Directory : \033[1m$size MiB\033[0m \033[0m" | |
fi | |
if [ $moreInfo -eq 1 ];then | |
if [ $scaleFactor -eq 1000 ];then | |
available=$(df -BGB . | grep -v "Filesystem" | awk '{print $4}') | |
else | |
available=$(df -BG . | grep -v "Filesystem" | awk '{print $4}') | |
fi | |
echo -e "Available Space In This Partition :\033[1m $available \033[0m " | |
fi | |
echo "===lsblk - list block devices===" | |
lsblk -l | |
} | |
Network-Details (){ | |
echo "===Network Section===" | |
echo "Ethernet known as: $(ip link | awk -vFS=': ' '/^2/ {print $2}')" | |
echo "Wireless known as: $(ip link | awk -vFS=': ' '/^3/ {print $2}')" | |
echo "===Ping===" | |
echo -e "\tping -c3 8.8.8.8:" | |
ping -c3 8.8.8.8 | |
echo "===DNS===" | |
cat /etc/resolv.conf | awk '/^nameserver/ {printf("%02d : %s\n",(++i),$0)}' | |
echo "===Wireless Connection Information===" | |
cat /proc/net/wireless | |
} | |
PacmanInfo (){ | |
echo "===Pacman Details===" | |
printf "%s\n" "$( pacman --version )" | |
echo | |
pastInSecY=$(date -d "$(tac /var/log/pacman.log | awk -vFS='] ' '/pacman -Syy/ {gsub(/\[/,"",$1);print $1;exit}')" +"%s") | |
pastInSecU=$(date -d "$(tac /var/log/pacman.log | awk -vFS='] ' '/pacman -Syu/ {gsub(/\[/,"",$1);print $1;exit}')" +"%s") | |
nowInSec=$(date +"%s") | |
differenceSecY=$((nowInSec-pastInSecY)) | |
differenceSecU=$((nowInSec-pastInSecU)) | |
echo "$(printf "You Used pacman -Syy %03d:%02d:%02d Before Now" "$((differenceSecY/3600))" "$((differenceSecY%3600/60))" "$((differenceSecY%60))")" | |
echo "$(printf "You Used pacman -Syu %03d:%02d:%02d Before Now" " $((differenceSecU/3600))" "$((differenceSecU%3600/60))" "$((differenceSecU%60))")" | |
} | |
ServiceInfo (){ | |
echo "===Service Information===" | |
echo "First Part: systemctl -t service --no-pager " | |
systemctl -t service --no-pager | |
echo "Second Part: systemctl --failed " | |
systemctl --failed | |
} | |
VerInfo (){ | |
echo "===Versions===" | |
echo -n "Kernel Version: " && echo "$( uname -r )" | |
} | |
MirrorsInfo (){ | |
echo "===Mirrors Information===" | |
if [ "$(getOS)" == "manjaro" ];then | |
printf "%13s%17s%17s\n" "Location" "Time" "Last Sync" | |
sed -n --regexp-extended -e '/(Location)|(Time)|(Last Sync)/p' /etc/pacman.d/mirrorlist | cut -d: -f 2- | paste - - - | column -t -o " " | awk '{printf("%02d : %s\n",NR,$0)}' | |
elif [ "$(getOS)" == "arch" ];then | |
grep "^[^#;]" /etc/pacman.d/mirrorlist | awk '{printf("%02d : %s\n",NR,$0)}' | |
fi | |
} | |
RepositoriesInfo (){ | |
echo "===Repositories Information===" | |
sed -n --regexp-extended -e '/^\[[^o]/p' /etc/pacman.conf | sed --regexp-extended 's/\[|\]//g' | awk '{printf("%02d : %s\n",NR,$0)}' | |
} | |
CPUInfo (){ | |
echo "===CPU Information===" | |
echo "CPU $( lscpu | head -n13 | tail -n1 )" | |
} | |
PackageInfo (){ | |
echo "===Package Counter Summary===" | |
read -r -d '' PKG_COUNT <<- EOF | |
Total number of your installed packages : $( pacman -Q | wc -l) | |
Number of installed packages from Core : $(paclist core | wc -l) | |
Number of installed packages from Extra : $( paclist extra | wc -l) | |
Number of installed packages from Community : $( paclist community | wc -l) | |
Number of installed packages from Multilib : $( paclist multilib | wc -l ) | |
EOF | |
echo -e "$PKG_COUNT" | column -s':' -t | |
SUM=$(echo -e "$PKG_COUNT" | sed --regexp-extended -e '1d' -e 's/[^[:digit:]]//g' | awk '{sum+=$1};END{print sum}') | |
TOTAL=$(pacman -Q | wc -l) | |
if [ $SUM -ne $TOTAL ];then | |
echo "It Seems That You Have $((TOTAL-SUM)) Packge From Repos Not Mentioned Above." | |
fi | |
} | |
Title (){ | |
tput clear | |
echo "####Iranian Arch Community####" | |
echo "Visit: Archusers.ir" | |
} | |
action=$1 | |
if [[ $action -ne 1 ]]; then | |
echo "ArchInfo only accepts 1 argument" | |
fi | |
case "$action" in | |
-a | -A | --all) | |
Title | |
CPUInfo | |
DiskInfo | |
PacmanInfo | |
GraphicCard | |
VerInfo | |
ServiceInfo | |
MirrorsInfo | |
RepositoriesInfo | |
Network-Details | |
PackageInfo | |
;; | |
-c | -C | --cpu) | |
Title | |
CPUInfo | |
;; | |
-g | -G | --graphic) | |
Title | |
GraphicCard | |
;; | |
-n | -N | --network) | |
Title | |
Network-Details | |
;; | |
-s | -S | --services) | |
Title | |
ServiceInfo | |
;; | |
-v | -V | --version) | |
Title | |
VerInfo | |
;; | |
-m | -M | --mirrors) | |
Title | |
MirrorsInfo | |
;; | |
-r | -R | --repositories) | |
Title | |
RepositoriesInfo | |
;; | |
-p | -P | --pkgcounter) | |
Title | |
PackageInfo | |
;; | |
-d | -D | --disk) | |
Title | |
DiskInfo | |
;; | |
--pacman) | |
Title | |
PacmanInfo | |
;; | |
*) | |
Title | |
echo "Usage: archinfo PARAMETER" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment