|
| 1 | +#!/sbin/openrc-run |
| 2 | +# Copyright (c) 2018 muXxer |
| 3 | + |
| 4 | +## Functions |
| 5 | +_bold=$(tput bold) |
| 6 | +_reset=$(tput sgr0) |
| 7 | + |
| 8 | +_red=$(tput setaf 1) |
| 9 | +_green=$(tput setaf 2) |
| 10 | +_yellow=$(tput setaf 3) |
| 11 | + |
| 12 | +function print_ok { printf "${_bold}${_green}%s${_reset}\n" "$@"; } |
| 13 | +function print_err { printf "${_bold}${_red}%s${_reset}\n" "$@"; } |
| 14 | +function print_warn { printf "${_bold}${_yellow}%s${_reset}\n" "$@"; } |
| 15 | + |
| 16 | +depend() |
| 17 | +{ |
| 18 | + after networking sshd |
| 19 | +} |
| 20 | + |
| 21 | +start() |
| 22 | +{ |
| 23 | + ebegin "Downloading IOTA-Ledger App..." |
| 24 | + |
| 25 | + echo "" |
| 26 | + print_warn "Please read our documentation carefully at https://github.com/IOTA-Ledger/blue-app-iota/" |
| 27 | + |
| 28 | + echo "" |
| 29 | + print_ok "Downloading latest compiled binary from https://github.com/IOTA-Ledger/blue-app-iota/releases..." |
| 30 | + echo "" |
| 31 | + |
| 32 | + mkdir -p /root/iota-ledger/download/ |
| 33 | + cd /root/iota-ledger/download/ |
| 34 | + latest_file=`curl -s https://api.github.com/repos/IOTA-Ledger/blue-app-iota/releases | grep browser_download_url | grep blue-app | grep .zip | head -n 1 | cut -d '"' -f 4` |
| 35 | + retVal=$? |
| 36 | + if [ $retVal -ne 0 ]; then |
| 37 | + echo "" |
| 38 | + print_err "No compiled binary found in the GitHub repository! Do you have a working internet connection? Rebooting..." |
| 39 | + rm -R /root/iota-ledger/download/ |
| 40 | + sleep 10 |
| 41 | + reboot |
| 42 | + eend $retVal |
| 43 | + fi |
| 44 | + |
| 45 | + curl -L $latest_file -O |
| 46 | + retVal=$? |
| 47 | + if [ $retVal -ne 0 ]; then |
| 48 | + echo "" |
| 49 | + print_err "Downloading the latest compiled binary from GitHub failed! Do you have a working internet connection? Rebooting..." |
| 50 | + rm -R /root/iota-ledger/download/ |
| 51 | + sleep 10 |
| 52 | + reboot |
| 53 | + eend $retVal |
| 54 | + fi |
| 55 | + |
| 56 | + file_name=`echo $latest_file | rev | cut -d '/' -f 1 | rev` |
| 57 | + echo "" |
| 58 | + print_ok "Downloaded:" |
| 59 | + print_ok ' File name = "'${file_name}'"' |
| 60 | + |
| 61 | + echo "" |
| 62 | + #echo "Unzipping the file and comparing the checksum..." |
| 63 | + print_ok "Unzipping the file and verifying the digital signature..." |
| 64 | + echo "" |
| 65 | + unzip ${file_name} |
| 66 | + echo "" |
| 67 | + #sha256sum -c app.hex.sha256 |
| 68 | + gpg --verify app.hex.asc |
| 69 | + retVal=$? |
| 70 | + if [ $retVal -ne 0 ]; then |
| 71 | + echo "" |
| 72 | + #echo "Checksum missmatch! Something went wrong! Please try again! Rebooting..." |
| 73 | + print_err "Digital signature not valid! Something went wrong! Please try again! Rebooting..." |
| 74 | + rm -R /root/iota-ledger/download/ |
| 75 | + sleep 10 |
| 76 | + reboot |
| 77 | + eend $retVal |
| 78 | + fi |
| 79 | + echo "" |
| 80 | + print_ok "File unzipped and digital signature valid!" |
| 81 | + |
| 82 | + echo "" |
| 83 | + print_warn "Plugin your Ledger Blue now and forward it in VirtualBox! You have 5 minutes to do this." |
| 84 | + print_warn "Searching for Ledger Blue..." |
| 85 | + echo "" |
| 86 | + |
| 87 | + time_ms=0 |
| 88 | + while [ $time_ms -le 300000 ] |
| 89 | + do |
| 90 | + if [ -e /dev/hidraw1 ]; then |
| 91 | + break |
| 92 | + fi |
| 93 | + |
| 94 | + usleep 500000 |
| 95 | + time_ms=$(( $time_ms + 500 )) |
| 96 | + done |
| 97 | + |
| 98 | + cd /root/iota-ledger/ |
| 99 | + python3 download_app_blue.py |
| 100 | + retVal=$? |
| 101 | + rm -R /root/iota-ledger/download/ |
| 102 | + if [ $retVal -ne 0 ]; then |
| 103 | + echo "" |
| 104 | + if [ $retVal -eq 2 ]; then |
| 105 | + print_err "Ledger Blue Firmware is too old! Please update your Ledger Blue Firmware and try again! Shutting down VM..." |
| 106 | + sleep 5 |
| 107 | + poweroff |
| 108 | + else |
| 109 | + print_err "Something went wrong! Please try again! Rebooting..." |
| 110 | + sleep 5 |
| 111 | + reboot |
| 112 | + fi |
| 113 | + else |
| 114 | + echo "" |
| 115 | + print_ok "IOTA App installed successfully! Shutting down VM..." |
| 116 | + sleep 3 |
| 117 | + poweroff |
| 118 | + fi |
| 119 | + eend 0 |
| 120 | +} |
| 121 | + |
| 122 | +stop() |
| 123 | +{ |
| 124 | + ebegin "" |
| 125 | + eend 0 |
| 126 | +} |
| 127 | + |
0 commit comments