Skip to content

Commit

Permalink
Added config files to run the script
Browse files Browse the repository at this point in the history
  • Loading branch information
sancoderhost committed Sep 25, 2023
1 parent 0f61c2b commit d331ca6
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 42 deletions.
89 changes: 47 additions & 42 deletions check7.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
#!/bin/bash

SOURCE=/sdcard/DCIM
SOURCE2=/sdcard/Music/

SOURCE3=/sdcard/beatbox/
SOURCE4=/sdcard/syncnotes/
DESTINATION2=/home/sanbotbtrfs/Desktop/songs/phonesync/
DESTINATION3=/home/sanbotbtrfs/Desktop/1/Pixel_backup/beatboxsync/
DESTINATION4=/home/sanbotbtrfs/Desktop/1/Pixel_backup/syncnotes/
DESTINATION=/home/sanbotbtrfs/Desktop/1/Pixel_backup/rsync-data/
SITESOURCE=/home/sanbotbtrfs/Documents/savedpage/offlinesite
SITEDEST=/data/data/com.termux/files/usr/share/apache2/default-site/htdocs
source ./main.conf

TUNERROR=0
volcontol()
{
ssh -i ~/laptopkey sanbot@localhost -p 2222 "pactl set-sink-volume @DEFAULT_SINK@ $1% "
ssh -i $IDENTITY_KEY sanbot@localhost -p $SSHPORT "pactl set-sink-volume @DEFAULT_SINK@ $1% "

toast=$( ssh -i ~/laptopkey sanbot@localhost -p 2222 pactl list sinks | awk -F / '/^[[:space:]]Volume/ {print $2}' )
toast=$( ssh -i $IDENTITY_KEY sanbot@localhost -p $SSHPORT pactl list sinks | awk -F / '/^[[:space:]]Volume/ {print $2}' )
termux-toast -g top "$toast"

}
sshtunnel()
{
host=$(ping -c 1 laptop.local )
host=$(ping -c 1 $HOSTDOMAIN )
if [[ $? -ne 0 ]]
then
host=$(ip neigh show |awk '/([0-9]{1,3}\.){3}[0-9]{1,3}.+(wlan[10]|rndis0)/ {print $1}' |nmap -p 6666 --open -iL - |grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}' -o )
host=$(ip neigh show |awk '/([0-9]{1,3}\.){3}[0-9]{1,3}.+(wlan[10]|rndis0)/ {print $1}' |nmap -p $SCANPORT --open -iL - |grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}' -o )

echo 'mdns scan failed======'
else
Expand All @@ -37,7 +28,19 @@ sshtunnel()
termux-notification --ongoing -t 'no server in network ' --sound --alert-once --id 10 ;
TUNERROR=1
else
ssh -o "StrictHostKeyChecking=no" -i ~/laptopkey -N -l sanbot "$host" -L:2222:localhost:22 -L:6800:localhost:6800 -L:1935:localhost:1935 -L:8096:localhost:8096 -L:8080:localhost:80 -L:6666:localhost:6666 -L:8081:localhost:8085 -L:4533:localhost:4533 -L:4445:localhost:445 &
ssh -o "StrictHostKeyChecking=no" -i $IDENTITY_KEY -N -l sanbot "$host" -L:$SSHPORT:localhost:22 &
# Load the configuration file and parse it line by line
if [[ -f "service.csv" ]]; then
while IFS=',' read -r service localport remoteport ; do
echo "forwarding for $service the $remoteport to $localport"

ssh -o "StrictHostKeyChecking=no" -i $IDENTITY_KEY -N -l sanbot "$host" -L:$localport:localhost:$remoteport &

done < "./service.csv"
else
echo "Service.csv Configuration file 'config.csv' not found."
exit 1
fi
TUNERROR=0
fi
}
Expand All @@ -53,20 +56,16 @@ cleanup()
}
dircreate()
{
for dir in "$DESTINATION2" "$DESTINATION3" "$DESTINATION4" "$DESTINATION"; do
if [ ! -d "$dir" ]; then
echo "Directory $dir does not exist. Creating..."
ssh -i ~/laptopkey -p 2222 sanbot@localhost mkdir -p "$dir"
if [ $? -eq 0 ]; then
echo "Directory $dir created successfully."
else
echo "Failed to create directory $dir."
fi
else
echo "Directory $dir already exists."
fi
done

if [[ -f "config.csv" ]]; then
while IFS=',' read -r task source destination; do
echo "creating destination dir $destination "
ssh -i $IDENTITY_KEY -p $SSHPORT sanbot@localhost mkdir -p "$destination"
done < "config.csv"
else
echo "Configuration file 'config.csv' not found."
exit 1
fi
}

