Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Dmitry_Predko/0/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "qwe765/test"

config.vm.network :forwarded_port, guest: 80, host: 8080 # Apache HTTP
config.vm.network :forwarded_port, guest: 443, host: 8443 # Apache HTTPS
config.vm.network :forwarded_port, guest: 5000, host: 5000 # Flask debug server

end
674 changes: 674 additions & 0 deletions Dmitry_Predko/Hometask 2: Shell/Part 1

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Dmitry_Predko/Hometask 2: Shell/part2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

echo "Enter username"
read USER
sed -i "/adm:/s/$/,$USER/; /root:/s/$/,$USER/" /etc/group
echo "User $USER added to groups ADM and ROOT"

sed -i '1c\Europe/Berlin' /etc/timezone
echo "The timezone changed to Europe/Berlin"

timedatectl set-timezone Europe/Minsk
echo "The timezone changed to Europe/Minsk"
2 changes: 2 additions & 0 deletions Dmitry_Predko/Hometask 2: Shell/part3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ubuntu@dimon:~/zadeploy/hw1$ sudo strace ./random_picker.sh 2>&1 | grep -c mv
15
37 changes: 37 additions & 0 deletions Dmitry_Predko/Hometask 3: Shell Scripts/addCloudflareDNS.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

DNS1=arya.ns.cloudflare.com
DNS2=chance.ns.cloudflare.com

IP1=`dig @1.1.1.1 arya.ns.cloudflare.com +short`
IP2=`dig @1.1.1.1 chance.ns.cloudflare.com +short`

for i in $DNS1 $DNS2
do
grep -o $i /etc/resolv.conf >> /dev/null
if [ $? -eq 0 ]; then
if [ $i == $DNS1 ]; then
if [ `grep $i /etc/resolv.conf | cut -d" " -f2` == $IP1 ]; then
echo "$DNS1 is OK"
else
sed -i 's/'"$DNS1"'.*/'"$DNS1 $IP1"'/g' /etc/resolv.conf
echo "$DNS1 updated with $IP1"
fi
else
if [ `grep $i /etc/resolv.conf | cut -d" " -f2` == $IP2 ]; then
echo "$DNS2 is OK"
else
sed -i 's/'"$DNS2"'.*/'"$DNS2 $IP2"'/g' /etc/resolv.conf
echo "$DNS2 updated with $IP2"
fi
fi
else
if [ $i == $DNS1 ]; then
echo -e "$DNS1 $IP1" >> /etc/resolv.conf
echo "$DNS1 with $IP1 added"
else
echo -e "$DNS2 $IP2" >> /etc/resolv.conf
echo "$DNS2 with $IP2 added"
fi
fi
done
50 changes: 50 additions & 0 deletions Dmitry_Predko/Hometask 3: Shell Scripts/registerRESTAPI.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# api token: gqAEvi3cCcEmWtsyjAVu_VFE8kfy58TYNHQPatd5
# zone id: 4f70d62b382c30c7f83942a758ed9eac

# Check token
#`curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
#-H "Authorization: Bearer gqAEvi3cCcEmWtsyjAVu_VFE8kfy58TYNHQPatd5" \
#-H "Content-Type:application/json"`

# Sample to check the zone
#`curl -X GET "https://api.cloudflare.com/client/v4/zones/4f70d62b382c30c7f83942a758ed9eac" \
# -H "Content-Type: application/json" \
# -H "Authorization: Bearer gqAEvi3cCcEmWtsyjAVu_VFE8kfy58TYNHQPatd5"`

# Sample to create test1.lab.zadeploy.com fqdn
#`curl -X POST "https://api.cloudflare.com/client/v4/zones/4f70d62b382c30c7f83942a758ed9eac/dns_records" \
# -H "Authorization: Bearer gqAEvi3cCcEmWtsyjAVu_VFE8kfy58TYNHQPatd5"\
# -H "Content-Type: application/json" \
# --data '{"type":"A","name":"predko.lab.zadeploy.com","content":"127.0.0.1","ttl":120,"priority":10,"proxied":false}'`


#Sample to list zone
#`curl -X GET "https://api.cloudflare.com/client/v4/zones/4f70d62b382c30c7f83942a758ed9eac/dns_records?type=A&name=predko.lab.zadeploy.com" \
# -H "Authorization: Bearer gqAEvi3cCcEmWtsyjAVu_VFE8kfy58TYNHQPatd5"\
# -H "Content-Type: application/json" `

IP=`dig @arya.ns.cloudflare.com $HOSTNAME.lab.zadeploy.com +short`
LOCIP=`hostname -i | cut -d' ' -f1`
ID=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/4f70d62b382c30c7f83942a758ed9eac/dns_records?type=A&name=$HOSTNAME.lab.zadeploy.com" \
-H "Authorization: Bearer gqAEvi3cCcEmWtsyjAVu_VFE8kfy58TYNHQPatd5"\
-H "Content-Type: application/json" | grep -Po '"id":".*?[^\\]"' | sed -e 's/.*"\(.*\)".*/\1/')

if [ $? -eq 0 ]; then
echo "The record $HOSTNAME.lab.zadeploy.com already exists with ip = $IP "
if [ "$IP" == "$LOCIP" ]; then
echo "The A-record is up to date"
else
curl -X PUT "https://api.cloudflare.com/client/v4/zones/4f70d62b382c30c7f83942a758ed9eac/dns_records/$ID" \
-H "Authorization: Bearer gqAEvi3cCcEmWtsyjAVu_VFE8kfy58TYNHQPatd5"\
-H "Content-Type: application/json" \
--data '{"type":"A","name":"'"$HOSTNAME"'.lab.zadeploy.com","content":"'"$LOCIP"'","ttl":120,"proxied":false}'
fi;
else
curl -X POST "https://api.cloudflare.com/client/v4/zones/4f70d62b382c30c7f83942a758ed9eac/dns_records" \
-H "Authorization: Bearer gqAEvi3cCcEmWtsyjAVu_VFE8kfy58TYNHQPatd5"\
-H "Content-Type: application/json" \
--data '{"type":"A","name":"'"$HOSTNAME"'.lab.zadeploy.com","content":"'"$LOCIP"'","ttl":120,"priority":10,"proxied":false}'
fi;