Checking of initial state added for camera and 1-wire; unnecessary reboots removed.

This commit is contained in:
spl 2016-05-24 11:37:36 +01:00
parent f60f081a6f
commit 96c31754d7

View File

@ -640,8 +640,10 @@ get_serial() {
do_serial() { do_serial() {
DEFAULT=--defaultno DEFAULT=--defaultno
CURRENT=0
if [ $(get_serial) -eq 0 ] ; then if [ $(get_serial) -eq 0 ] ; then
DEFAULT= DEFAULT=
CURRENT=1
fi fi
if [ "$INTERACTIVE" = True ]; then if [ "$INTERACTIVE" = True ]; then
@ -651,6 +653,9 @@ do_serial() {
get_init_sys get_init_sys
RET=$1 RET=$1
fi fi
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 1 ]; then if [ $RET -eq 1 ]; then
if [ $SYSTEMD -eq 0 ]; then if [ $SYSTEMD -eq 0 ]; then
sed -i /etc/inittab -e "s|^.*:.*:respawn:.*ttyAMA0|#&|" sed -i /etc/inittab -e "s|^.*:.*:respawn:.*ttyAMA0|#&|"
@ -659,7 +664,7 @@ do_serial() {
sed -i /boot/cmdline.txt -e "s/console=serial0,[0-9]\+ //" sed -i /boot/cmdline.txt -e "s/console=serial0,[0-9]\+ //"
set_config_var enable_uart 0 $CONFIG set_config_var enable_uart 0 $CONFIG
if [ "$INTERACTIVE" = True ]; then if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Serial is now disabled" 20 60 1 whiptail --msgbox "The serial interface is disabled" 20 60 1
fi fi
elif [ $RET -eq 0 ]; then elif [ $RET -eq 0 ]; then
if [ $SYSTEMD -eq 0 ]; then if [ $SYSTEMD -eq 0 ]; then
@ -681,12 +686,11 @@ do_serial() {
fi fi
set_config_var enable_uart 1 $CONFIG set_config_var enable_uart 1 $CONFIG
if [ "$INTERACTIVE" = True ]; then if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Serial is now enabled" 20 60 1 whiptail --msgbox "The serial interface is enabled" 20 60 1
fi fi
else else
return $RET return $RET
fi fi
ASK_TO_REBOOT=1
} }
disable_raspi_config_at_boot() { disable_raspi_config_at_boot() {
@ -935,28 +939,12 @@ registration.\
read TMP read TMP
} }
# $1 is 0 to disable camera, 1 to enable it get_camera() {
set_camera() { CAM=$(get_config_var start_x $CONFIG)
# Stop if /boot is not a mountpoint if [ $CAM -eq 1 ]; then
if ! mountpoint -q /boot; then echo 0
return 1 else
fi echo 1
[ -e $CONFIG ] || touch $CONFIG
if [ "$1" -eq 0 ]; then # disable camera
set_config_var start_x 0 $CONFIG
sed $CONFIG -i -e "s/^startx/#startx/"
sed $CONFIG -i -e "s/^start_file/#start_file/"
sed $CONFIG -i -e "s/^fixup_file/#fixup_file/"
else # enable camera
set_config_var start_x 1 $CONFIG
CUR_GPU_MEM=$(get_config_var gpu_mem $CONFIG)
if [ -z "$CUR_GPU_MEM" ] || [ "$CUR_GPU_MEM" -lt 128 ]; then
set_config_var gpu_mem 128 $CONFIG
fi
sed $CONFIG -i -e "s/^startx/#startx/"
sed $CONFIG -i -e "s/^fixup_file/#fixup_file/"
fi fi
} }
@ -965,16 +953,45 @@ do_camera() {
whiptail --msgbox "Your firmware appears to be out of date (no start_x.elf). Please update" 20 60 2 whiptail --msgbox "Your firmware appears to be out of date (no start_x.elf). Please update" 20 60 2
return 1 return 1
fi fi
# Stop if /boot is not a mountpoint
if ! mountpoint -q /boot; then
return 1
fi
DEFAULT=--defaultno
CURRENT=0
if [ $(get_camera) -eq 0 ] ; then
DEFAULT=
CURRENT=1
fi
[ -e $CONFIG ] || touch $CONFIG
sed $CONFIG -i -e "s/^startx/#startx/"
sed $CONFIG -i -e "s/^fixup_file/#fixup_file/"
if [ "$INTERACTIVE" = True ]; then if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Enable support for Raspberry Pi camera?" 20 60 2 \ whiptail --yesno "Would you like the camera interface to be enabled?" $DEFAULT 20 60 2
--yes-button Disable --no-button Enable
RET=$? RET=$?
else else
RET=$1 RET=$1
fi fi
if [ $RET -eq 0 ] || [ $RET -eq 1 ]; then if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1 ASK_TO_REBOOT=1
set_camera $RET; fi
if [ $RET -eq 1 ]; then
set_config_var start_x 0 $CONFIG
sed $CONFIG -i -e "s/^start_file/#start_file/"
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The camera interface is disabled" 20 60 1
fi
elif [ $RET -eq 0 ]; then
set_config_var start_x 1 $CONFIG
CUR_GPU_MEM=$(get_config_var gpu_mem $CONFIG)
if [ -z "$CUR_GPU_MEM" ] || [ "$CUR_GPU_MEM" -lt 128 ]; then
set_config_var gpu_mem 128 $CONFIG
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The camera interface is enabled" 20 60 1
fi
else else
return 1 return 1
fi fi
@ -988,15 +1005,25 @@ get_onewire() {
fi fi
} }
# $1 is 1 to disable interface, 0 to enable it do_onewire() {
set_onewire() { DEFAULT=--defaultno
CURRENT=0
if [ $(get_onewire) -eq 0 ]; then
DEFAULT=
CURRENT=1
fi
[ -e $CONFIG ] || touch $CONFIG [ -e $CONFIG ] || touch $CONFIG
if [ "$1" -eq 1 ]; then # disable driver if [ "$INTERACTIVE" = True ]; then
sed $CONFIG -i -e "s/^dtoverlay=w1-gpio/#dtoverlay=w1-gpio/" whiptail --yesno "Would you like the one-wire interface to be enabled?" $DEFAULT 20 60 2
if [ "$INTERACTIVE" = True ]; then RET=$?
whiptail --msgbox "The one-wire interface is disabled" 20 60 1 else
fi RET=$1
else # enable driver fi
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
sed $CONFIG -i -e "s/^#dtoverlay=w1-gpio/dtoverlay=w1-gpio/" sed $CONFIG -i -e "s/^#dtoverlay=w1-gpio/dtoverlay=w1-gpio/"
if ! grep -q -E "^dtoverlay=w1-gpio" $CONFIG; then if ! grep -q -E "^dtoverlay=w1-gpio" $CONFIG; then
printf "dtoverlay=w1-gpio\n" >> $CONFIG printf "dtoverlay=w1-gpio\n" >> $CONFIG
@ -1004,24 +1031,11 @@ set_onewire() {
if [ "$INTERACTIVE" = True ]; then if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The one-wire interface is enabled" 20 60 1 whiptail --msgbox "The one-wire interface is enabled" 20 60 1
fi fi
fi elif [ $RET -eq 1 ]; then
} sed $CONFIG -i -e "s/^dtoverlay=w1-gpio/#dtoverlay=w1-gpio/"
if [ "$INTERACTIVE" = True ]; then
do_onewire() { whiptail --msgbox "The one-wire interface is disabled" 20 60 1
DEFAULT=--defaultno fi
if [ $(get_onewire) -eq 0 ]; then
DEFAULT=
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the one-wire interface to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq 0 ] || [ $RET -eq 1 ]; then
ASK_TO_REBOOT=1
set_onewire $RET;
else else
return 1 return 1
fi fi