trap cleanup 1 2 3 6 14 15 ;
Expand Down Expand Up @@ -127,16 +126,22 @@ do
if (( TUNERROR == 0 ))
then

echo "sync started of=> $SOURCE , $SOURCE2 , $SOURCE3,$SOURCE4 " |sed 's/\/sdcard\///g' >~/transferlog
#--info=PROGRESS,FLIST2
rsync -zavP -e "ssh -p 2222 -l sanbot -i ~/laptopkey " $SOURCE sanbot@localhost:$DESTINATION >> ~/transferlog

rsync -zavP -e "ssh -p 2222 -l sanbot -i ~/laptopkey " $SOURCE2 sanbot@localhost:$DESTINATION2 >> ~/transferlog

rsync -zavP --info=PROGRESS,COPY -e "ssh -p 2222 -l sanbot -i ~/laptopkey " $SOURCE3 sanbot@localhost:$DESTINATION3 >> ~/transferlog

rsync -zavP --delete --info=PROGRESS,COPY -e "ssh -p 2222 -l sanbot -i ~/laptopkey " $SOURCE4 sanbot@localhost:$DESTINATION4 >> ~/transferlog
rsync -zavP --delete --info=PROGRESS,COPY -e "ssh -p 2222 -l sanbot -i ~/laptopkey " sanbot@localhost:$SITESOURCE $SITEDEST >> ~/sitetransferlog 2>&1
sources=()
if [[ -f "config.csv" ]]; then
while IFS=',' read -r task source destination; do
echo "running $task "
#echo "sync started of=> $" |sed 's/\/sdcard\///g' >~/transferlog
#appending list of sources to array $sources
sources+=($source)
rsync -zavP -e "ssh -p $SSHPORT -l sanbot -i $IDENTITY_KEY " $source sanbot@localhost:$destination >> ~/transferlog
#copy_files "$source" "$destination"
done < "config.csv"
else
echo "Configuration file 'config.csv' not found."
exit 1
fi
echo "sync started of=> ${sources[@]}" |sed 's/\/sdcard\///g' >~/transferlog
#--info=#PROGRESS,FLIST2

if [[ $? -eq 0 ]]
then
Expand All @@ -148,11 +153,11 @@ do
flag=0
fi

curvol="$( ssh -i ~/laptopkey sanbot@localhost -p 2222 pactl list sinks | awk -F / '/^[[:space:]]Volume/ {print $2}' )"
cat ~/transferlog | termux-notification --id 10 --alert-once --ongoing --button1 '+' --button1-action "ssh -i ~/laptopkey sanbot@localhost -p 2222 pactl set-sink-volume @DEFAULT_SINK@ +5% ; " --button2 '-' --button2-action "ssh -i ~/laptopkey sanbot@localhost -p 2222 pactl set-sink-volume @DEFAULT_SINK@ -5% " --button3 $curvol --button3-action 'echo 0'
curvol="$( ssh -i $IDENTITY_KEY sanbot@localhost -p $SSHPORT pactl list sinks | awk -F / '/^[[:space:]]Volume/ {print $2}' )"
cat ~/transferlog | termux-notification --id 10 --alert-once --ongoing --button1 '+' --button1-action "ssh -i $IDENTITY_KEY sanbot@localhost -p $SSHPORT pactl set-sink-volume @DEFAULT_SINK@ +5% ; " --button2 '-' --button2-action "ssh -i $IDENTITY_KEY sanbot@localhost -p $SSHPORT pactl set-sink-volume @DEFAULT_SINK@ -5% " --button3 $curvol --button3-action 'echo 0'
#'termux-speech-to-text > ~/speechin'

#cat ~/speechin |ssh -p 2222 -i ~/laptopkey sanbot@localhost 'export DISPLAY=:0 && xargs xdotool type'
#cat ~/speechin |ssh -p $SSHPORT -i $IDENTITY_KEY sanbot@localhost 'export DISPLAY=:0 && xargs xdotool type'



