-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchange_sprite.sh
More file actions
executable file
·91 lines (84 loc) · 2.89 KB
/
change_sprite.sh
File metadata and controls
executable file
·91 lines (84 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
#
# A script for chnaging the sprite on
# a unifi doorbell. Note you must pass the
# sprite name and IP of the doorbell
################################################################################
# Help #
################################################################################
Help()
{
# Display Help
echo "Changes the sprite (animated gif) on a UNIFI Doorbell"
echo ""
echo "Nicholas Saraniti 2023 (https://nicholassaraniti.com/)"
echo "https://github.com/tracerrx/unifi-doorbell"
echo ""
echo "Syntax: change_sprite [-h|i|s]"
echo "options:"
echo " h Print this Help."
echo " i IP address of UNIFI Doorbell (REQUIRED)."
echo " s Name of Sprite to upload with path i.e. ./easter-sprite.png (REQUIRED)."
echo " p ssh password of doorbell (REQUIRED)."
echo
}
################################################################################
################################################################################
# Main program #
################################################################################
################################################################################
while getopts s:i:p:h flag
do
case "${flag}" in
s) SPRITEPATH=${OPTARG};;
i) IP=${OPTARG};;
p) PASSWORD=${OPTARG};;
h) Help
exit;;
esac
done
############Check That SSHPASS is installed###############
if ! command -v sshpass &> /dev/null
then
echo "sshpass could not be found and must be installed."
exit 1
fi
############Check Doorbell IP is Reachable###############
if ping -t 3 -c 1 $IP &> /dev/null
then
echo "Able to Ping Doorbell at $IP"
else
echo "error: Unable to ping doorbell at $IP."
exit 1;
fi
############Check That Sprite file Exists Locally###############
if test -f $SPRITEPATH;
then
echo "File $SPRITEPATH exists."
SPRITE="$(basename -- $SPRITEPATH)"
echo "Sprite Name is $SPRITE"
else
echo "error: Unable to read file $SPRITEPATH."
exit 2;
fi
############SCP the Sprite to the doorbell###############
sshpass -p $PASSWORD scp -O $SPRITEPATH ubnt@$IP:/etc/persistent/$SPRITE
if [ $? -eq 0 ];
then
echo "Sprite copied to doorbell"
else
echo "error: Could not copy Sprite to doorbell"
exit 3;
fi
############Run Mount command Remotely via SSH###############
echo "Attempting to unmount in case doorbell has not rebooted since last update"
sshpass -p $PASSWORD ssh ubnt@$IP "umount /usr/etc/gui/screen_240x240/Welcome_Anim_60.png"
echo "Mounting New Sprite"
sshpass -p $PASSWORD ssh ubnt@$IP "mount -o bind /etc/persistent/$SPRITE /usr/etc/gui/screen_240x240/Welcome_Anim_60.png"
if [ $? -eq 0 ];
then
echo "Sprite mounted on doorbell, alldone!"
else
echo "error: Could not mount Sprite on doorbell"
exit 4;
fi