Skip to content

Commit

Permalink
Merge branch 'lesson03' into Oleg.Khokhlov
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegH-ua committed Nov 3, 2018
2 parents 9eaf398 + 066c8aa commit 2b882ff
Show file tree
Hide file tree
Showing 26 changed files with 430 additions and 3 deletions.
1 change: 0 additions & 1 deletion 03-bash/README1.md

This file was deleted.

31 changes: 31 additions & 0 deletions 03-bash/addsyspath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

path_to_add=/usr/local/bin

if [ -n "$1" ]
then
path_to_add=$1
fi

nnn=1
while [ 0 ]
do
pathn=$(cut -f$nnn -d":" <<< $PATH)
if [ ! -n "$pathn" ]; then
break
fi
if [ $pathn = "$path_to_add" ]
then
echo "$path_to_add already in the PATH."
exit 0
fi
let nnn=nnn+1
done

echo "Adding $path_to_add to PATH..."
export PATH=$PATH:${path_to_add}

if [ -n "$2" ]
then
cp $0 "/etc/profile.d/$2"
fi
15 changes: 15 additions & 0 deletions 03-bash/task1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Date: Ср, 24 окт 2018 10:54:18 +0300
---- Hardware ----
CPU: "Intel(R) Pentium(R) Silver N5000 CPU @ 1.10GHz"
RAM: 4096 MB
Motherboard: "LENOVO", "LNVNB161216"
System serial number: PF199ZW8
---- System ----
OS Distribution: "Ubuntu 18.04.1 LTS"
Kernel Version: 4.19.0-rc8+
Hostname: olegh-ideapad
---- Network ----
enp1s0: -/-
lo: 127.0.0.1/8
wlp2s0: 192.168.1.24/24
---- "EOF" ----
152 changes: 152 additions & 0 deletions 03-bash/task1.sh
Original file line number Diff line number Diff line change
@@ -1 +1,153 @@
#!/bin/bash
# LESSON03: task1.sh - system information

# check lang
LNG='en'
SYS_LANG=${LANG::5}
if [ "$SYS_LANG" = "uk_UA" ]
then
LNG='ua'
fi

# output file name
FNAME=~/bash/task1.out

declare -i NFILES=0

# check and parse command line arguments
for arg
do
if [ $arg = '-h' ] || [ $arg = '--help' ]
then
if [ $LNG = 'ua' ]
then
echo 'Завдання03: учбовий скрип shell: інформація про систему'
echo 'arguments:'
echo ' -h or --help - this help'
echo ' -n N - max number of output files'
echo ' filename - path and name of file to store system information'
else
echo 'Lesson03: educative shell script: system info'
echo 'arguments:'
echo ' -h or --help - this help'
echo ' -n N - max number of output files'
echo ' filename - path and name of file to store system information'
fi
exit 0
elif [ $NKEY ]
then
NKEY=''
if [ $arg -ge "1" ]
then
NFILES=$arg
else
if [ $LNG = 'ua' ]
then
echo 'Треба вказа3ти ціле число файлів після ключа -n' 1>&2
else
echo 'Expected integer max file number after -n key.' 1>&2
fi
exit 1
fi
elif [ $arg = '-n' ]
then
NKEY='1'
else
FNAME=$arg
fi
done

DIR="$(dirname $FNAME)"
echo "DIR is $DIR"
mkdir -p "$DIR"
if [ $? -ne 0 ]
then
if [ $LNG = 'ua' ]
then
echo "Неможливо збудувати повний путь '$DIR'." 1>&2
else
echo "Can't create path: '$DIR'." 1>&2
fi
exit 2
fi

if [ -f "$FNAME" ]
then
echo "File '$FNAME' exists. Renaming..."
# loop
NN='0000'
while [ "0" ]
do
FNAME2="$FNAME-"`date +%Y%m%d`-`printf "%04d" $NN`
#echo $FNAME2
if [ ! -f "$FNAME2" ]
then
break;
fi
let NN=NN+1
done
mv $FNAME $FNAME2
fi