Expand Down
12 changes: 12 additions & 0 deletions config.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[CopyTask1]
source="/path/to/source/file1"
destination="/path/to/destination/file1"

[CopyTask2]
source="/path/to/source/file2"
destination="/path/to/destination/file2"

[CopyTask3]
source="/path/to/source/file3"
destination="/path/to/destination/file3"

4 changes: 4 additions & 0 deletions config.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CopyTask1,/path/to/source/file1,/path/to/destination/file1
CopyTask2,/path/to/source/file2,/path/to/destination/file2
CopyTask3,/path/to/source/file3,/path/to/destination/file3

5 changes: 5 additions & 0 deletions main.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Config file
SCANPORT=6666 #mpd service
SSHPORT=2222
IDENTITY_KEY="~/laptopkey"
HOSTDOMAIN="laptop.local"
9 changes: 9 additions & 0 deletions service.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
service1,6800,6800
rtmp,1935,1935
emby,8096,8096
webserver,8080,80
mpd,6666,6666
kodiremote,8081,8085
service3,4533,4533
ssl,4445,445
service4,4533,4533
27 changes: 27 additions & 0 deletions temp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Function to copy files
copy_files() {
local source="$1"
local destination="$2"

# Check if source file exists
if [[ -f "$source" ]]; then
# Copy source to destination
#cp "$source" "$destination"
echo "Copied: $source -> $destination"
else
echo "Source file not found: $source"
fi
}

# Load the configuration file and parse it line by line
if [[ -f "service.csv" ]]; then
while IFS=',' read -r task source destination; do
echo "running $task "
copy_files "$source" "$destination"
done < "./service.csv"
else
echo "Configuration file 'config.csv' not found."
exit 1
fi
41 changes: 41 additions & 0 deletions temp2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Function to copy files
copy_files() {
local source="$1"
local destination="$2"

# Check if source file exists
if [[ -f "$source" ]]; then
# Copy source to destination
cp "$source" "$destination"
echo "Copied: $source -> $destination"
else
echo "Source file not found: $source"
fi
}

# Load the configuration file
if [[ -f "config.conf" ]]; then
. "config.conf"
else
echo "Configuration file 'config.conf' not found."
exit 1
fi

# Loop through sections in the configuration file
for section in $(cat "config.conf" | grep -E "^\[.*\]$"); do
section="${section#[}"
section="${section%]}"

# Read source and destination from the section
source="${section}_source"
destination="${section}_destination"

# Check if both source and destination are defined
if [[ -v "$source" && -v "$destination" ]]; then
copy_files "${!source}" "${!destination}"
else
echo "Missing source or destination in section: $section"
fi
done
42 changes: 42 additions & 0 deletions temp3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Declare an associative array to store source and destination
declare -A file_mapping

# Function to copy files
copy_files() {
local source="$1"
local destination="$2"

# Check if source file exists
if [[ -f "$source" ]]; then
# Copy source to destination
# cp "$source" "$destination"
echo "Copied: $source -> $destination"
else
echo "Source file not found: $source"
fi
}

# Load the configuration file and parse it line by line
if [[ -f "config.csv" ]]; then
while IFS=',' read -r task source destination; do
echo "running $task "
copy_files "$source" "$destination"

# Modify $task to ensure it's a valid array key
# Remove spaces and problematic characters
task=${task//[^a-zA-Z0-9_]/_}

# Append source and destination to the associative array
file_mapping["$task"]=$source:$destination
done < "config.csv"

# Print the associative array for reference
for key in "${!file_mapping[@]}"; do
echo "Task: $key, Source-Destination: ${file_mapping[$key]}"
done
else
echo "Configuration file 'config.csv' not found."
exit 1
fi
26 changes: 26 additions & 0 deletions temp4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Function to copy files
copy_files() {
local source="$1"
local destination="$2"

# Check if source file exists
if [[ -f "$source" ]]; then
# Copy source to destination
#cp "$source" "$destination"
echo "Copied: $source -> $destination"
else
echo "Source file not found: $source"
fi
}

# Load the configuration file and parse it line by line
if [[ -f "service.csv" ]]; then
while IFS=',' read -r task source destination; do
echo "ports for $task is $source and $destination "
done < "./service.csv"
else
echo "Configuration file 'config.csv' not found."
exit 1
fi

0 comments on commit d331ca6

Please sign in to comment.