From c269f5b7315d3275e615f8728dcb90dff09bbfe6 Mon Sep 17 00:00:00 2001 From: ueno Date: Wed, 7 Aug 2019 16:53:36 +0900 Subject: [PATCH] Squashed commit of the following: commit 7496e18b1b1f5f6a863a35c1e0b09664660a7f98 Author: ueno Date: Wed Aug 7 16:46:23 2019 +0900 remove invoice.txt commit 6021bfa25fcad3b093c80bea85648cb685ebbbd8 Author: ueno Date: Fri Aug 2 19:14:14 2019 +0900 fix commit 19e8ada8ac830a61e7c3eed7c2593dda9c09ea6d Author: ueno Date: Fri Aug 2 18:50:13 2019 +0900 sudo commit ec98266d4b20561cda35363c19832722cdec29e7 Author: ueno Date: Fri Aug 2 18:40:18 2019 +0900 read button after LED on commit e6442ba4573741ac14e030cc37c590d1c0d34e52 Author: ueno Date: Fri Aug 2 18:34:54 2019 +0900 ProgUpd.new commit 9edc366019b66d1f0fc4532b4621b65c3e2ed526 Author: ueno Date: Fri Aug 2 18:27:55 2019 +0900 fix commit 96aaa6a88b9b9cd591ebb75e49e264b29315eb9e Author: ueno Date: Fri Aug 2 18:23:07 2019 +0900 copy if not exist commit 37e07a37fda2ed59eccf5bbd403a9273e77f2c19 Author: ueno Date: Fri Aug 2 18:13:04 2019 +0900 remove bak commit 71564eea6a62386536324b153fb9e45b57722c28 Author: ueno Date: Fri Aug 2 18:11:42 2019 +0900 sync commit 75d6698cc2f0e5641cbb9bb4b5472513cdf33bfc Author: ueno Date: Fri Aug 2 18:10:43 2019 +0900 LED commit 4daf489bba2e6c2fcc5a4d8a8a28e9780239fb9f Author: ueno Date: Fri Aug 2 18:04:49 2019 +0900 move swupdate commit da4be90249b2a821908dd1d0d653c64c73e91f4e Author: ueno Date: Fri Aug 2 17:17:06 2019 +0900 log func commit b028bd54882900d9cfb00b317421a05437951434 Author: ueno Date: Fri Aug 2 17:13:31 2019 +0900 fix VAR name commit 3b7ac2804158917f3ae705a3edef971f1034c9d5 Author: ueno Date: Fri Aug 2 16:23:46 2019 +0900 update software commit 7100454d5581d0e153f84ee740c218198bdf6ced Author: ueno Date: Thu Aug 1 19:34:19 2019 +0900 add COPYNODEDIR commit db0aee110120c3ce7611e6a59a8f69b19c607d4d Author: ueno Date: Thu Aug 1 10:01:42 2019 +0900 rename commit 52fd54fc42b47488c4d535e18640de3a817b5576 Author: ueno Date: Wed Jul 31 22:55:50 2019 +0900 fix path commit 4a717c48b2706d3e55add635dcf830765a9b582a Author: ueno Date: Wed Jul 31 21:36:37 2019 +0900 fix path commit a524866cbc87b7b751be3f319a05a8c1835c5a90 Author: ueno Date: Wed Jul 31 19:27:37 2019 +0900 software update service --- rpi_config.ini | 9 ++++- rpi_config.sh | 8 +++- rpi_prepare.service | 2 +- rpi_start_pre.sh => rpi_prepare.sh | 4 +- rpi_ptarm.service | 2 +- rpi_start.sh => rpi_ptarm.sh | 3 +- rpi_swupdate.service | 14 +++++++ rpi_swupdate.sh | 62 ++++++++++++++++++++++++++++++ rpi_watchbtn.service | 4 +- watch_btn.sh => rpi_watchbtn.sh | 0 10 files changed, 98 insertions(+), 10 deletions(-) rename rpi_start_pre.sh => rpi_prepare.sh (94%) rename rpi_start.sh => rpi_ptarm.sh (96%) create mode 100644 rpi_swupdate.service create mode 100755 rpi_swupdate.sh rename watch_btn.sh => rpi_watchbtn.sh (100%) diff --git a/rpi_config.ini b/rpi_config.ini index 0e8f231..252e908 100644 --- a/rpi_config.ini +++ b/rpi_config.ini @@ -1,13 +1,18 @@ [PATH] -PROGDIR=/home/pi/Prog +HOMEDIR=/home/pi +PROGDIR=%(HOMEDIR)s/Prog +COPYNODEDIR=%(HOMEDIR)s/NodeData + PTARMDIR=%(PROGDIR)s/ptarmigan/install NODEDIR=%(PROGDIR)s/ptarmigan/install/node EPAPERDIR=%(PROGDIR)s/rpi_epaper UARTDIR=%(PROGDIR)s/rpi_uart WEBDIR=%(PROGDIR)s/rpi_web -MAINNET=/boot/RPI_MAINNET + STATIC = %(PROGDIR)s/rpi_web/static +MAINNET=/boot/RPI_MAINNET + [DISP] NOEPAPER=/boot/RPI_NOEPAPER LED1=3 diff --git a/rpi_config.sh b/rpi_config.sh index 280a0dd..0adfa31 100644 --- a/rpi_config.sh +++ b/rpi_config.sh @@ -1,5 +1,10 @@ #!/bin/bash -export PROGDIR=/home/pi/Prog +export HOMEDIR=/home/pi +export PROGDIR=${HOMEDIR}/Prog +export PROGORGDIR=${HOMEDIR}/ProgOrg +export UPDATEDIR=${HOMEDIR}/ProgUpd +export COPYNODEDIR=${HOMEDIR}/NodeData + export PTARMDIR=${PROGDIR}/ptarmigan/install export NODEDIR=${PTARMDIR}/node export EPAPERDIR=${PROGDIR}/rpi_epaper @@ -17,6 +22,7 @@ export APMODE=/boot/RPI_APMODE export CLIENT=/boot/RPI_CLIENT export USEWEB=/boot/RPI_USEWEB export MAINNET=/boot/RPI_MAINNET +export SWUPDATE=/boot/RPI_SWUPDATE export LED1=3 export LED2=2 diff --git a/rpi_prepare.service b/rpi_prepare.service index 16edc77..fdc3b73 100644 --- a/rpi_prepare.service +++ b/rpi_prepare.service @@ -4,7 +4,7 @@ After=rpi_watchbtn.service ConditionPathExists=/home/pi/Prog/bin [Service] -ExecStart=/home/pi/Prog/bin/rpi_start_pre.sh +ExecStart=/home/pi/Prog/bin/rpi_prepare.sh Type=oneshot RemainAfterExit=yes User=pi diff --git a/rpi_start_pre.sh b/rpi_prepare.sh similarity index 94% rename from rpi_start_pre.sh rename to rpi_prepare.sh index 61252c4..e0b8f29 100755 --- a/rpi_start_pre.sh +++ b/rpi_prepare.sh @@ -124,8 +124,8 @@ echo 0 > ${PROGDIR}/start_count.txt # copy ptarmigan script(update) cp ${PROGDIR}/bin/ptarmd_script/* ${PTARMDIR}/script/ -cp ${PROGDIR}/bin/ptarmd_script/* ${PTARMDIR}/testnet/script/ -cp ${PROGDIR}/bin/ptarmd_script/* ${PTARMDIR}/mainnet/script/ +cp ${PROGDIR}/bin/ptarmd_script/* ${COPYNODEDIR}/testnet/script/ +cp ${PROGDIR}/bin/ptarmd_script/* ${COPYNODEDIR}/mainnet/script/ gpio write ${LED1} ${LED_OFF} gpio write ${LED2} ${LED_OFF} diff --git a/rpi_ptarm.service b/rpi_ptarm.service index 5c0fd1a..f380b6a 100644 --- a/rpi_ptarm.service +++ b/rpi_ptarm.service @@ -4,7 +4,7 @@ After=rpi_prepare.service ConditionPathExists=/home/pi/Prog/bin [Service] -ExecStart=/home/pi/Prog/bin/rpi_start.sh +ExecStart=/home/pi/Prog/bin/rpi_ptarm.sh ExecStop=/home/pi/Prog/ptarmigan/install/ptarmcli -q Type=simple Restart=on-failure diff --git a/rpi_start.sh b/rpi_ptarm.sh similarity index 96% rename from rpi_start.sh rename to rpi_ptarm.sh index 1f18182..b2841d6 100755 --- a/rpi_start.sh +++ b/rpi_ptarm.sh @@ -59,7 +59,7 @@ else CHAIN=testnet fi rm -f ${NODEDIR} -ln -s ${PTARMDIR}/${CHAIN} ${NODEDIR} +ln -s ${COPYNODEDIR}/${CHAIN} ${NODEDIR} rm -f ${NODEDIR}/logs/bitcoinj_startup.log stage_log_add "chain=${CHAIN}" @@ -122,6 +122,7 @@ else exit 0 fi +sudo rm -f ${PROGDIR}/invoice.png ${PROGDIR}/invoice.txt ${UARTPY}& echo "done: uart" diff --git a/rpi_swupdate.service b/rpi_swupdate.service new file mode 100644 index 0000000..b7d2b42 --- /dev/null +++ b/rpi_swupdate.service @@ -0,0 +1,14 @@ +[Unit] +Description = Nayuta RPi Software Update +After=network.target +ConditionPathExists=/home/pi/Prog/bin + +[Service] +ExecStart=/home/pi/Prog/bin/rpi_swupdate.sh +Type=oneshot +User=pi +Group=pi + +[Install] +WantedBy=multi-user.target + diff --git a/rpi_swupdate.sh b/rpi_swupdate.sh new file mode 100755 index 0000000..eb81ea1 --- /dev/null +++ b/rpi_swupdate.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +set -eu + +source /home/pi/Prog/bin/rpi_config.sh + +blink() { + for i in `seq 1 $1`; do + gpio write ${LED1} ${LED_ON} + gpio write ${LED2} ${LED_ON} + sleep $2 + gpio write ${LED1} ${LED_OFF} + gpio write ${LED2} ${LED_OFF} + sleep $2 + done + gpio write ${LED1} ${LED_ON} + gpio write ${LED2} ${LED_ON} +} + +if [ -f ${NOTSTART} ]; then + exit 0 +fi + +gpio mode ${LED1} out +gpio mode ${LED2} out +gpio mode ${BTN1} in +gpio mode ${BTN2} in + +gpio write ${LED1} ${LED_ON} +gpio write ${LED2} ${LED_ON} + +sleep 3 + +btn1_on=`gpio read ${BTN1}` +btn2_on=`gpio read ${BTN2}` + +if [ -f ${SWUPDATE} ] && [ ${btn1_on} -eq 0 ] && [ ${btn2_on} -eq 0 ]; then + echo "begin SW update" + ${EPAPERPY} "" "SW update!" & + blink 15 0.1 + + # /home/pi/ProgUpd.new + sudo rm -rf ${UPDATEDIR}.new + sudo tar jxf ${SWUPDATE} -C ${HOMEDIR} + + for dname in bin rpi_epaper rpi_uart rpi_web ptarmigan; do + if [ ! -f ${UPDATEDIR}.new/${dname} ]; then + echo use previous ${dname} + sudo cp -ra ${PROGDIR}/${dname} ${UPDATEDIR}.new/ + fi + done + + sudo rm -rf ${UPDATEDIR} + sudo mv ${UPDATEDIR}.new ${UPDATEDIR} + rm ${PROGDIR} + ln -s ${UPDATEDIR} ${PROGDIR} + sudo rm ${SWUPDATE} + sync + echo "end SW update" +fi + +blink 3 0.3 diff --git a/rpi_watchbtn.service b/rpi_watchbtn.service index 0be0df7..00cb014 100644 --- a/rpi_watchbtn.service +++ b/rpi_watchbtn.service @@ -1,10 +1,10 @@ [Unit] Description = Watch Button RPi service -After=network.target +After=rpi_swupdate.service ConditionPathExists=/home/pi/Prog/bin [Service] -ExecStart=/home/pi/Prog/bin/watch_btn.sh +ExecStart=/home/pi/Prog/bin/rpi_watchbtn.sh Type=simple User=pi Group=pi diff --git a/watch_btn.sh b/rpi_watchbtn.sh similarity index 100% rename from watch_btn.sh rename to rpi_watchbtn.sh