bash-toys/toys/fake-work.sh

136 lines
3.5 KiB
Bash
Executable File

#! /bin/bash
FAKER=$1;
if [ "$FAKER" = "hex" ]; then
while true; do head -c200 /dev/urandom | \
od -An -w50 -x | \
grep -E --color "([[:alpha:]][[:digit:]]){2}";
sleep 0.5;
done;
elif [ "$FAKER" = 'compile' ]; then
collect()
{
while read line; do
if [ -d "$line" ];then
(for i in "$line"/*;do echo $i;done)|sort -R|collect
echo $line
elif [[ "$line" == *".h" ]];then
echo $line
fi
done
}
sse="$(awk '/flags/{print;exit}' </proc/cpuinfo|grep -o 'sse\S*'|sed 's/^/-m/'|xargs)"
flags=""
pd="\\"
while true;do
collect <<< /usr/include|cut -d/ -f4-|
(
while read line;do
if [ "$(dirname "$line")" != "$pd" ];then
x=$((RANDOM%8-3))
if [[ "$x" != "-"* ]];then
ssef="$(sed 's/\( *\S\S*\)\{'"$x,$x"'\}$//' <<< "$sse")"
fi
pd="$(dirname "$line")"
opt="-O$((RANDOM%4))"
if [[ "$((RANDOM%2))" == 0 ]];then
pipe=-pipe
fi
case $((RANDOM%4)) in
0) arch=-m32;;
1) arch="";;
*) arch=-m64;;
esac
if [[ "$((RANDOM%3))" == 0 ]];then
gnu="-D_GNU_SOURCE=1 -D_REENTRANT -D_POSIX_C_SOURCE=200112L "
fi
flags="gcc -w $(xargs -n1 <<< "opt pipe gnu ssef arch"|sort -R|(while read line;do eval echo \$$line;done))"
fi
if [ -d "/usr/include/$line" ];then
echo $flags -shared $(for i in /usr/include/$line/*.h;do cut -d/ -f4- <<< "$i"|sed 's/h$/o/';done) -o "$line"".so"
sleep $((RANDOM%2+1))
else
line=$(sed 's/h$//' <<< "$line")
echo $flags -c $line"c" -o $line"o"
sleep 0.$((RANDOM%4))
fi
done
)
done
elif [ "$FAKER" = 'code' ]; then
function randstatus() {
bsize=4096
r_rate=$(echo "$RANDOM/32767 * $bsize * 1.5 + $bsize / 4" | bc -l | sed 's/\..*$//')
r_min=2
r_max=4
r_val=$(($r_min + $RANDOM % $(($r_max - $r_min)) ))
i=0
dd if=/dev/urandom bs=$bsize count=$r_val 2> /dev/null \
| pv -L $bsize -s $(($r_val * bsize)) > /dev/null
}
function randout() {
r_file=$1;
#r_file=$(find $1 -name '*.php|*.js' | sort -R | head -n 1)
echo "# $r_file"
grep '^\s*/\*.*\*/\s*$' $r_file \
| sed 's:[/\*]::g' \
| sed -e 's:^\s\+::' -e 's:\s\+$::' \
| sed -e 's:^\W\+::' \
| grep -v '^$' \
| while read line; do
echo $line
sleep $(printf "%0.2f" $(echo "$((($RANDOM%4)+1))/4" | bc -l))
done
}
function randmessage() {
key=$(tr -dc A-Fa-f0-9 </dev/urandom | head -c 32);
random_number=$(( ( RANDOM % 10 ) + 1 )) # 1 to 10
restore='\033[0m';
if [ $random_number = 10 ]; then
msgs=("ERROR" "NOK" "CONNECTION FAILED");
color='\033[00;91m';
lcolor='\033[01;91m';
else
msgs=("OK" "DONE" "CREATED" "PASSED" "COMPLETE")
color='\033[00;92m';
lcolor='\033[01;92m';
fi
msg=${msgs[$RANDOM % ${#msgs[@]} ]};
msg=$(echo -e "${color}${msg}${lcolor}${restore}");
echo "$key - $msg"
echo ""
}
files=$(find $HOME -regex ".*/.*\.\(html\|yml\|toml\|cs\|c\|rb\|py\|xml\|rs\|js\|php\|css\)");
while true; do
randout $(echo "$files" | shuf -n 1);
randstatus
randmessage
sleep 2
done
else
echo ""
echo "USAGE:"
echo "$0 [hex|compile|code]"
echo ""
fi