fetch.html

on kitten's pastes | raw

expires: 20 Jun, 2024

  1<!DOCTYPE html>
  2<html>
  3<head>
  4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5<meta name="viewport" content="width=device-width, initial-scale=1" />
  6<title>fetch - bin - scripts or programs i made
  7</title>
  8<link rel="icon" type="image/png" href="../favicon.png" />
  9<link rel="alternate" type="application/atom+xml" title="bin.git Atom Feed" href="../atom.xml" />
 10<link rel="alternate" type="application/atom+xml" title="bin.git Atom Feed (tags)" href="../tags.xml" />
 11<link rel="stylesheet" type="text/css" href="../style.css" />
 12</head>
 13<body>
 14<table><tr><td><a href="../../"><img src="../logo.png" alt="" width="32" height="32" /></a></td><td><h1>bin</h1><span class="desc">scripts or programs i made
 15</span></td></tr><tr class="url"><td></td><td>git clone <a href="git://git.wael.cc/bin">git://git.wael.cc/bin</a></td></tr><tr><td></td><td>
 16<a href="../log.html">Log</a> | <a href="../files.html">Files</a> | <a href="../refs.html">Refs</a></td></tr></table>
 17<hr/>
 18<div id="content">
 19<p> fetch (4141B)</p><hr/><pre id="blob">
 20<a href="#l1" class="line" id="l1">      1</a> #!/bin/sh
 21<a href="#l2" class="line" id="l2">      2</a> # shellcheck source=/dev/null
 22<a href="#l3" class="line" id="l3">      3</a> #
 23<a href="#l4" class="line" id="l4">      4</a> # The MIT License (MIT)
 24<a href="#l5" class="line" id="l5">      5</a> #
 25<a href="#l6" class="line" id="l6">      6</a> # Copyright (c) 2022 wael &lt;wael@wael.cc&gt;
 26<a href="#l7" class="line" id="l7">      7</a> #
 27<a href="#l8" class="line" id="l8">      8</a> # Permission is hereby granted, free of charge, to any person obtaining a copy
 28<a href="#l9" class="line" id="l9">      9</a> # of this software and associated documentation files (the &quot;Software&quot;), to deal
 29<a href="#l10" class="line" id="l10">     10</a> # in the Software without restriction, including without limitation the rights
 30<a href="#l11" class="line" id="l11">     11</a> # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 31<a href="#l12" class="line" id="l12">     12</a> # copies of the Software, and to permit persons to whom the Software is
 32<a href="#l13" class="line" id="l13">     13</a> # furnished to do so, subject to the following conditions:
 33<a href="#l14" class="line" id="l14">     14</a> #
 34<a href="#l15" class="line" id="l15">     15</a> # The above copyright notice and this permission notice shall be included in all
 35<a href="#l16" class="line" id="l16">     16</a> # copies or substantial portions of the Software.
 36<a href="#l17" class="line" id="l17">     17</a> #
 37<a href="#l18" class="line" id="l18">     18</a> # THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 38<a href="#l19" class="line" id="l19">     19</a> # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 39<a href="#l20" class="line" id="l20">     20</a> # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 40<a href="#l21" class="line" id="l21">     21</a> # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 41<a href="#l22" class="line" id="l22">     22</a> # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 42<a href="#l23" class="line" id="l23">     23</a> # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 43<a href="#l24" class="line" id="l24">     24</a> # SOFTWARE.
 44<a href="#l25" class="line" id="l25">     25</a> 
 45<a href="#l26" class="line" id="l26">     26</a> print() {
 46<a href="#l27" class="line" id="l27">     27</a> 	printf &quot;\033[1;34m%6s\033[m %s\n&quot; &quot;${1}&quot; &quot;$2&quot;
 47<a href="#l28" class="line" id="l28">     28</a> }
 48<a href="#l29" class="line" id="l29">     29</a> 
 49<a href="#l30" class="line" id="l30">     30</a> print_uptime() {
 50<a href="#l31" class="line" id="l31">     31</a> 	IFS=. read -r i _ &lt; /proc/uptime
 51<a href="#l32" class="line" id="l32">     32</a> 
 52<a href="#l33" class="line" id="l33">     33</a> 	d=&quot;$((i / 60 / 60 / 24))&quot;
 53<a href="#l34" class="line" id="l34">     34</a> 	h=&quot;$((i / 60 / 60 % 24))&quot;
 54<a href="#l35" class="line" id="l35">     35</a> 	m=&quot;$((i / 60 % 60))&quot;
 55<a href="#l36" class="line" id="l36">     36</a> 
 56<a href="#l37" class="line" id="l37">     37</a> 	[ $m -gt 0 ] &amp;&amp; up=&quot;${m}m $((i % 60))s&quot;
 57<a href="#l38" class="line" id="l38">     38</a> 	[ $h -gt 0 ] &amp;&amp; up=&quot;${h}h $up&quot;
 58<a href="#l39" class="line" id="l39">     39</a> 	[ $d -gt 0 ] &amp;&amp; up=&quot;${d}d $up&quot;
 59<a href="#l40" class="line" id="l40">     40</a> 
 60<a href="#l41" class="line" id="l41">     41</a> 	print up &quot;$up&quot;
 61<a href="#l42" class="line" id="l42">     42</a> }
 62<a href="#l43" class="line" id="l43">     43</a> 
 63<a href="#l44" class="line" id="l44">     44</a> print_x11_wm() {
 64<a href="#l45" class="line" id="l45">     45</a> 	! [ &quot;$DISPLAY&quot; ] || ! command -v xprop 1&gt;/dev/null || {
 65<a href="#l46" class="line" id="l46">     46</a> 		# query for the root window for _NET_SUPPORTING_WM_CHECK
 66<a href="#l47" class="line" id="l47">     47</a> 		#   &#39;_NET_SUPPORTING_WM_CHECK(WINDOW): window id # 0x40000f&#39;
 67<a href="#l48" class="line" id="l48">     48</a> 		id=&quot;$(xprop -root _NET_SUPPORTING_WM_CHECK)&quot;
 68<a href="#l49" class="line" id="l49">     49</a> 		# query for window id 0x40000f for _NET_WM_NAME
 69<a href="#l50" class="line" id="l50">     50</a> 		#   &#39;_NET_WM_NAME(UTF8_STRING) = &quot;dwm&quot;&#39;
 70<a href="#l51" class="line" id="l51">     51</a> 		wm=&quot;$(xprop -id &quot;${id##*\# }&quot; _NET_WM_NAME)&quot;
 71<a href="#l52" class="line" id="l52">     52</a> 		wm=&quot;${wm##*= \&quot;}&quot; # _NET_WM_NAME(UTF8_STRING) = &quot;dwm&quot; -&gt; dwm&quot;
 72<a href="#l53" class="line" id="l53">     53</a> 		wm=&quot;${wm%%\&quot;}&quot;    # dwm&quot; -&gt; dwm
 73<a href="#l54" class="line" id="l54">     54</a> 
 74<a href="#l55" class="line" id="l55">     55</a> 		print wm &quot;$wm&quot;
 75<a href="#l56" class="line" id="l56">     56</a> 	}
 76<a href="#l57" class="line" id="l57">     57</a> }
 77<a href="#l58" class="line" id="l58">     58</a> 
 78<a href="#l59" class="line" id="l59">     59</a> print_cpu() {
 79<a href="#l60" class="line" id="l60">     60</a> 	# read (loop over) each line of the /proc/cpuinfo,
 80<a href="#l61" class="line" id="l61">     61</a> 	# and check if that line starts with &#39;model name&#39;,
 81<a href="#l62" class="line" id="l62">     62</a> 	# and if it does, remove all that is up to &#39;:&#39;
 82<a href="#l63" class="line" id="l63">     63</a> 	#   model name: cpu -&gt; cpu
 83<a href="#l64" class="line" id="l64">     64</a> 	while read -r line; do case $line in 
 84<a href="#l65" class="line" id="l65">     65</a> 		model\ name*) cpu=${line##*: }; break ;; 
 85<a href="#l66" class="line" id="l66">     66</a> 	esac; done &lt; /proc/cpuinfo
 86<a href="#l67" class="line" id="l67">     67</a> 	
 87<a href="#l68" class="line" id="l68">     68</a> 	# remove useless information.
 88<a href="#l69" class="line" id="l69">     69</a> 	cpu=${cpu% CPU*}
 89<a href="#l70" class="line" id="l70">     70</a> 	cpu=${cpu#*Core(TM) *}
 90<a href="#l71" class="line" id="l71">     71</a> 
 91<a href="#l72" class="line" id="l72">     72</a> 	print cpu &quot;$cpu&quot;
 92<a href="#l73" class="line" id="l73">     73</a> }
 93<a href="#l74" class="line" id="l74">     74</a> 
 94<a href="#l75" class="line" id="l75">     75</a> print_mem() {
 95<a href="#l76" class="line" id="l76">     76</a> 	# loop over /proc/meminfo with delimiter : to
 96<a href="#l77" class="line" id="l77">     77</a> 	# seperate strings
 97<a href="#l78" class="line" id="l78">     78</a> 	#   $n              $v       $_
 98<a href="#l79" class="line" id="l79">     79</a> 	#   MemTotal:       16156544 kB
 99<a href="#l80" class="line" id="l80">     80</a> 	# loop till $n is MemTotal or MemAvailable, 
100<a href="#l81" class="line" id="l81">     81</a> 	# take $v of that $n, and divide it by 1024.
101<a href="#l82" class="line" id="l82">     82</a> 	# 16156544 -&gt; 15777
102<a href="#l83" class="line" id="l83">     83</a> 	# source from pfetch from https://github.com/KittyKatt/screenFetch/issues/386
103<a href="#l84" class="line" id="l84">     84</a> 	while IFS=&#39;: &#39; read -r n v _; do case $n in 
104<a href="#l85" class="line" id="l85">     85</a> 		MemTotal) totalmem=$((v / 1024)) ;; 
105<a href="#l86" class="line" id="l86">     86</a> 		MemAvailable) availmem=$((v / 1024)) ;; 
106<a href="#l87" class="line" id="l87">     87</a> 	esac; done &lt; /proc/meminfo
107<a href="#l88" class="line" id="l88">     88</a> 
108<a href="#l89" class="line" id="l89">     89</a> 	print mem &quot;$((totalmem - availmem))M / ${totalmem}M&quot;
109<a href="#l90" class="line" id="l90">     90</a> }
110<a href="#l91" class="line" id="l91">     91</a> 
111<a href="#l92" class="line" id="l92">     92</a> print_gpu() {
112<a href="#l93" class="line" id="l93">     93</a> 	# similar to the cpu loop, except read from a pciutils program:
113<a href="#l94" class="line" id="l94">     94</a> 	#  X:XX.X VGA: XX Corporation XXX [GeForce XXX XXXX Rev. A] (rev aX)
114<a href="#l95" class="line" id="l95">     95</a> 	while read -r line; do case $line in 
115<a href="#l96" class="line" id="l96">     96</a> 			*VGA*)
116<a href="#l97" class="line" id="l97">     97</a> 				gpu=${line##*: }    # XX Corporation XXX [GeForce XXX XXXX Rev. A] (rev aX)
117<a href="#l98" class="line" id="l98">     98</a> 				gpu=${gpu%]*}       # XX Corporation XXX [GeForce XXX XXXX Rev. A
118<a href="#l99" class="line" id="l99">     99</a> 				gpu=${gpu#*[}       # GeForce XXX XXXX Rev. A
119<a href="#l100" class="line" id="l100">    100</a> 				gpu=${gpu% (*}      # (backup) &#39;(rev aX)&#39; removed
120<a href="#l101" class="line" id="l101">    101</a> 
121<a href="#l102" class="line" id="l102">    102</a> 				# some lspci implemetations such as busybox does not work.
122<a href="#l103" class="line" id="l103">    103</a> 				[ -n &quot;$gpu&quot; ] || break
123<a href="#l104" class="line" id="l104">    104</a> 
124<a href="#l105" class="line" id="l105">    105</a> 				print gpu &quot;$gpu&quot;
125<a href="#l106" class="line" id="l106">    106</a> 				unset gpu
126<a href="#l107" class="line" id="l107">    107</a> 			;; 
127<a href="#l108" class="line" id="l108">    108</a> 		esac; done &lt;&lt;-EOF
128<a href="#l109" class="line" id="l109">    109</a> 		$(lspci)
129<a href="#l110" class="line" id="l110">    110</a> 	EOF
130<a href="#l111" class="line" id="l111">    111</a> }
131<a href="#l112" class="line" id="l112">    112</a> 
132<a href="#l113" class="line" id="l113">    113</a> # read -r hostname &lt; /proc/sys/kernel/hostname
133<a href="#l114" class="line" id="l114">    114</a> read -r osrelease &lt; /proc/sys/kernel/osrelease
134<a href="#l115" class="line" id="l115">    115</a> read -r product_name &lt; /sys/devices/virtual/dmi/id/product_name
135<a href="#l116" class="line" id="l116">    116</a> read -r product_version &lt; /sys/devices/virtual/dmi/id/product_version
136<a href="#l117" class="line" id="l117">    117</a> . /etc/os-release
137<a href="#l118" class="line" id="l118">    118</a> 
138<a href="#l119" class="line" id="l119">    119</a> # shellcheck disable=SC2041
139<a href="#l120" class="line" id="l120">    120</a> # shellcheck disable=SC2086
140<a href="#l121" class="line" id="l121">    121</a> for pd in &#39;/var/db/kiss/installed/*&#39;; do
141<a href="#l122" class="line" id="l122">    122</a> 	set -- $pd
142<a href="#l123" class="line" id="l123">    123</a> 	[ $# -gt 1 ] &amp;&amp; pkgs=$# &amp;&amp; break
143<a href="#l124" class="line" id="l124">    124</a> done
144<a href="#l125" class="line" id="l125">    125</a> 
145<a href="#l126" class="line" id="l126">    126</a> print kern &quot;$osrelease&quot;
146<a href="#l127" class="line" id="l127">    127</a> print dist &quot;$NAME&quot;
147<a href="#l128" class="line" id="l128">    128</a> print_x11_wm
148<a href="#l129" class="line" id="l129">    129</a> print sh &quot;$SHELL&quot;
149<a href="#l130" class="line" id="l130">    130</a> print pkgs &quot;$pkgs&quot;
150<a href="#l131" class="line" id="l131">    131</a> print host &quot;$product_name $product_version&quot;
151<a href="#l132" class="line" id="l132">    132</a> print_uptime
152<a href="#l133" class="line" id="l133">    133</a> print_cpu
153<a href="#l134" class="line" id="l134">    134</a> print_mem
154<a href="#l135" class="line" id="l135">    135</a> #print_gpu</pre>
155</div>
156</body>
157</html>