consolidate all repos to one for archive

This commit is contained in:
2025-01-28 13:46:42 +01:00
commit a6610fbc7a
5350 changed files with 2705721 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
#!/bin/bash
# dodajanje stikov
./imenik_26097.sh -dodaj -ime "Nikola" -priimek "Petrov" -naslov "Ulica cesta" -posta 2000 -kraj "Maribor" -tel 123456789
./imenik_26097.sh -dodaj -ime "Zan" -priimek "Pols" -naslov "Lika" -posta 2000 -kraj "Maribor" -tel 123456789
./imenik_26097.sh -dodaj -ime "Nejc" -priimek "Kranjc" -naslov "Gosposvedska cesta" -posta 2000 -kraj "Maribor" -tel 123456789
./imenik_26097.sh -dodaj -ime "Jan" -priimek "Polo" -naslov "HHAA" -posta 459 -kraj "Ljubljana" -tel 123456789
./imenik_26097.sh -dodaj -ime "Jan" -priimek "Polo"
# iskanje stikov
./imenik_26097.sh -isci -ime "Jan"
./imenik_26097.sh -isci -posta 459
./imenik_26097.sh -isci -ime "Nikola" -priimek "Petrov"
# ker so id nakjucni ga na tak nacin pridobi, zbran je tretji v tem primeru
id=$(awk -F";" 'NR==3{print $1}' "imenik_26097.dat")
# spreminjanje stikov
./imenik_26097.sh -uredi -id "$id" -ime "IME"
./imenik_26097.sh -uredi -id "$id" -priimek "PRIIMEK"
# brisanje stikov
./imenik_26097.sh -izbrisi -id "$id"

View File

@@ -0,0 +1,119 @@
#!/bin/bash
input=("" "" "" "" "" "" "")
myFile=imenik_26097.dat
function potrdi(){
read -p "Potrdi? y/n : " -n 1 -r
if [[ $REPLY != "y" ]]; then
echo ""
echo "Prekinjeno!"
exit 1
fi
echo ""
}
function isciPod(){
formString=$(printf '%s;' "${input[@]/#/.*}")
if grep -q "$formString" "$myFile"; then
grep "$formString" "$myFile"
else
echo "Ni kontakta"
fi
}
function urediPod(){
# The '-F' option specifies the field separator as a semicolon and the '-v' option creates a variable 'ref' with the value of the first element of the 'input' array.
# The pattern to search for is '$1==ref', which means the first field of the line (i.e., the part of the line before the first semicolon) should match the value of 'ref'.
searchedLine=$(awk -F';' -v ref="${input[0]}" '$1==ref {print}' $myFile)
if [[ $searchedLine == "" ]]; then
echo "ERROR: Ni osebe z tem id"
exit 1
fi
IFS=';' read -r -a array <<< "$searchedLine"
for i in "${!input[@]}"; do
[[ "${input[$i]}" != "" ]] && array[$i]="${input[$i]}"
done
newLine=$(IFS=';' ; echo "${array[*]}")
# s substitution
# g all occurrences of the searched string should be replaced
sed -i "s|${searchedLine}|${newLine}|g" $myFile
echo "Urejeno uspesno."
}
function odstraniPod(){
#-i modify the file in-place.
# /d delete
sed -i "/${input[0]};/d" "$myFile"
echo "Kontakt zbrisan."
}
function dodajPod(){
input[0]=$(($RANDOM % 99999 + 1))
# Set any empty input values to "PRAZNO"
for i in "${!input[@]}"
do
if [[ -z "${input[$i]}" ]]; then
input[$i]="PRAZNO"
fi
done
# Append each input value to the file separated by ';'
printf "%s;" "${input[@]}" >> $myFile
echo "" >> $myFile
# Print success message
echo "Kontakt dodan ${input[@]}"
}
# The `! -f` operator checks if the file does not exist.
if [ ! -f "$myFile" ]; then
echo "" > $myFile
fi
selection=$1
shift
while [ $# -gt 0 ] ; do
case $1 in
-id) input[0]="$2" ;;
-ime) input[1]="$2" ;;
-priimek) input[2]="$2" ;;
-naslov) input[3]="$2" ;;
-posta) input[4]="$2" ;;
-kraj) input[5]="$2" ;;
-tel) input[6]="$2" ;;
*)
echo "ERROR napacen kljuc $1"
exit 1
;;
esac
shift
shift
done
potrdi
# izbiranje funkcije
case $selection in
-dodaj)
dodajPod
"$@" ;;
-izbrisi)
odstraniPod "$@" ;;
-isci)
isciPod "$@" ;;
-uredi)
urediPod "$@" ;;
*)
echo "ERROR napacen ukaz $selection"
exit 1
;;
esac

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@@ -0,0 +1,14 @@
./fs-26097.sh -izpis
./fs-26097.sh -ustvari /dev/sdb ext2
./fs-26097.sh -posodobi /dev/sdb1
mkdir ~/data
./fs-26097.sh -priklopi /dev/sdb1 ~/data
./fs-26097.sh -ustvariraid /dev/sdc /dev/sdd
./fs-26097.sh -izpisraid
./fs-26097.sh -hotspare /dev/sde
./fs-26097.sh -izpisraid
mkdir ~/raid
./fs-26097.sh -filesistem /dev/md0
./fs-26097.sh -priklopi /dev/md0 ~/raid

