#!/bin/bash

# SCRIPT 1
# Dimiourgiste ena script me onoma tis epilogis sas. To script 
# 8a prepei na dexetai akribos ena orisma.
# 1. Na eleghei to pli8os ton orismaton
# 2. Na eleghei an to orisma antistixei se arxeio poy yparxei
# To arxeio exei dedomena tis morfis:
# 192.168.1.1:100
# 192.168.1.2:100
# 192.168.1.3:500
# 192.168.1.4:350
# 192.168.1.5:200
# 
# 3. Afou ginoun oi parapano eleghoi, to script prepei na diavazei
# to arxeio grammi-grammi kai na ypologizei to a8risma tis teleftaias
# stilis

# Prosoxi A) Ta minimata la8ous ektiponontai stin e3odo la8on (echo "error" >&2)
#         B) Se periptosei la8ous prepei na ginete exodos me ton katallilo
#            kodiko sfalmatos (exit 1)

#######################################################

# 1
# an o arithmos ton orismaton ($#) einai diaforetikos
# tou 1, tote error kai exit
if [ "$#" -ne 1 ]; then
	echo "Usage: $0 FILE" >&2
	exit 1
fi

# 2
# an to arxeio pou dinei o xristis ($1) den yparxei
# tote error kai exit
if ! [ -e "$1" ]; then
	echo "$1 not found" >&2
	exit 1
fi


# an dwsei fakelo kai oxi arxeio
# tote error kai exit
if [ -d "$1" ]; then
	echo "$1 is a directory" >&2
	exit 1
fi


# 3
# Gia ka8e seira sto arxeio pou dinei o xristis ($1)
# pernoume to deftero pedio kai to prosthetoume sto $sum
sum=0
while read p; do
	add=$(echo "$p" | cut -d":" -f2)
	let "sum=sum + add";
done < "$1"

echo $sum