if (( $NFILES > 0 ))
then
echo "NFiles = $NFILES"
#delete old files (not only for current date)
FLIST=$(ls -1 -t $FNAME-????????-????)
#skip NFILES lines, else (if any) - remove
#echo $FLIST
FILEN=0
while read -r line
do
let FILEN=FILEN+1
if [[ $FILEN -gt $NFILES ]]
then
echo "Removing old file '$line'..."
rm $line
fi
done <<< $FLIST
fi

echo "Using output file '$FNAME'..."
echo -n "Date: " > $FNAME
date "+%a, %d %h %Y %T %z" >> $FNAME
echo "---- Hardware ----" >> $FNAME
CPU=$(sudo dmidecode -s processor-version)
echo "CPU: \"$CPU\"" >> $FNAME
MEMGB=$(sudo dmidecode -q | grep -e "Size: [0-9][0-9][0-9][0-9] MB")
MEMGB=$(cut -f2 -d":" <<< $MEMGB)
echo "RAM:$MEMGB" >> $FNAME
MBOARD="\"$(sudo dmidecode -s baseboard-manufacturer)\", \"$(sudo dmidecode -s baseboard-product-name)\""
echo "Motherboard: $MBOARD" >> $FNAME
SSN=$(sudo dmidecode -s system-serial-number)
echo "System serial number: $SSN" >> $FNAME

echo "---- System ----" >> $FNAME
OS_ABOUT=$(hostnamectl | grep "Operating System")
OS_ABOUT=${OS_ABOUT:20}
echo "OS Distribution: \"$OS_ABOUT\"" >> $FNAME
KERNEL_VER=$(uname -r)
echo "Kernel Version: $KERNEL_VER" >> $FNAME
HOST_NAME=$(hostname)
echo "Hostname: $HOST_NAME" >> $FNAME

echo "---- Network ----" >> $FNAME
IFLIST=$(ls -1 /sys/class/net/)

while read -r line
do
echo -n $line >> $FNAME
IPLINE=$(ip address show dev $line | grep "inet ")
if [ -n "$IPLINE" ]
then
#IPADDR=$(cut -f6 -d" " <<< $IPLINE)
IPADDR=$(awk '{ print $2}' <<< $IPLINE)
else
IPADDR="-/-"
fi
echo ": $IPADDR" >> $FNAME
done <<< $IFLIST


echo "---- \"EOF\" ----" >> $FNAME
echo "Done.Buy!"
80 changes: 80 additions & 0 deletions 03-bash/task2.sh
Original file line number Diff line number Diff line change
@@ -1 +1,81 @@
#!/bin/bash
# INSTALLER for task1.sh

# check lang
LNG='en'
SYS_LANG=${LANG::5}
if [ "$SYS_LANG" = "uk_UA" ]
then
LNG='ua'
fi

# check and parse command line arguments
for arg
do
if [ $arg = '-h' ] || [ $arg = '--help' ]
then
if [ $LNG = 'ua' ]
then
echo 'Завдання03: учбовий скрип shell: інсталляція скрипта task1.sh інформації про систему'
else
echo 'Lesson03: educative shell script: system info task1.sh installator'
fi
exit 0
else
if [ $LNG = 'ua' ]
then
echo 'Некоректні параметри командного рядка' 1>&2
else
echo 'Illegal command line arguments' 1>&2
fi
exit 1
fi
done

DIR=/usr/local/bin
PROGNAME=task1.sh

if [ ! -f "$PROGNAME" ]
then
if [ $LNG = 'ua' ]
then
echo "Програмний файл $PROGNAME не знайдено" 1>&2
else
echo "Can't find file $PROGAME" 1>&2
fi
exit 1
fi

echo "Installing $PROGNAME into $DIR..."
mkdir -p "$DIR"
if [ $? -ne 0 ]
then
if [ $LNG = 'ua' ]
then
echo "Неможливо збудувати повний путь '$DIR'." 1>&2
else
echo "Can't create path: '$DIR'." 1>&2
fi
exit 2
fi

cp "$PROGNAME" "$DIR/"
#check copy result
if [ $? -ne 0 ]
then
if [ $LNG = 'ua' ]
then
echo "Неможливо встановити файл $PROGNAME у каталог '$DIR'." 1>&2
else
echo "Can't install $PROGNAME into '$DIR'." 1>&2
fi
exit 2
fi

#set read and execute for all. write only for owner
chmod 755 "$DIR/$RPOGNAME"