View File

@@ -0,0 +1,139 @@
#!/bin/bash
# sudo mdadm -S /dev/md0
function print(){
#izpisemo diske z lsblk
lsblk
}
function create(){
if [ ! "$2" ] || [ ! "$3" ]; then
echo "Use: $1 <disk> <file-system-type>"
exit 1
fi
#dodamo label gpt drivu
parted -s $2 mklabel gpt
#ustvarimo particijo 50% velikosti
parted -s "$2" mkpart primary 1 50%
#ustvarimo particijo 50% velikosti
parted -s "$2" mkpart primary 50% -- -1
#ustvarimo datotecni sistem
echo -e "y\n" | mkfs.$3 ${2}1
#ustvarimo datotecni sistem
echo -e "y\n" | mkfs.$3 ${2}2
}
function fs(){
if [ ! "$2" ] || [ ! "$3" ]; then
echo "Use: $1 <disk> <file-system-type>"
exit 1
fi
#dodamo filesistem
echo -e "y\n" | mkfs.$3 "$2"
}
function attach(){
if [ ! "$2" ] || [ ! "$3" ]; then
echo "Use: $1 <partition> <mount point>"
exit 1
fi
#priklopimo $2 particijo v $3 mount point
mount $2 $3
}
function update(){
if [ ! "$2" ]; then
echo "Use: $1 <partiton>"
exit 1
fi
#dodamo razsiritve ext4
tune2fs -O extents,uninit_bg,huge_file $2
#preverimo zbircni sistem
e2fsck -f $2
#dodamo recicle bin
tune2fs -j $2
}
function createRaid(){
if [ ! "$2" ] || [ ! "$3" ]; then
echo "Use: $1 <partition 1> <partition 2>"
exit 1
fi
#ustvari particjo z labelo msdos in dovolimo raid
parted -s $2 mklabel msdos
parted -s $2 mkpart primary 1 -- -1
parted -s $2 set 1 raid on
parted -s $3 mklabel msdos
parted -s $3 mkpart primary 1 -- -1
parted -s $3 set 1 raid on
#ustvarimo radi z imenom md0 in dodamo 2 diska v raid
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 ${2}1 ${3}1
}
function hotSpare(){
if [ ! "$2" ]; then
echo "Use: $1 <partiton>"
exit 1
fi
parted -s $2 mklabel msdos
parted -s $2 mkpart primary 1 -- -1
parted -s $2 set 1 raid on
#dodamo spare disk v raid
mdadm --manage /dev/md0 --add-spare ${2}1
}
function printRaid(){
#izpisemo detaile o raidu md0
mdadm --detail /dev/md0
}
function failure(){
if [ ! "$2" ]; then
echo "Use: $1 <partiton>"
exit 1
fi
#failamo particijo v raidu
mdadm --manage /dev/md0 --fail $2
}
function remove(){
if [ ! "$2" ]; then
echo "Use: $1 <partiton>"
exit 1
fi
#odstranimo disk iz raida
mdadm --manage /dev/md0 --remove $2
}
if [[ $EUID -ne 0 ]]; then
echo "Must be root"
exit 1
fi
case $1 in
-izpis) print ;;
-ustvari) create "$@" ;;
-filesistem) fs "$@" ;;
-priklopi) attach "$@" ;;
-posodobi) update "$@" ;;
-ustvariraid) createRaid "$@" ;;
-hotspare) hotSpare "$@" ;;
-izpisraid) printRaid "$@" ;;
-izpad) failure "$@" ;;
-odstrani) remove "$@" ;;
esac

