20/05/2015

TrueAbility Linux Showdown 8 - Round 1

I think TrueAbility is one of cool projects I've seen lately, I really love its model!

For professionals, you can "improve your skills through technical walkthroughs and practice what you have learned on a real server"!

On the other hand, for employers or companies that want to hire system admins/engineer/devops can "Reduce time-to-hire by spending more time with the candidates who have proven their ability to do the job"!

So, you can do it for fun, improve/test your skills ... or to find a good job! One of recently challenges was "Linux Showdown 8", I love scripting and it was really cool :D

You can find more info about "Round 1", and this was my -quick and dirty- solution :-)

#! /bin/bash
#
# You can find more info about this competition at following url:
# https://community.trueability.com/t/the-sub-par-assembler-round-1/911
#

#Main section.
spasm_dir_path="."
#spasm_dir_path="/var/lib/spasm"
print_error () {
  echo "Operation is not supported or syntax error!"
}

#Check if there is any syntax error.
if ! [[ $(echo "$1" | grep -P "\b(mov|add|sub|mul|eq|lt|gt)\b") ]]; then
  print_error
  exit 1
elif ! [[ $(echo "$2" | grep -P "\bR(1|2|3|4)\b") ]]; then
  print_error
  exit 1
elif [[ ! $(echo "$3" | grep -P "(R(1|2|3|4)\b|%\b)") ]]; then
  print_error
  exit 1
fi

#Get target number.
target_number=$(cat ${spasm_dir_path}/$2 | grep -P -o "\d+")

#Get value number.
if [[ $(echo "$3" | grep -P "\bR(1|2|3|4)\b") ]]; then
  value_number=$(cat ${spasm_dir_path}/$3 | grep -P -o "\d+")
elif [[ $(echo "$3" | grep -P "%\b") ]]; then
  value_number=$(echo "$3" | grep -P -o "\d+")
fi

#Check Operations.
case $1 in
  mov)
  echo $value_number > ${spasm_dir_path}/$2
;;
  add)
  [[ -f ${spasm_dir_path}/$2 ]] && echo $(( $target_number + $value_number )) > ${spasm_dir_path}/$2 || print_error; exit 1
;;
  sub)
  [[ -f ${spasm_dir_path}/$2 ]] && echo $(( $target_number - $value_number )) > ${spasm_dir_path}/$2 || print_error; exit 1
;;
  mul)
  [[ -f ${spasm_dir_path}/$2 ]] && echo $(( $target_number * $value_number )) > ${spasm_dir_path}/$2 || print_error; exit 1
;;
  eq)
  [[ $target_number -eq $value_number ]] && echo -n "0" > ${spasm_dir_path}/CP || echo -n "1" > ${spasm_dir_path}/CP
;;
  lt)
  [[ $target_number -lt $value_number ]] && echo -n "0" > ${spasm_dir_path}/CP || echo -n "1" > ${spasm_dir_path}/CP
;;
  gt)
  [[ $target_number -gt $value_number ]] && echo -n "0" > ${spasm_dir_path}/CP || echo -n "1" > ${spasm_dir_path}/CP
;;
esac
Powered by Blogger.

Hello, my name is Ahmed AbouZaid, I'm a passionate Tech Lead DevOps Engineer. 👋

I specialize in Cloud-Native and Kubernetes. I'm also a Free/Open source geek and book author. My favorite topics are DevOps transformation, DevSecOps, automation, data, and metrics.

More about me ➡️

Contact Me

Name

Email *

Message *

Start Your DevOps Engineer Journey!

Start Your DevOps Engineer Journey!
Start your DevOps career for free the Agile way in 2024 with the Dynamic DevOps Roadmap ⭐

Latest Post

Bootstrap Cloud-Native bootstrappers like Crossplane with K3d - Automation

I created a logo for the Crossplane Bootstrapper because all good projects deserve a logo. 😁 TL;DR ...

Popular Posts

Blog Archive