slitaz-arm annotate rpi/tazberry @ rev 44

Add TazBerry, kernel config patch and some fixes to spi
author Christophe Lincoln <pankso@slitaz.org>
date Sun Mar 09 10:14:01 2014 +0100 (2014-03-09)
parents
children b946dc4f933a
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
pankso@44 38 rpi_stats() {
pankso@44 39 cat << EOT
pankso@44 40 $(gettext 'Kernel') : $(uname -snrm)
pankso@44 41 $(gettext 'Uptime') :$(uptime | cut -d "," -f 1,2)
pankso@44 42 $(gettext 'CPU heat') : $(awk '{printf "%3.1f C\n", $1/1000}' \
pankso@44 43 /sys/class/thermal/thermal_zone0/temp)
pankso@44 44 EOT
pankso@44 45 }
pankso@44 46
pankso@44 47 rpi_turbo() {
pankso@44 48 if ! fgrep -q 'force_turbo=1' ${config}; then
pankso@44 49 gettext "Enabling Raspberry Pi force turbo..."
pankso@44 50 echo "force_turbo=1" >> ${config}; status
pankso@44 51 else
pankso@44 52 gettext "Disabling Raspberry Pi force turbo..."
pankso@44 53 sed -i '/force_turbo=1/'d ${config}; status
pankso@44 54 fi
pankso@44 55 }
pankso@44 56
pankso@44 57 # RPi Overclocking
pankso@44 58 rpi_oclock() {
pankso@44 59 cat << EOT
pankso@44 60 none 700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt
pankso@44 61 modest 800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt
pankso@44 62 medium 900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt
pankso@44 63 high 950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt
pankso@44 64 turbo 1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt
pankso@44 65 EOT
pankso@44 66 }
pankso@44 67
pankso@44 68 #
pankso@44 69 # GUI Functions
pankso@44 70 #
pankso@44 71
pankso@44 72 # Usage: msg_box "title" "message"
pankso@44 73 msg_box() {
pankso@44 74 dialog --title "{ $1 }" --cr-wrap \
pankso@44 75 --ok-label "TazBerry" --msgbox "\n$2" ${height} ${width}
pankso@44 76 }
pankso@44 77
pankso@44 78 # Usage: text_box "file"
pankso@44 79 text_box() {
pankso@44 80 local file="$1"
pankso@44 81 if [ -f "$file" ]; then
pankso@44 82 dialog --cr-wrap \
pankso@44 83 --title " $(gettext 'Viewing file:') $file " \
pankso@44 84 --extra-button \
pankso@44 85 --extra-label "Edit file" \
pankso@44 86 --ok-label "TazBerry" \
pankso@44 87 --textbox ${file} ${height} ${width}
pankso@44 88 else
pankso@44 89 dialog --title "$title" \
pankso@44 90 --msgbox "\nERROR: $file does not exist" 10 ${width}
pankso@44 91 fi
pankso@44 92 # Handle options
pankso@44 93 case "$?" in
pankso@44 94 3) nano ${file} ;;
pankso@44 95 esac
pankso@44 96 }
pankso@44 97
pankso@44 98 # Usage: tail_box "file"
pankso@44 99 tail_box() {
pankso@44 100 dialog --title " $(gettext 'Watching file:') $2 " \
pankso@44 101 --tailbox "$1" ${height} ${width}
pankso@44 102 }
pankso@44 103
pankso@44 104 # Packages info and spk-up button
pankso@44 105 pkgs_box() {
pankso@44 106 out="$tmpdir/spk-info.txt"
pankso@44 107 spk info --output=raw > ${out}
pankso@44 108 dialog --cr-wrap \
pankso@44 109 --title "{ $(gettext 'Packages') }" \
pankso@44 110 --extra-button \
pankso@44 111 --extra-label "$(gettext 'Upgrade')" \
pankso@44 112 --ok-label "TazBerry" \
pankso@44 113 --textbox "$out" ${height} ${width}
pankso@44 114 # Handle options
pankso@44 115 case "$?" in
pankso@44 116 3) spk-up && gettext "Press ENTER to go back to TazBerry"; read ;;
pankso@44 117 esac
pankso@44 118 }
pankso@44 119
pankso@44 120 oclock_box() {
pankso@44 121 out="$tmpdir/overclocking.txt"
pankso@44 122 cat > ${out} << EOT
pankso@44 123
pankso@44 124 Overclocking modes:
pankso@44 125 -------------------
pankso@44 126 $(rpi_oclock)
pankso@44 127
pankso@44 128 Current /boot/config.txt
pankso@44 129 ------------------------
pankso@44 130 $(cat $config)
pankso@44 131
pankso@44 132 EOT
pankso@44 133 dialog --cr-wrap \
pankso@44 134 --title "$title" \
pankso@44 135 --ok-label "TazBerry" \
pankso@44 136 --textbox "$out" ${height} ${width}
pankso@44 137 }
pankso@44 138
pankso@44 139 # Main Dialog menu
pankso@44 140 main_box() {
pankso@44 141 dialog \
pankso@44 142 --clear \
pankso@44 143 --title "$title" \
pankso@44 144 --ok-label "Exec" \
pankso@44 145 --cancel-label "Quit" \
pankso@44 146 --menu "" ${height} ${width} 14 \
pankso@44 147 "rpi-stats" "$(gettext 'Show some RPi system stats')" \
pankso@44 148 "cmdline.txt" "$(gettext 'View boot args /boot/cmdline.txt')" \
pankso@44 149 "config.txt" "$(gettext 'View config file /boot/config.txt')" \
pankso@44 150 "rpi-turbo" "$(gettext 'Enable or disable RPi turbo on next boot')" \
pankso@44 151 "oclock" "$(gettext 'Overclocking information and config')" \
pankso@44 152 "packages" "$(gettext 'Packages info and upgrade (spk)')" \
pankso@44 153 "keyboard" "$(gettext 'System keyboard setting')" \
pankso@44 154 "reboot" "$(gettext 'Reboot SliTaz')" \
pankso@44 155 "halt" "$(gettext 'Halt the Raspberry Pi')" \
pankso@44 156 "quit" "$(gettext 'Exit from TazBerry tool')" 2>${tmp}
pankso@44 157
pankso@44 158 # Handle options
pankso@44 159 opt=${?}
pankso@44 160 case "$opt" in
pankso@44 161 1|255) rm ${tmpdir} && exit 0 ;;
pankso@44 162 esac
pankso@44 163
pankso@44 164 # Handle actions
pankso@44 165 action=$(cat $tmp)
pankso@44 166 case "$action" in
pankso@44 167 rpi-stats)
pankso@44 168 msg_box "RPi Stats" "$(rpi_stats)" ;;
pankso@44 169 cmdline.txt)
pankso@44 170 text_box /boot/cmdline.txt ;;
pankso@44 171 config.txt)
pankso@44 172 text_box ${config} ;;
pankso@44 173 rpi-turbo)
pankso@44 174 rpi_turbo && newline
pankso@44 175 gettext "Press ENTER to go back to TazBerry"; read ;;
pankso@44 176 oclock)
pankso@44 177 oclock_box ;;
pankso@44 178 packages)
pankso@44 179 pkgs_box ;;
pankso@44 180 keyboard)
pankso@44 181 tazkeymap ;;
pankso@44 182 reboot)
pankso@44 183 reboot ;;
pankso@44 184 halt)
pankso@44 185 halt ;;
pankso@44 186 quit)
pankso@44 187 rm -rf ${tmpdir} && exit 0 ;;
pankso@44 188 esac
pankso@44 189 }
pankso@44 190
pankso@44 191 # Progress bar testsuite
pankso@44 192 gauge_box() {
pankso@44 193 { for i in $(seq 1 100); do
pankso@44 194 echo $i
pankso@44 195 sleep 0.01
pankso@44 196 done
pankso@44 197 echo 100; } | dialog --title "{ TazBerry }" \
pankso@44 198 --gauge "Work in progress..." 6 ${width} 0
pankso@44 199 }
pankso@44 200
pankso@44 201 #
pankso@44 202 # Handle commands
pankso@44 203 #
pankso@44 204
pankso@44 205 case "$1" in
pankso@44 206 oclock)
pankso@44 207 newline
pankso@44 208 boldify "Overclocking modes:"
pankso@44 209 rpi_oclock
pankso@44 210 boldify "Current config.txt:"
pankso@44 211 cat ${config}
pankso@44 212 newline ;;
pankso@44 213
pankso@44 214 ls-functions)
pankso@44 215 newline
pankso@44 216 boldify "$(gettext 'TazBerry functions list')"
pankso@44 217 separator
pankso@44 218 grep "^rpi_*" $0 | awk '{print " ", $1}'
pankso@44 219 newline ;;
pankso@44 220
pankso@44 221 testsuite)
pankso@44 222 gauge_box
pankso@44 223 msg_box "Testsuite" "Test message"
pankso@44 224 rpi_stats
pankso@44 225 newline ;;
pankso@44 226
pankso@44 227 rpi_*)
pankso@44 228 # Execute functions
pankso@44 229 $@ ;;
pankso@44 230
pankso@44 231 "")
pankso@44 232 # No args: display Ncurses dialog
pankso@44 233 while true; do
pankso@44 234 main_box
pankso@44 235 done ;;
pankso@44 236
pankso@44 237 *|*help|-h)
pankso@44 238 # Display help
pankso@44 239 help ;;
pankso@44 240 esac
pankso@44 241
pankso@44 242 # Clean exit
pankso@44 243 rm -rf ${tmpdir}
pankso@44 244 exit 0