Skip to content

Commit

Permalink
added dependency check
Browse files Browse the repository at this point in the history
  • Loading branch information
sancoderhost committed Sep 25, 2023
1 parent 38308f0 commit c77b8a9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
48 changes: 40 additions & 8 deletions check7.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
#!/bin/bash


# Define an array of dependencies
dependencies=("termux-api" "iptools" "openssh")

# Function to check if a dependency is installed
is_dependency_installed() {
local dependency_name="$1"
command -v "$dependency_name" &>/dev/null
}

# Iterate through the array and install missing dependencies
for dependency in "${dependencies[@]}"; do
if ! is_dependency_installed "$dependency"; then
echo "Installing $dependency..."
apt install -y "$dependency"
if [ $? -eq 0 ]; then
echo "$dependency is now installed."
else
echo "Failed to install $dependency. Exiting."
exit 1
fi
else
echo "$dependency is already installed."
fi
done

# Main part of your script goes here
echo "All dependencies are satisfied. Running the main part of the script..."
# Your main script logic here

# End of script

source ./main.conf

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

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

}
Expand All @@ -28,13 +60,13 @@ sshtunnel()
termux-notification --ongoing -t 'no server in network ' --sound --alert-once --id 10 ;
TUNERROR=1
else
ssh -o "StrictHostKeyChecking=no" -i $IDENTITY_KEY -N -l sanbot "$host" -L:$SSHPORT:localhost:22 &
ssh -o "StrictHostKeyChecking=no" -i $IDENTITY_KEY -N -l $USERNAME "$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 &
ssh -o "StrictHostKeyChecking=no" -i $IDENTITY_KEY -N -l $USERNAME "$host" -L:$localport:localhost:$remoteport &

done < "./service.csv"
else
Expand All @@ -60,7 +92,7 @@ dircreate()
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"
ssh -i $IDENTITY_KEY -p $SSHPORT $USERNAME@localhost mkdir -p "$destination"
done < "config.csv"
else
echo "Configuration file 'config.csv' not found."
Expand Down Expand Up @@ -133,7 +165,7 @@ do
echo "running $task "
#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
rsync -zavP -e "ssh -p $SSHPORT -l $USERNAME -i $IDENTITY_KEY " $source $USERNAME@localhost:$destination >> ~/transferlog
done < "config.csv"
else
echo "Configuration file 'config.csv' not found."
Expand All @@ -152,8 +184,8 @@ do
flag=0
fi

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'
curvol="$( ssh -i $IDENTITY_KEY $USERNAME@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 $USERNAME@localhost -p $SSHPORT pactl set-sink-volume @DEFAULT_SINK@ +5% ; " --button2 '-' --button2-action "ssh -i $IDENTITY_KEY $USERNAME@localhost -p $SSHPORT pactl set-sink-volume @DEFAULT_SINK@ -5% " --button3 $curvol --button3-action 'echo 0'



Expand Down
1 change: 1 addition & 0 deletions main.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#Config file
USERNAME='sanbot'
SCANPORT=6666 #mpd service
SSHPORT=2222
IDENTITY_KEY="~/laptopkey"
Expand Down

0 comments on commit c77b8a9

Please sign in to comment.