#add $DIR to system path
./addsyspath.sh "$DIR" "path_to_task1.sh"

echo "Done.Buy!"
20 changes: 20 additions & 0 deletions 03-make/cook-it/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

AMOUNT?=1

all: soup pilaf tea

soup: soup.sh water meat rice fried_onion walnuts sause spices
@./soup.sh $(AMOUNT) > $@

fried_onion: oil onion
@./fry_onion.sh $(AMOUNT) >$@

pilaf: pilaf.sh water rice meat fried_onion spices
@./pilaf.sh $(AMOUNT) >$@

tea: water boil
@echo "Рецепт приготовления $(AMOUNT) л чая" > $@
@./water $(AMOUNT) >>$@
@echo "- Взять 50 гр чайного листа" >> $@
@./boil 1 >> $@
@echo "- Добавить сахар по вкусу. Чай готов!" >> $@
3 changes: 3 additions & 0 deletions 03-make/cook-it/boil
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "- Положить в воду, довести до кипения и варить $1 минут"
4 changes: 4 additions & 0 deletions 03-make/cook-it/fried_onion
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Возьмите чистую сковородку
- Налейте 50.0 мл подсолнечного масла
- Почистите лук репчатый (около 100 гр) и мелко нарежте
- Положите все на сковородку и жарте 15 минут, периодически помешивая
3 changes: 3 additions & 0 deletions 03-make/cook-it/fry
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "- Положите все на сковородку и жарте $1 минут, периодически помешивая"
8 changes: 8 additions & 0 deletions 03-make/cook-it/fry_onion
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

A=$1

echo "- Возьмите чистую сковородку"
./oil $(bc -q <<< "$A*0.5")
./onion $(bc -q <<< "$A")
./fry 15
8 changes: 8 additions & 0 deletions 03-make/cook-it/fry_onion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

A=$1

echo "- Возьмите чистую сковородку"
./oil $(bc -q <<< "$A*0.5")
./onion $(bc -q <<< "$A")
./fry 15
6 changes: 6 additions & 0 deletions 03-make/cook-it/meat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo "- Возмите $1 кг мяса"
echo "- Промойте мясо"
echo "- Нарежте мясо кубиками"

3 changes: 3 additions & 0 deletions 03-make/cook-it/oil
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "- Налейте $1 мл подсолнечного масла"
3 changes: 3 additions & 0 deletions 03-make/cook-it/onion
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "- Почистите лук репчатый (около $1 гр) и мелко нарежте"
16 changes: 16 additions & 0 deletions 03-make/cook-it/pilaf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Рецепт приготовления 1 кг плова
- Возмите .25 кг мяса
- Промойте мясо
- Нарежте мясо кубиками
- Положите все на сковородку и жарте 10 минут, периодически помешивая
- Возьмите чистую сковородку
- Налейте 50.0 мл подсолнечного масла
- Почистите лук репчатый (около 100 гр) и мелко нарежте
- Положите все на сковородку и жарте 15 минут, периодически помешивая
- Положить в воду 150 гр промытого риса
- Положить в воду, довести до кипения и варить 10 минут
- Добавьте обжаренное мясо, лук и морковь
- Положить в воду, довести до кипения и варить 15 минут
- Добавьте соус ткемали (50 гр)
- Добавьте хмели-сунели, красный перец, соль и прочие специи по вкусу
- Добавьте зелень. Плов готов!
15 changes: 15 additions & 0 deletions 03-make/cook-it/pilaf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

A=$1

echo "Рецепт приготовления $A кг плова"
./meat $(bc -q <<< "$A*0.25")
./fry 10
./fry_onion.sh $(bc -q <<< "$A*100")
./rice $(bc -q <<< "$A*150")
./boil 10
echo "- Добавьте обжаренное мясо, лук и морковь"
./boil 15
./sause $(bc -q <<< "$A*50")
./spices
echo "- Добавьте зелень. Плов готов!"
3 changes: 3 additions & 0 deletions 03-make/cook-it/rice
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "- Положить в воду $1 гр промытого риса"
3 changes: 3 additions & 0 deletions 03-make/cook-it/sause
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "- Добавьте соус ткемали ($1 гр)"
Loading

0 comments on commit 2b882ff

Please sign in to comment.