Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHCP #150

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
===============
JJ Changes
===============

- Scripts to deploy changes in several Cameras ( with ftp and telnet already active)
Req. curl + expect

- Wiki: desired changes and ideas

....
....



===============
Yi-hack project
===============
Expand Down Expand Up @@ -75,7 +89,7 @@ You will need to set a static IP adresse to the camera. To check for the availab

To configure the wifi network to use, edit the file **test/wpa_supplicant.conf**.

To configure your IP address, open the file **test/yi-hack.cfg** and set the values.
To configure your IP address, open the file **test/yi-hack.cfg** and set the values OR use **dhcp** option.

Start the camera
----------------
Expand Down
23 changes: 23 additions & 0 deletions sd/reboot.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/expect
set timeout 1
set ip [lindex $argv 0]
set port [lindex $argv 1]
set username [lindex $argv 2]
set password [lindex $argv 3]
spawn telnet $ip $port
expect "'^]'." sleep .1;
send "\r";
sleep .1;
expect -nocase "login:"
send "$username\r"
expect -nocase "password: "
send "$password\r"
# Match the prompt (contains a $)
expect -re {\#}
# reboot
send "reboot\r"
# Wait for the prompt
expect -re {\#}
exit


19 changes: 19 additions & 0 deletions sd/reboot_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

#set -x

get_config() {
key=$1
grep "^$1=" ./test/yi-hack.cfg | cut -d'=' -f2
}

pass=$(get_config ROOT_PASSWORD)
IPs="192.168.2.20 192.168.2.21 192.168.2.22 192.168.2.23 192.168.2.24"


for srv in $(echo $IPs)
do
echo "Restarting ... $srv"
./reboot.expect $srv 23 root $pass

done
61 changes: 36 additions & 25 deletions sd/test/equip_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ log() {

get_config() {
key=$1
grep $1 /home/hd1/test/yi-hack.cfg | cut -d"=" -f2
grep "^$1=" /home/hd1/test/yi-hack.cfg | cut -d"=" -f2
}

boot_voice() {
voice_file=$1
if [ "$(get_config BOOT_VOICE)" = "yes" ]; then
/home/rmm "$voice_file" 1
fi
}


### first we assume that this script is started from /home/init.sh and will replace it from the below lines (which are not commented in init.sh :
Expand Down Expand Up @@ -114,8 +120,8 @@ cd /home/3518
himm 0x20050074 0x06802424

### Let ppl hear that we start
/home/rmm "/home/hd1/voice/welcome.g726" 1
/home/rmm "/home/hd1/voice/wait.g726" 1
boot_voice "/home/hd1/test/voice/welcome.g726" 1
boot_voice "/home/hd1/test/voice/wait.g726" 1

### start blinking blue led for configuration in progress
#/home/led_ctl -boff -yon &
Expand Down Expand Up @@ -261,7 +267,7 @@ log "Debug mode = $(get_config DEBUG)"
# first, configure wifi

### Let ppl hear that we start connect wifi
/home/rmm "/home/hd1/voice/connectting.g726" 1
boot_voice "/home/hd1/test/voice/connectting.g726" 1

log "Check for wifi configuration file...*"
log $(find /home -name "wpa_supplicant.conf")
Expand All @@ -271,20 +277,27 @@ res=$(/home/wpa_supplicant -B -i ra0 -c /home/wpa_supplicant.conf )
log "Status for wifi configuration=$? (0 is ok)"
log "Wifi configuration answer: $res"

log "Do network configuration 1/2 (ip and gateway)"
#ifconfig ra0 192.168.1.121 netmask 255.255.255.0
#route add default gw 192.168.1.254
ifconfig ra0 $(get_config IP) netmask $(get_config NETMASK)
route add default gw $(get_config GATEWAY)
log "Done"

log "Configuration is :"
ifconfig | sed "s/^/ /" >> ${LOG_FILE}
if [[ $(get_config DHCP) == "yes" ]] ; then
log "Network config >> DHCP"
my_gateway=$(udhcpc --interface=ra0 | grep "Adding router" | awk '{print $3}' | tr -d '\n')
log "Default router is $my_gateway"
else
log "Do network configuration 1/2 (ip and gateway)"
#ifconfig ra0 192.168.1.121 netmask 255.255.255.0
#route add default gw 192.168.1.254
ifconfig ra0 $(get_config IP) netmask $(get_config NETMASK)
route add default gw $(get_config GATEWAY)
my_gateway=$(get_config GATEWAY)
log "Done"
###
log "Configuration is :"
ifconfig | sed "s/^/ /" >> ${LOG_FILE}
### configure DNS (google one)
log "Do network configuration 2/2 (DNS)"
echo "nameserver $(get_config NAMESERVER)" > /etc/resolv.conf
log "Done"
fi

### configure DNS (google one)
log "Do network configuration 2/2 (DNS)"
echo "nameserver $(get_config NAMESERVER)" > /etc/resolv.conf
log "Done"

### configure time on a NTP server
log "Get time from a NTP server..."
Expand All @@ -298,9 +311,9 @@ log "New datetime is $(date)"


### Check if reach gateway and notify
ping -c1 -W2 $(get_config GATEWAY) > /dev/null
ping -c1 -W2 $my_gateway > /dev/null
if [ 0 -eq $? ]; then
/home/rmm "/home/hd1/voice/wifi_connected.g726" 1
boot_voice "/home/hd1/test/voice/wifi_connected.g726" 1
fi

### set the root password
Expand Down Expand Up @@ -397,10 +410,10 @@ fi
### Final led color

### Check if reach gateway and notify
ping -c1 -W2 $(get_config GATEWAY) > /dev/null
ping -c1 -W2 $my_gateway > /dev/null
if [ 0 -eq $? ]; then
led $(get_config LED_WHEN_READY)
/home/rmm "/home/hd1/voice/success.g726" 1
boot_voice "/home/hd1/test/voice/success.g726" 1
else
led -boff -yfast
fi
Expand All @@ -427,6 +440,8 @@ ps | grep rtspsvr | grep -v grep >> ${LOG_FILE}

sleep 5

### Start check_motion.sh script
/home/hd1/test/check_motion.sh &

### List the processes after startup
log "Processes after startup :"
Expand All @@ -439,7 +454,3 @@ df -h >> ${LOG_FILE}
### to make sure log are written...

sync




8 changes: 8 additions & 0 deletions sd/test/yi-hack.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ ROOT_PASSWORD=1234qwer

### Network configuration
# Don't forget to also fill the file wpa_supplicant.conf for the wifi configuration
# If DHCP = no, USE IP/NETMASK/GATEWAY/NAMESERVER
DHCP=yes
IP=192.168.1.121
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
NAMESERVER=192.168.1.254


### Led color after full boot
# The sequence will be :
# - orange : startup
Expand Down Expand Up @@ -35,6 +38,11 @@ TIMEZONE=GMT0BST,M3.5.0/1,M10.5.0
#If you want to change your ntp server you can see a list here http://www.pool.ntp.org/zone/@
NTP_SERVER=0.uk.pool.ntp.org

### Boot voice
# If you want to disable the voice feedback during boot, change BOOT_VOICE to 'no'
# Values : yes|no
BOOT_VOICE=yes

### Debug
# Debug mode, keep it to 'no' unless you known what you do
# Values : yes|no
Expand Down
31 changes: 31 additions & 0 deletions sd/upload_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

#set -x

get_config() {
key=$1
grep "^$1=" ./test/yi-hack.cfg | cut -d'=' -f2
}

pass=$(get_config ROOT_PASSWORD)


for srv in $(echo "192.168.2.20 192.168.2.21 192.168.2.22 192.168.2.23 192.168.2.24")
do
echo "=================================="
echo "Uploading test to ... $srv"
echo "=================================="

for file in $(find test -type f | grep -v "\.DS_Store")
do
#echo -ne "Deleting file $file " && curl ftp://$srv -X 'DELE /home/hd1/${file}' && echo -ne "\t\t\tOK\n"
echo -ne "Uploading file $file " && ( curl -s -S --ftp-create-dirs -T $file ftp://${srv}/home/hd1/${file} && echo -ne "\t\t\tOK\n" ) || echo -ne "\t\t\tERROR!!!\n"
done
#curl ftp://$srv -X 'DELE /home/hd1/test/web' -v
#find test -type f -exec curl -s -S --ftp-create-dirs -T {} ftp://${srv}/home/hd1/{} \;

# Restart
echo ""
echo "Restarting ... $srv"
./reboot.expect $srv 23 root $pass >/dev/null
done