forked from muXxer/blue-app-iota-loader-alpine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiota_loader
executable file
·127 lines (110 loc) · 3.03 KB
/
iota_loader
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/sbin/openrc-run
# Copyright (c) 2018 muXxer
## Functions
_bold=$(tput bold)
_reset=$(tput sgr0)
_red=$(tput setaf 1)
_green=$(tput setaf 2)
_yellow=$(tput setaf 3)
function print_ok { printf "${_bold}${_green}%s${_reset}\n" "$@"; }
function print_err { printf "${_bold}${_red}%s${_reset}\n" "$@"; }
function print_warn { printf "${_bold}${_yellow}%s${_reset}\n" "$@"; }
depend()
{
after networking sshd
}
start()
{
ebegin "Downloading IOTA-Ledger App..."
echo ""
print_warn "Please read our documentation carefully at https://github.com/IOTA-Ledger/blue-app-iota/"
echo ""
print_ok "Downloading latest compiled binary from https://github.com/IOTA-Ledger/blue-app-iota/releases..."
echo ""
mkdir -p /root/iota-ledger/download/
cd /root/iota-ledger/download/
latest_file=`curl -s https://api.github.com/repos/IOTA-Ledger/blue-app-iota/releases | grep browser_download_url | grep nanos-app | grep .zip | head -n 1 | cut -d '"' -f 4`
retVal=$?
if [ $retVal -ne 0 ]; then
echo ""
print_err "No compiled binary found in the GitHub repository! Do you have a working internet connection? Rebooting..."
rm -R /root/iota-ledger/download/
sleep 10
reboot
eend $retVal
fi
curl -L $latest_file -O
retVal=$?
if [ $retVal -ne 0 ]; then
echo ""
print_err "Downloading the latest compiled binary from GitHub failed! Do you have a working internet connection? Rebooting..."
rm -R /root/iota-ledger/download/
sleep 10
reboot
eend $retVal
fi
file_name=`echo $latest_file | rev | cut -d '/' -f 1 | rev`
echo ""
print_ok "Downloaded:"
print_ok ' File name = "'${file_name}'"'
echo ""
#echo "Unzipping the file and comparing the checksum..."
print_ok "Unzipping the file and verifying the digital signature..."
echo ""
unzip ${file_name}
echo ""
#sha256sum -c app.hex.sha256
gpg --verify app.hex.asc
retVal=$?
if [ $retVal -ne 0 ]; then
echo ""
#echo "Checksum missmatch! Something went wrong! Please try again! Rebooting..."
print_err "Digital signature not valid! Something went wrong! Please try again! Rebooting..."
rm -R /root/iota-ledger/download/
sleep 10
reboot
eend $retVal
fi
echo ""
print_ok "File unzipped and digital signature valid!"
echo ""
print_warn "Plugin your Ledger Nano S now and forward it in VirtualBox! You have 5 minutes to do this."
print_warn "Searching for Ledger Nano S..."
echo ""
time_ms=0
while [ $time_ms -le 300000 ]
do
if [ -e /dev/hidraw1 ]; then
break
fi
usleep 500000
time_ms=$(( $time_ms + 500 ))
done
cd /root/iota-ledger/
python3 download_app.py
retVal=$?
rm -R /root/iota-ledger/download/
if [ $retVal -ne 0 ]; then
echo ""
if [ $retVal -eq 2 ]; then
print_err "Ledger Nano S Firmware is too old! Please update your Ledger Nano S Firmware and try again! Shutting down VM..."
sleep 5
poweroff
else
print_err "Something went wrong! Please try again! Rebooting..."
sleep 5
reboot
fi
else
echo ""
print_ok "IOTA App installed successfully! Shutting down VM..."
sleep 3
poweroff
fi
eend 0
}
stop()
{
ebegin ""
eend 0
}