slitaz-arm annotate rpi/tazberry @ rev 100
Start Rpi GPIO + leds CGI plugin and improve tazberry
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Apr 13 05:24:04 2014 +0200 (2014-04-13) |
parents | ba52d096f50f |
children | b5629d67388b |
rev | line source |
---|---|
pankso@44 | 1 #!/bin/sh |
pankso@44 | 2 # |
pankso@44 | 3 # TazBerry - SliTaz Raspberry Pi Config Tool |
pankso@44 | 4 # |
pankso@44 | 5 # Copyright (C) 2014 SliTaz ARM - BSD License |
pankso@44 | 6 # Author: Christophe Lincoln <pankso@slitaz.org> |
pankso@44 | 7 # |
pankso@44 | 8 . /lib/libtaz.sh |
pankso@44 | 9 |
pankso@44 | 10 title="{ TazBerry }" |
pankso@44 | 11 config="/boot/config.txt" |
pankso@44 | 12 tmpdir="/tmp/tazberry" |
pankso@44 | 13 tmp="$tmpdir/$$" |
pankso@44 | 14 height="20" |
pankso@44 | 15 width="72" |
pankso@44 | 16 |
pankso@44 | 17 # Use a tmp directory |
pankso@44 | 18 mkdir -p ${tmpdir} |
pankso@44 | 19 |
pankso@44 | 20 # Small built-in help |
pankso@44 | 21 help() { |
pankso@44 | 22 cat << EOT |
pankso@44 | 23 |
pankso@44 | 24 $(boldify "$(gettext 'Usage:')") $(basename $0) [command|rpi_function] |
pankso@44 | 25 |
pankso@44 | 26 $(boldify "$(gettext 'Commands:')") |
pankso@44 | 27 oclock $(gettext 'Display overclocking information') |
pankso@44 | 28 ls-functions $(gettext 'List TazBerry functions') |
pankso@44 | 29 testsuite $(gettext 'Run TazBerry testsuite') |
pankso@44 | 30 |
pankso@44 | 31 EOT |
pankso@44 | 32 } |
pankso@44 | 33 |
pankso@44 | 34 # |
pankso@44 | 35 # RPi functions |
pankso@44 | 36 # |
pankso@44 | 37 |
paul@65 | 38 # This could move to /usr/bin/slitaz-??? or something since it's not |
pankso@58 | 39 # ARM specific |
pankso@44 | 40 rpi_stats() { |
pankso@58 | 41 ip=$(ifconfig | fgrep -A 1 "encap:Ethernet" | fgrep "inet" | cut -d ":" -f 2) |
pankso@58 | 42 mem_total=$(free -m | fgrep "Mem:" | awk '{print $2}') |
pankso@58 | 43 mem_used=$(free -m | fgrep "Mem:" | awk '{print $3}') |
pankso@58 | 44 mem_used_pct=$(( ( ${mem_used} * 100) / ${mem_total} )) |
pankso@44 | 45 cat << EOT |
pankso@67 | 46 $(gettext 'Kernel') : $(uname -snrm) |
pankso@67 | 47 $(gettext 'Uptime') : $(uptime | awk '{print $3}' | sed s"/:/h /" | sed s"/,/min/") |
pankso@67 | 48 $(gettext 'Network IP') : $(echo $ip | awk '{print $1}') |
pankso@67 | 49 $(gettext 'CPU heat') : $(awk '{printf "%3.1f C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp) |
pankso@67 | 50 $(gettext 'Processes') : $(ps | wc -l) |
pankso@67 | 51 $(gettext 'Memory usage') : ${mem_used_pct}% |
pankso@44 | 52 EOT |
pankso@44 | 53 } |
pankso@44 | 54 |
pankso@44 | 55 rpi_turbo() { |
pankso@44 | 56 if ! fgrep -q 'force_turbo=1' ${config}; then |
pankso@44 | 57 gettext "Enabling Raspberry Pi force turbo..." |
pankso@44 | 58 echo "force_turbo=1" >> ${config}; status |
pankso@44 | 59 else |
pankso@44 | 60 gettext "Disabling Raspberry Pi force turbo..." |
pankso@44 | 61 sed -i '/force_turbo=1/'d ${config}; status |
pankso@44 | 62 fi |
pankso@44 | 63 } |
pankso@44 | 64 |
pankso@44 | 65 # RPi Overclocking |
pankso@44 | 66 rpi_oclock() { |
pankso@44 | 67 cat << EOT |
pankso@44 | 68 none 700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt |
pankso@44 | 69 modest 800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt |
pankso@44 | 70 medium 900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt |
pankso@44 | 71 high 950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt |
pankso@44 | 72 turbo 1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt |
pankso@44 | 73 EOT |
pankso@44 | 74 } |
pankso@44 | 75 |
pankso@44 | 76 # |
pankso@44 | 77 # GUI Functions |
pankso@44 | 78 # |
pankso@44 | 79 |
pankso@44 | 80 # Usage: msg_box "title" "message" |
pankso@44 | 81 msg_box() { |
pankso@44 | 82 dialog --title "{ $1 }" --cr-wrap \ |
pankso@44 | 83 --ok-label "TazBerry" --msgbox "\n$2" ${height} ${width} |
pankso@44 | 84 } |
pankso@44 | 85 |
pankso@44 | 86 # Usage: text_box "file" |
pankso@44 | 87 text_box() { |
pankso@44 | 88 local file="$1" |
pankso@44 | 89 if [ -f "$file" ]; then |
pankso@44 | 90 dialog --cr-wrap \ |
pankso@44 | 91 --title " $(gettext 'Viewing file:') $file " \ |
pankso@44 | 92 --extra-button \ |
pankso@44 | 93 --extra-label "Edit file" \ |
pankso@44 | 94 --ok-label "TazBerry" \ |
pankso@44 | 95 --textbox ${file} ${height} ${width} |
pankso@44 | 96 else |
pankso@44 | 97 dialog --title "$title" \ |
pankso@44 | 98 --msgbox "\nERROR: $file does not exist" 10 ${width} |
pankso@44 | 99 fi |
pankso@44 | 100 # Handle options |
pankso@44 | 101 case "$?" in |
pankso@73 | 102 3) editor ${file} ;; |
pankso@44 | 103 esac |
pankso@44 | 104 } |
pankso@44 | 105 |
pankso@44 | 106 # Usage: tail_box "file" |
pankso@44 | 107 tail_box() { |
pankso@44 | 108 dialog --title " $(gettext 'Watching file:') $2 " \ |
pankso@44 | 109 --tailbox "$1" ${height} ${width} |
pankso@44 | 110 } |
pankso@44 | 111 |
pankso@44 | 112 # Packages info and spk-up button |
pankso@44 | 113 pkgs_box() { |
pankso@44 | 114 out="$tmpdir/spk-info.txt" |
pankso@44 | 115 spk info --output=raw > ${out} |
pankso@44 | 116 dialog --cr-wrap \ |
pankso@44 | 117 --title "{ $(gettext 'Packages') }" \ |
pankso@44 | 118 --extra-button \ |
pankso@44 | 119 --extra-label "$(gettext 'Upgrade')" \ |
pankso@44 | 120 --ok-label "TazBerry" \ |
pankso@44 | 121 --textbox "$out" ${height} ${width} |
pankso@44 | 122 # Handle options |
pankso@44 | 123 case "$?" in |
pankso@44 | 124 3) spk-up && gettext "Press ENTER to go back to TazBerry"; read ;; |
pankso@44 | 125 esac |
pankso@44 | 126 } |
pankso@44 | 127 |
pankso@44 | 128 oclock_box() { |
pankso@44 | 129 out="$tmpdir/overclocking.txt" |
pankso@44 | 130 cat > ${out} << EOT |
pankso@44 | 131 |
pankso@44 | 132 Overclocking modes: |
pankso@44 | 133 ------------------- |
pankso@44 | 134 $(rpi_oclock) |
pankso@44 | 135 |
pankso@44 | 136 Current /boot/config.txt |
pankso@44 | 137 ------------------------ |
pankso@100 | 138 $(fgrep _freq /boot/config.txt) |
pankso@100 | 139 $(fgrep over_voltage /boot/config.txt) |
pankso@44 | 140 |
pankso@44 | 141 EOT |
pankso@44 | 142 dialog --cr-wrap \ |
pankso@44 | 143 --title "$title" \ |
pankso@44 | 144 --ok-label "TazBerry" \ |
pankso@44 | 145 --textbox "$out" ${height} ${width} |
pankso@44 | 146 } |
pankso@44 | 147 |
pankso@44 | 148 # Main Dialog menu |
pankso@44 | 149 main_box() { |
pankso@44 | 150 dialog \ |
pankso@44 | 151 --clear \ |
pankso@44 | 152 --title "$title" \ |
pankso@44 | 153 --ok-label "Exec" \ |
pankso@44 | 154 --cancel-label "Quit" \ |
pankso@44 | 155 --menu "" ${height} ${width} 14 \ |
pankso@44 | 156 "rpi-stats" "$(gettext 'Show some RPi system stats')" \ |
pankso@88 | 157 "boot-cmdline" "$(gettext 'View boot args /boot/cmdline.txt')" \ |
pankso@88 | 158 "boot-config" "$(gettext 'View config file /boot/config.txt')" \ |
pankso@100 | 159 "oclock" "$(gettext 'Overclocking information and config')" \ |
pankso@44 | 160 "rpi-turbo" "$(gettext 'Enable or disable RPi turbo on next boot')" \ |
pankso@100 | 161 "act-led" "$(gettext 'Test RPi onboard ACT green led')" \ |
pankso@88 | 162 "packages" "$(gettext 'Spk packages manager')" \ |
pankso@88 | 163 "config" "$(gettext 'System config (lang, keyboard)')" \ |
pankso@44 | 164 "reboot" "$(gettext 'Reboot SliTaz')" \ |
pankso@44 | 165 "halt" "$(gettext 'Halt the Raspberry Pi')" \ |
pankso@88 | 166 "quit" "$(gettext 'Exit TazBerry tool')" 2>${tmp} |
pankso@44 | 167 |
pankso@44 | 168 # Handle options |
pankso@44 | 169 opt=${?} |
pankso@44 | 170 case "$opt" in |
pankso@46 | 171 1|255) rm -rf ${tmpdir} && exit 0 ;; |
pankso@44 | 172 esac |
pankso@44 | 173 |
pankso@44 | 174 # Handle actions |
pankso@44 | 175 action=$(cat $tmp) |
pankso@44 | 176 case "$action" in |
pankso@44 | 177 rpi-stats) |
pankso@44 | 178 msg_box "RPi Stats" "$(rpi_stats)" ;; |
pankso@88 | 179 boot-cmdline) |
pankso@44 | 180 text_box /boot/cmdline.txt ;; |
pankso@88 | 181 boot-config) |
pankso@44 | 182 text_box ${config} ;; |
pankso@100 | 183 oclock) |
pankso@100 | 184 oclock_box ;; |
pankso@44 | 185 rpi-turbo) |
pankso@44 | 186 rpi_turbo && newline |
pankso@44 | 187 gettext "Press ENTER to go back to TazBerry"; read ;; |
pankso@100 | 188 act-led) |
pankso@100 | 189 brightness="/sys/class/leds/led0/brightness" |
pankso@100 | 190 (echo "1" > ${brightness} |
pankso@100 | 191 sleep 2; echo "0" > ${brightness}) & ;; |
pankso@44 | 192 packages) |
pankso@88 | 193 spk-dialog ;; |
pankso@88 | 194 config) |
pankso@88 | 195 slitaz-config ;; |
pankso@44 | 196 reboot) |
pankso@44 | 197 reboot ;; |
pankso@44 | 198 halt) |
pankso@44 | 199 halt ;; |
pankso@44 | 200 quit) |
pankso@44 | 201 rm -rf ${tmpdir} && exit 0 ;; |
pankso@44 | 202 esac |
pankso@44 | 203 } |
pankso@44 | 204 |
pankso@44 | 205 # Progress bar testsuite |
pankso@44 | 206 gauge_box() { |
pankso@44 | 207 { for i in $(seq 1 100); do |
pankso@44 | 208 echo $i |
pankso@44 | 209 sleep 0.01 |
pankso@44 | 210 done |
pankso@44 | 211 echo 100; } | dialog --title "{ TazBerry }" \ |
pankso@44 | 212 --gauge "Work in progress..." 6 ${width} 0 |
pankso@44 | 213 } |
pankso@44 | 214 |
pankso@44 | 215 # |
pankso@44 | 216 # Handle commands |
pankso@44 | 217 # |
pankso@44 | 218 |
pankso@44 | 219 case "$1" in |
pankso@44 | 220 oclock) |
pankso@44 | 221 newline |
pankso@44 | 222 boldify "Overclocking modes:" |
pankso@44 | 223 rpi_oclock |
pankso@44 | 224 boldify "Current config.txt:" |
pankso@44 | 225 cat ${config} |
pankso@44 | 226 newline ;; |
pankso@44 | 227 |
pankso@44 | 228 ls-functions) |
pankso@44 | 229 newline |
pankso@44 | 230 boldify "$(gettext 'TazBerry functions list')" |
pankso@44 | 231 separator |
pankso@44 | 232 grep "^rpi_*" $0 | awk '{print " ", $1}' |
pankso@44 | 233 newline ;; |
pankso@44 | 234 |
pankso@44 | 235 testsuite) |
pankso@44 | 236 gauge_box |
pankso@44 | 237 msg_box "Testsuite" "Test message" |
pankso@44 | 238 rpi_stats |
pankso@44 | 239 newline ;; |
pankso@44 | 240 |
pankso@44 | 241 rpi_*) |
pankso@44 | 242 # Execute functions |
pankso@44 | 243 $@ ;; |
pankso@44 | 244 |
pankso@44 | 245 "") |
pankso@44 | 246 # No args: display Ncurses dialog |
pankso@44 | 247 while true; do |
pankso@44 | 248 main_box |
pankso@44 | 249 done ;; |
pankso@44 | 250 |
pankso@44 | 251 *|*help|-h) |
pankso@44 | 252 # Display help |
pankso@44 | 253 help ;; |
pankso@44 | 254 esac |
pankso@44 | 255 |
pankso@44 | 256 # Clean exit |
pankso@44 | 257 rm -rf ${tmpdir} |
pankso@44 | 258 exit 0 |