View File

@@ -0,0 +1,19 @@
#!/bin/bash
backup_type=$1
backup_dir="/mnt/backup/26097"
source_dir="/home"
if [ "$backup_type" == "incremental" ]; then
for userdir in /home/*; do
rdiff-backup --include="$userdir/Maildir" --exclude="$userdir/*" $source_dir "$backup_dir/criinc"
done
elif [ "$backup_type" == "mirror" ]; then
for userdir in /home/*; do
rsync -va --include="$userdir/Maildir" --exclude="$userdir/*" $source_dir "$backup_dir/crimir"
done
else
echo "Napaka: Neveljaven način izdelave kopije."
exit 1
fi

View File

@@ -0,0 +1,18 @@
#!/bin/bash
backup_type=$1
backup_dir="/mnt/backup/26097"
source_dir="/home"
if [ "$backup_type" == "incremental" ]; then
for userdir in /home/*; do
rdiff-backup --exclude="$userdir/Maildir" $source_dir "$backup_dir/othinc"
done
elif [ "$backup_type" == "mirror" ]; then
for userdir in /home/*; do
rsync -va --exclude="$userdir/Maildir" $source_dir "$backup_dir/othmir"
done
else
echo "Napaka: Neveljaven način izdelave kopije."
exit 1
fi

View File

@@ -0,0 +1,10 @@
# Izdelava kopije kritičnih podatkov
1 * * * * /home/nik/Sola/SA/Naloga_5/backup-critical.sh incremental
#zato ker se zmotim bi rad mel opcijo da povlecem iz zgodovine
# Izdelava kopije ostalih podatkov
0 0 * * * /home/nik/Sola/SA/Naloga_5/backup-other.sh mirror
# ne portrebujem zgodovine za ne kriticne stvari

View File

@@ -0,0 +1,6 @@
#!/bin/bash
./backup-critical.sh incremental
./backup-other.sh mirror
./restore.sh

View File

@@ -0,0 +1,19 @@
#!/bin/bash
backup_criinc="/mnt/backup/26097/criinc/nik/Maildir"
destination_criinc="/home/nik/Maildir"
backup_othmir="/mnt/backup/26097/othmir"
destination_othmir="/home/nik"
if [ -d "$destination_dir" ]; then
read -p "POZOR: Obstojajo podatki v direktoriju $destination_dir. Nadomestim? (da/ne) " confirm
if [ "$confirm" != "da" ]; then
echo "Obnovitev prekinjena."
exit 1
fi
fi
# rsync -av $backup_othmir/ $destination_othmir
rdiff-backup --force --restore-as-of now $backup_criinc $destination_criinc

View File

@@ -0,0 +1,2 @@
Network: 10.0.10.32
Broadcast: 10.0.10.63

View File

@@ -0,0 +1,29 @@
#!/bin/bash
zazeni()
{
sudo netplan apply
}
# ustavi proces
ustvari()
{
sudo touch /etc/netplan/config.yaml
sudo echo "network:
version: 2
renderer: networkd
ethernets:
enp2s0:
dhcp4: no
addresses: [10.0.10.37/27]
gateway4: 10.0.10.33
nameservers:
addresses: [9.9.9.9]" > /etc/netplan/config.yaml
}
case $1 in
-zazeni) zazeni "$@" ;;
-ustvari) ustvari "$@" ;;
*) echo "napacen ukaz!" ;;
esac

View File

@@ -0,0 +1,24 @@
#!/bin/bash
sudo ufw enable
sudo ufw status
sudo ufw default allow incoming
sudo ufw allow https
sudo ufw allow ssh
sudo ufw allow 85/tcp
sudo ufw allow 888/tcp
sudo ufw allow 8085:8095/udp
sudo ufw allow from 10.10.0.39
sudo ufw allow from 10.30.0.0/24
sed -i 's/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/g' /etc/ufw/before.rules
sudo ufw status

View File

@@ -0,0 +1,69 @@
/tmp/pomembni_projekt/:
total 16
drwxrwxr-x+ 2 ps6 progskupina_26097 4096 May 25 23:33 projektA
drwxrwxr-x+ 2 ps6 progskupina_26097 4096 May 25 23:33 projektB
drwxrw-r-x+ 2 ps6 progskupina_26097 4096 May 25 23:33 projektC
drwxrwxr-x+ 2 ps6 progskupina_26097 4096 May 25 23:33 testi
/tmp/pomembni_projekt/projektA:
total 0
/tmp/pomembni_projekt/projektB:
total 0
/tmp/pomembni_projekt/projektC:
total 0
/tmp/pomembni_projekt/testi:
total 0
# file: tmp/pomembni_projekt/
# owner: ps6
# group: progskupina_26097
user::rwx
group::r-x
other::r-x
# file: tmp/pomembni_projekt//projektC
# owner: ps6
# group: progskupina_26097
user::rwx
group::r-x #effective:r--
mask::rw-
other::r-x
# file: tmp/pomembni_projekt//projektB
# owner: ps6
# group: progskupina_26097
user::rwx
user:ps2:r-x
user:ps3:rwx
user:ps4:rwx
group::r-x
mask::rwx
other::r-x
# file: tmp/pomembni_projekt//testi
# owner: ps6
# group: progskupina_26097
user::rwx
user:ps1:rwx
user:ps2:rwx
user:ps3:rwx
user:ps4:rwx
user:ps5:rwx
user:ps6:rwx
group::r-x
mask::rwx
other::r-x
# file: tmp/pomembni_projekt//projektA
# owner: ps6
# group: progskupina_26097
user::rwx
user:ps1:rwx
user:ps2:rwx
group::r-x
mask::rwx
other::r-x

View File

@@ -0,0 +1,43 @@
#!/bin/bash
echo "mkdir"
mkdir /tmp/pomembni_projekt
mkdir /tmp/pomembni_projekt/projektA
mkdir /tmp/pomembni_projekt/projektB
mkdir /tmp/pomembni_projekt/projektC
mkdir /tmp/pomembni_projekt/testi
echo "chown"
chown ps6:progskupina_26097 /tmp/pomembni_projekt
chown ps6:progskupina_26097 /tmp/pomembni_projekt/projektA
chown ps6:progskupina_26097 /tmp/pomembni_projekt/projektB
chown ps6:progskupina_26097 /tmp/pomembni_projekt/projektC
chown ps6:progskupina_26097 /tmp/pomembni_projekt/testi
echo "m"
setfacl -m m:rw- /tmp/pomembni_projekt/testi
setfacl -m m:rw- /tmp/pomembni_projekt/projektA
setfacl -m m:rw- /tmp/pomembni_projekt/projektB
setfacl -m m:rw- /tmp/pomembni_projekt/projektC
setfacl -m u:ps1:rwx /tmp/pomembni_projekt/projektA
setfacl -m u:ps2:rwx /tmp/pomembni_projekt/projektA
setfacl -m u:ps2:r-x /tmp/pomembni_projekt/projektB
setfacl -m u:ps3:rwx /tmp/pomembni_projekt/projektB
setfacl -m u:ps4:rwx /tmp/pomembni_projekt/projektB
# projekt C ni vpisano pravic
setfacl -m u:ps1:rwx /tmp/pomembni_projekt/testi
setfacl -m u:ps2:rwx /tmp/pomembni_projekt/testi
setfacl -m u:ps3:rwx /tmp/pomembni_projekt/testi
setfacl -m u:ps4:rwx /tmp/pomembni_projekt/testi
setfacl -m u:ps5:rwx /tmp/pomembni_projekt/testi
setfacl -m u:ps6:rwx /tmp/pomembni_projekt/testi

View File

@@ -0,0 +1,10 @@
#!/bin/bash
sudo groupadd progskupina_26097
sudo useradd -m -s /bin/bash -G progskupina_26097 ps1
sudo useradd -m -s /bin/bash -G progskupina_26097 ps2
sudo useradd -m -s /bin/bash -G progskupina_26097 ps3
sudo useradd -m -s /bin/bash -G progskupina_26097 ps4
sudo useradd -m -s /bin/bash -G progskupina_26097 ps5
sudo useradd -m -s /bin/bash -G progskupina_26097 ps6