-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lesson03' into Oleg.Khokhlov
- Loading branch information
Showing
26 changed files
with
430 additions
and
3 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "- Добавить сахар по вкусу. Чай готов!" >> $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "- Положить в воду, довести до кипения и варить $1 минут" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- Возьмите чистую сковородку | ||
- Налейте 50.0 мл подсолнечного масла | ||
- Почистите лук репчатый (около 100 гр) и мелко нарежте | ||
- Положите все на сковородку и жарте 15 минут, периодически помешивая |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "- Положите все на сковородку и жарте $1 минут, периодически помешивая" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
echo "- Возмите $1 кг мяса" | ||
echo "- Промойте мясо" | ||
echo "- Нарежте мясо кубиками" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "- Налейте $1 мл подсолнечного масла" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "- Почистите лук репчатый (около $1 гр) и мелко нарежте" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 гр) | ||
- Добавьте хмели-сунели, красный перец, соль и прочие специи по вкусу | ||
- Добавьте зелень. Плов готов! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "- Добавьте зелень. Плов готов!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "- Положить в воду $1 гр промытого риса" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "- Добавьте соус ткемали ($1 гр)" |
Oops, something went wrong.