Browse Source

Init

master
NaiJi ✨ 8 months ago
commit
ec5afc9e0c
  1. 179
      aptupdater.sh
  2. 143
      dbsshutil.sh
  3. 52
      rawjsonvaluereader.sh
  4. 75
      sqlite3.sh

179
aptupdater.sh

@ -0,0 +1,179 @@ @@ -0,0 +1,179 @@
#!/bin/bash
tryUpdateFromSd()
{
local sd_name=$1
# cut received line by / and take the third found result. (for /dev/sdb1 it's sdb1)
local sd_folder_name=$(echo "${sd_name}" | cut -f 3 -d '/')
exit_condition=false
while [ "$exit_condition" == false ]
do
echo "Do you want to update from ${sd_name}? (Y/n)"
read input_char
if [ "$input_char" == "Y" ] || [ "$input_char" == "y" ]
then
echo " - Create /media/iso-$sd_folder_name"
mkdir /media/iso-$sd_folder_name
echo " - Mount ${sd_name} in /media/iso-$sd_folder_name"
mount $sd_name /media/iso-$sd_folder_name
echo " - Update the package manager."
cp /etc/apt/sources.list /etc/apt/sources-backup.list
mkdir /home/temp-apt
mv /etc/apt/sources.list.d/* /home/temp-apt/
echo "deb [trusted=yes] file:/media/iso-$sd_folder_name orel main contrib" > /etc/apt/sources.list
echo " - Update packages."
apt update
apt upgrade
echo " - Unmount ${sd_name}"
umount /media/iso-$sd_folder_name
rm -rf /media/iso-$sd_folder_name
echo " - Restore the package manager."
mv /etc/apt/sources-backup.list /etc/apt/sources.list
mv /home/temp-apt/* /etc/apt/sources.list.d/
rm -rf /home/temp-apt/
exit_condition=true
exit 0
elif [ "$input_char" == "N" ] || [ "$input_char" == "n" ]
then
echo "Skip "${sd_name}""
exit_condition=true
else
echo "Please, type Y to agree or N to decline."
echo "Input Ctrl+C to exit."
fi
done
}
tryUpdateFromDrive()
{
# Show devices with fdisk -l
# Filter all lines which contain "sd*" (where * -- any latin letter from B to Z) except for "sd*:"
# cut by space character and take the first found result
# so it is: /dev/sdb1 , for example
sd_arr_raw=$(fdisk -l | egrep "sd[b-zB-Z][^:]" | cut -f 1 -d ' ')
amount_of_sd=0
for sd_raw in $sd_arr_raw
do
amount_of_sd=$(($amount_of_sd+1))
echo "${sd_raw}; ID=${amount_of_sd}"
done
if (( $amount_of_sd < 1 ))
then
echo "Couldn't find external drives. Please, make sure they are connected and available."
exit 1
else
for sd_raw in $sd_arr_raw
do
tryUpdateFromSd "${sd_raw}"
done
exot 0
fi
}
tryUpdateFromFile()
{
exit_condition=false
while [ "$exit_condition" == false ]
do
echo "Do you want to update from ${filename}? (Y/n)"
read input_char
if [ "$input_char" == "y" ] || [ "$input_char" == "Y" ]
then
echo " - Create /media/iso-$filename"
mkdir /media/iso-$filename
echo " - Mount ${filename} in /media/iso-$filename"
mount $filename /media/iso-$filename
echo " - Update the package manager."
cp /etc/apt/sources.list /etc/apt/sources-backup.list
mkdir /home/temp-apt
mv /etc/apt/sources.list.d/* /home/temp-apt/
echo "deb [trusted=yes] file:/media/iso-$filename orel main contrib" > /etc/apt/sources.list
echo " - Update packages."
apt update
apt upgrade
echo " - Unmount ${filename}"
umount /media/iso-$filename
rm -rf /media/iso-$filename
echo " - Restore the package manager."
mv /etc/apt/sources-backup.list /etc/apt/sources.list
mv /home/temp-apt/* /etc/apt/sources.list.d/
rm -rf /home/temp-apt/
exit_condition=true
updated=true
exit 0
elif [ "$input_char" == "n" ] || [ "$input_char" == "N" ]
then
exit_condition=true
exit 0
else
echo "Please, type Y to agree or N to decline."
echo "Input Ctrl+C to exit."
fi
done
}
printHelp()
{
echo "iso-updater - tool for updating OS packages by apt."
echo " "
echo "USAGE: iso-updater [-OPTIONS...] [ARGS]"
echo " "
echo "OPTIONS:"
echo "-h, --help Show brief instructions."
echo " "
echo "-d, --drive Update the system from drive."
echo " Make sure there is one and only one external drive "
echo " connected. The program will read its partisions and "
echo " try to upgrade the system from each of them."
echo " Thoroughly follow all the instructions after launch."
echo " "
echo "-f, --file [PATH] Update the system from an .iso file."
echo " Make sure there is an .iso file needed to update "
echo " the system from and that the file is being placed "
echo " exactly at PATH. Thoroughly follow all "
echo " the instructions after launch."
echo " "
echo "Example: sudo iso-updater --file /home/user/iso/very-very-cool-iso-file.iso"
echo " "
echo " "
exit 0
}
while test $# -gt 0; do
case "$1" in
-h|--help)
printHelp
;;
-d|--drive)
if [[ $UID != 0 ]]; then
echo "Please, run with sudo:"
echo "sudo $0 $*"
exit 1
fi
tryUpdateFromDrive
exit 0
;;
-f|--file)
if [[ $UID != 0 ]]; then
echo "Please, run with sudo:"
echo "sudo $0 $*"
exit 1
fi
shift
filename=$1
if [ ! -f "$filename" ]
then
echo "Couldn't find $filename. Please, use correct filename and make sure it does exist."
exit 1
fi
tryUpdateFromFile
exit 0
;;
esac
echo "Couldn't recognize $1."
echo " "
shift
done
printHelp
exit 0

143
dbsshutil.sh

@ -0,0 +1,143 @@ @@ -0,0 +1,143 @@
#!/bin/bash
TARGET_REMOTE_USER=adm0
TARGET_OWNER_USER=owner
TARGET_REMOTE_PATH=/usr/disp/
export PATH
if [ "$#" -ne "1" ] && [ "$#" -ne "2" ] && [ "$#" -ne "3" ]
then
echo "$0 --help "
exit 0
fi
if [ "$1" == "--help" ]
then
echo "sshdb - utility for simpler database management between local machines vie authorized_keys and rsync."
echo " "
echo "USAGE: sshdb [-FLAG] [ARGS..]"
echo " "
echo "FLAGS:"
echo "--help Show this sheet."
echo " "
echo "-g [IP] [|PATH] Copy database from remote machine to PATH/"
echo " or ./ if the PATH argument is missing."
echo " Example: sshdb -g 10.64.184.60"
echo " sshdb -g 10.64.184.60 ./tempdb/"
echo " "
echo "-l [IP] [|FILE] Copy database from FILE to remote machine"
echo " and execute initial maintenance from"
echo " ./database.sqlite if the FILE argument is missing."
echo " Example: sshdb -l 10.64.184.60"
echo " sshdb -l 10.64.184.60 /home/myuser/folder/folder2/database.sqlite"
echo " "
echo "-c [IP1] [IP2] Copy database from IP1 to IP2 and execute initial maintenance."
echo " Example: sshdb -c 172.23.16.176 10.64.184.60"
echo " "
exit 0
fi
# -----------------------------------
if [ "$1" == "-g" ]
then
if [ -z "$(cat ~/.ssh/id_rsa.pub)" ]
then
echo "SSH key is needed. Proceed to generating it by ssh-keygen."
exit 1
fi
if [ -z "$2" ]
then
echo "Target IP is needed. Run $0 --help."
exit 1
fi
LOCAL_DATABASE_PATH="./"
if [ ! -z "$3" ]
then
LOCAL_DATABASE_PATH="$3"
fi
if [ ! -d $LOCAL_DATABASE_PATH ]
then
echo "Path $LOCAL_DATABASE_PATH is missing."
exit 1
fi
ssh-copy-id "$TARGET_REMOTE_USER"@"$2"
ssh "$TARGET_REMOTE_USER"@"$2" "sudo apt install rsync"
rsync "$TARGET_REMOTE_USER"@"$2":${TARGET_REMOTE_PATH}database.sqlite $LOCAL_DATABASE_PATH
exit 0
fi
# -----------------------------------
if [ "$1" == "-l" ]
then
if [ -z "$(cat ~/.ssh/id_rsa.pub)" ]
then
echo "SSH key is needed. Proceed to generating it by ssh-keygen."
exit 1
fi
if [ -z "$2" ]
then
echo "Target IP is needed. Run $0 --help."
exit 1
fi
LOCAL_DATABASE_FILE="./database.sqlite"
if [ ! -z "$3" ]
then
LOCAL_DATABASE_FILE="$3"
fi
if [ ! -f $LOCAL_DATABASE_FILE ]
then
echo "File $LOCAL_DATABASE_FILE is missing."
exit 1
fi
ssh-copy-id "$TARGET_REMOTE_USER"@"$2"
ssh "$TARGET_REMOTE_USER"@"$2" "sudo apt install rsync"
rsync $LOCAL_DATABASE_FILE "$TARGET_REMOTE_USER"@"$2":/home/"$TARGET_REMOTE_USER"/
ssh "$TARGET_REMOTE_USER"@"$2" "sudo mv -f ./database.sqlite ${TARGET_REMOTE_PATH}database.sqlite && sudo chown ${owner}:${owner} ${TARGET_REMOTE_PATH}database.sqlite"
exit 0
fi
# -----------------------------------
if [ "$1" == "-c" ]
then
if [ -z "$(cat ~/.ssh/id_rsa.pub)" ]
then
echo "SSH key is needed. Proceed to generating it by ssh-keygen."
exit 1
fi
if [ -z "$2" ]
then
echo "Target IP of the first machine is needed. Run $0 --help."
exit 1
fi
if [ -z "$3" ]
then
echo "Target IP of the second machine is needed. Run $0 --help."
exit 1
fi
ssh-copy-id "$TARGET_REMOTE_USER"@"$2"
ssh "$TARGET_REMOTE_USER"@"$2" "sudo apt install rsync"
rsync "$TARGET_REMOTE_USER"@"$2":${TARGET_REMOTE_PATH}database.sqlite ./.temp.sqlite
ssh-copy-id "$TARGET_REMOTE_USER"@"$3"
ssh "$TARGET_REMOTE_USER"@"$3" "sudo apt install rsync"
rsync ./.temp.sqlite "$TARGET_REMOTE_USER"@"$3":/home/"$TARGET_REMOTE_USER"/
ssh "$TARGET_REMOTE_USER"@"$3" "sudo mv -f ./database.sqlite ${TARGET_REMOTE_PATH}database.sqlite && sudo chown ${owner}:${owner} ${TARGET_REMOTE_PATH}database.sqlite"
rm -f ./.temp.sqlite
exit 0
fi

52
rawjsonvaluereader.sh

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
# Manually extracting value from settings JSON file
FOUND_CURSOR=0
JSON_PATH=/var/pos/config/UiSettings.cfg
echo " " > /tmp/checkIcons.log
# Are we launcing it for the first time (assuming currently cursor is visible)
if [[ ! -d /usr/share/icons/default-backup ]]
then
mv /usr/share/icons/default /usr/share/icons/default-backup
cp -r /usr/share/icons/xcursor-transparent /usr/share/icons/default
fi
if [[ ! -f ${JSON_PATH} ]]
then
echo "${JSON_PATH} is missing" >> /tmp/checkIcons.log
exit 0
fi
while IFS= read -r line
do
if [ ! -z "$(echo \"${line}\" | grep \"isCursorVisible\")" ]
then
echo "Found JSON key about cursor visibility" >> /tmp/checkIcons.log
FOUND_CURSOR=1
fi
if [ "$FOUND_CURSOR" = "1" ] && [ ! -z "$(echo \"$line\" | grep \"value\")" ]
then
if [ ! -z "$(echo \"${line}\" | grep 0)" ]
then
echo "Disable cursor visibility." >> /tmp/checkIcons.log
rm -rf /usr/share/icons/default
cp -r /usr/share/icons/xcursor-transparent /usr/share/icons/default
fi
if [ ! -z "$(echo \"${line}\" | grep 1)" ]
then
echo "Enable cursor visibility." >> /tmp/checkIcons.log
rm -rf /usr/share/icons/default
cp -r /usr/share/icons/default-backup /usr/share/icons/default
fi
fi
if [ ! -z "$(echo \"${line}\" | grep })" ]
then
FOUND_CURSOR=0
fi
done < ${JSON_PATH}

75
sqlite3.sh

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
#!/bin/bash
database_path=" "
exit_condition=false
printLastCassette()
{
last_id=$(sqlite3 "${database_path}" "SELECT MAX(id) FROM cassete;")
if [ -z ${last_id} ]
then
echo "Couldn't find cassete entries in \"${database_path}\"."
exit 0
fi
printCassetteById $last_id
}
printCassetteById()
{
local cassette_id=$1
local deposit_ids=$(sqlite3 "${database_path}" "SELECT id FROM deposit WHERE cassete_id = \"${cassette_id}\";")
local validation_id=$(sqlite3 "${database_path}" "SELECT MAX(id) FROM deposit WHERE cassete_id = \"${cassette_id}\";")
if [ -z ${validation_id} ]
then
echo "Couldn't find deposits by cassete id ${cassette_id} in \"${database_path}\"."
else
local cassette_sum=0
local cassette_bills_amount=0
for i in $deposit_ids
do
deposit_sum=$(sqlite3 "${database_path}" "SELECT SUM(value) FROM bills WHERE deposit_id = \"${i}\";")
if [ ! -z ${deposit_sum} ]
then
cassette_sum=$(($cassette_sum+$deposit_sum))
operand=$(sqlite3 "${database_path}" "SELECT COUNT(id) FROM bills WHERE deposit_id = \"${i}\";")
cassette_bills_amount=$(($cassette_bills_amount+$operand))
else
echo "Deposit ${i} is registered but also empty."
fi
done
echo "Sum of cash: ${cassette_sum}"
echo "Amount of bills: ${cassette_bills_amount}"
exit_condition=true
fi
}
if [ ! -f "$database_path" ]
then
echo "Missing \"${database_path}\" database."
exit 0
fi
while [ "$exit_condition" == false ]
do
echo "Show information from the last registered cassete? (y/n)"
read input_char
if [ "$input_char" == "y" ] || [ "$input_char" == "Y" ]
then
printLastCassette
elif [ "$input_char" == "n" ] || [ "$input_char" == "N" ]
then
echo "Input specific cassete id: "
read cassette_id
printCassetteById $cassette_id
else
echo "Please input y to show information about the last active cassete or n to specify cassete id on your own."
echo " "
fi
done
Loading…
Cancel
Save