Merge branch 'master' of github.com:RPi-Distro/raspi-config

This commit is contained in:
Simon Long 2017-05-03 11:28:42 +01:00
commit febb2ef0c6
3 changed files with 67 additions and 38 deletions

7
debian/changelog vendored
View File

@ -1,3 +1,10 @@
raspi-config (20170307) jessie; urgency=medium
* Run init_resize.sh through shellcheck
* Improve init_resize.sh reliability
-- Serge Schneider <serge@raspberrypi.org> Tue, 07 Mar 2017 13:49:57 +0000
raspi-config (20170228) jessie; urgency=medium
* Added detection of 0 W boards

View File

@ -2,6 +2,7 @@
reboot_pi () {
umount /boot
mount / -o remount,ro
sync
echo b > /proc/sysrq-trigger
sleep 5
@ -10,11 +11,11 @@ reboot_pi () {
check_commands () {
if ! command -v whiptail > /dev/null; then
echo ="whiptail not found"
echo "whiptail not found"
sleep 5
return 1
fi
for COMMAND in grep cut sed parted fdisk; do
for COMMAND in grep cut sed parted fdisk findmnt partprobe; do
if ! command -v $COMMAND > /dev/null; then
FAIL_REASON="$COMMAND not found"
return 1
@ -24,7 +25,7 @@ check_commands () {
}
check_noobs () {
if [ "$BOOT_PART_DEV" = "/dev/mmcblk0p1" ]; then
if [ "$BOOT_PART_NUM" = "1" ]; then
NOOBS=0
else
NOOBS=1
@ -32,59 +33,73 @@ check_noobs () {
}
get_variables () {
ROOT_PART_DEV=`grep -Eo 'root=[[:graph:]]+' /proc/cmdline | cut -d "=" -f 2-`
ROOT_PART_NAME=`echo $ROOT_PART_DEV | cut -d "/" -f 3`
ROOT_DEV_NAME=`echo /sys/block/*/${ROOT_PART_NAME} | cut -d "/" -f 4`
ROOT_PART_DEV=$(findmnt / -o source -n)
ROOT_PART_NAME=$(echo "$ROOT_PART_DEV" | cut -d "/" -f 3)
ROOT_DEV_NAME=$(echo /sys/block/*/"${ROOT_PART_NAME}" | cut -d "/" -f 4)
ROOT_DEV="/dev/${ROOT_DEV_NAME}"
ROOT_PART_NUM=`cat /sys/block/${ROOT_DEV_NAME}/${ROOT_PART_NAME}/partition`
ROOT_PART_NUM=$(cat "/sys/block/${ROOT_DEV_NAME}/${ROOT_PART_NAME}/partition")
BOOT_PART_DEV=`cat /proc/mounts | grep " /boot " | cut -d " " -f 1`
BOOT_PART_NAME=`echo $BOOT_PART_DEV | cut -d "/" -f 3`
BOOT_DEV_NAME=`echo /sys/block/*/${BOOT_PART_NAME} | cut -d "/" -f 4`
BOOT_PART_NUM=`cat /sys/block/${BOOT_DEV_NAME}/${BOOT_PART_NAME}/partition`
BOOT_PART_DEV=$(findmnt /boot -o source -n)
BOOT_PART_NAME=$(echo "$BOOT_PART_DEV" | cut -d "/" -f 3)
BOOT_DEV_NAME=$(echo /sys/block/*/"${BOOT_PART_NAME}" | cut -d "/" -f 4)
BOOT_PART_NUM=$(cat "/sys/block/${BOOT_DEV_NAME}/${BOOT_PART_NAME}/partition")
OLD_DISKID=$(fdisk -l "$ROOT_DEV" | sed -n 's/Disk identifier: 0x\([^ ]*\)/\1/p')
check_noobs
ROOT_DEV_SIZE=`cat /sys/block/${ROOT_DEV_NAME}/size`
TARGET_END=`expr $ROOT_DEV_SIZE - 1`
ROOT_DEV_SIZE=$(cat "/sys/block/${ROOT_DEV_NAME}/size")
TARGET_END=$((ROOT_DEV_SIZE - 1))
PARTITION_TABLE=`parted -m $ROOT_DEV unit s print | tr -d 's'`
PARTITION_TABLE=$(parted -m "$ROOT_DEV" unit s print | tr -d 's')
LAST_PART_NUM=`echo "$PARTITION_TABLE" | tail -n 1 | cut -d ":" -f 1`
LAST_PART_NUM=$(echo "$PARTITION_TABLE" | tail -n 1 | cut -d ":" -f 1)
ROOT_PART_LINE=`echo "$PARTITION_TABLE" | grep -e "^${ROOT_PART_NUM}:"`
ROOT_PART_START=`echo $ROOT_PART_LINE | cut -d ":" -f 2`
ROOT_PART_END=`echo $ROOT_PART_LINE | cut -d ":" -f 3`
ROOT_PART_LINE=$(echo "$PARTITION_TABLE" | grep -e "^${ROOT_PART_NUM}:")
ROOT_PART_START=$(echo "$ROOT_PART_LINE" | cut -d ":" -f 2)
ROOT_PART_END=$(echo "$ROOT_PART_LINE" | cut -d ":" -f 3)
if [ "$NOOBS" = "1" ]; then
EXT_PART_LINE=`echo "$PARTITION_TABLE" | grep ":::;" | head -n 1`
EXT_PART_NUM=`echo $EXT_PART_LINE | cut -d ":" -f 1`
EXT_PART_START=`echo $EXT_PART_LINE | cut -d ":" -f 2`
EXT_PART_END=`echo $EXT_PART_LINE | cut -d ":" -f 3`
EXT_PART_LINE=$(echo "$PARTITION_TABLE" | grep ":::;" | head -n 1)
EXT_PART_NUM=$(echo "$EXT_PART_LINE" | cut -d ":" -f 1)
EXT_PART_START=$(echo "$EXT_PART_LINE" | cut -d ":" -f 2)
EXT_PART_END=$(echo "$EXT_PART_LINE" | cut -d ":" -f 3)
fi
}
fix_partuuid() {
DISKID="$(fdisk -l "$ROOT_DEV" | sed -n 's/Disk identifier: 0x\([^ ]*\)/\1/p')"
sed -i "s/${OLD_DISKID}/${DISKID}/g" /etc/fstab
sed -i "s/${OLD_DISKID}/${DISKID}/" /boot/cmdline.txt
}
check_variables () {
if [ "$NOOBS" = "1" ]; then
if [ $EXT_PART_NUM -gt 4 ] || \
[ $EXT_PART_START -gt $ROOT_PART_START ] || \
[ $EXT_PART_END -lt $ROOT_PART_END ]; then
if [ "$EXT_PART_NUM" -gt 4 ] || \
[ "$EXT_PART_START" -gt "$ROOT_PART_START" ] || \
[ "$EXT_PART_END" -lt "$ROOT_PART_END" ]; then
FAIL_REASON="Unsupported extended partition"
return 1
fi
fi
if [ $ROOT_PART_NUM -ne $LAST_PART_NUM ]; then
if [ "$BOOT_DEV_NAME" != "$ROOT_DEV_NAME" ]; then
FAIL_REASON="Boot and root partitions are on different devices"
return 1
fi
if [ "$ROOT_PART_NUM" -ne "$LAST_PART_NUM" ]; then
FAIL_REASON="Root partition should be last partition"
return 1
fi
if [ $ROOT_PART_END -gt $TARGET_END ]; then
if [ "$ROOT_PART_END" -gt "$TARGET_END" ]; then
FAIL_REASON="Root partition runs past the end of device"
return 1
fi
if [ ! -b $ROOT_DEV ] || [ ! -b $ROOT_PART_DEV ] || [ ! -b $BOOT_PART_DEV ] ; then
if [ ! -b "$ROOT_DEV" ] || [ ! -b "$ROOT_PART_DEV" ] || [ ! -b "$BOOT_PART_DEV" ] ; then
FAIL_REASON="Could not determine partitions"
return 1
fi
@ -98,30 +113,33 @@ main () {
fi
if [ "$NOOBS" = "1" ]; then
BCM_MODULE=`cat /proc/cpuinfo | grep -e "^Hardware" | cut -d ":" -f 2 | tr -d " " | tr '[:upper:]' '[:lower:]'`
if ! modprobe $BCM_MODULE; then
BCM_MODULE=$(grep -e "^Hardware" /proc/cpuinfo | cut -d ":" -f 2 | tr -d " " | tr '[:upper:]' '[:lower:]')
if ! modprobe "$BCM_MODULE"; then
FAIL_REASON="Couldn't load BCM module $BCM_MODULE"
return 1
fi
echo $BOOT_PART_NUM > /sys/module/${BCM_MODULE}/parameters/reboot_part
echo "$BOOT_PART_NUM" > "/sys/module/${BCM_MODULE}/parameters/reboot_part"
fi
if [ $ROOT_PART_END -eq $TARGET_END ]; then
if [ "$ROOT_PART_END" -eq "$TARGET_END" ]; then
reboot_pi
fi
if [ "$NOOBS" = "1" ]; then
if ! parted -m $ROOT_DEV u s resizepart $EXT_PART_NUM yes $TARGET_END; then
if ! parted -m "$ROOT_DEV" u s resizepart "$EXT_PART_NUM" yes "$TARGET_END"; then
FAIL_REASON="Extended partition resize failed"
return 1
fi
fi
if ! parted -m $ROOT_DEV u s resizepart $ROOT_PART_NUM $TARGET_END; then
if ! parted -m "$ROOT_DEV" u s resizepart "$ROOT_PART_NUM" "$TARGET_END"; then
FAIL_REASON="Root partition resize failed"
return 1
fi
partprobe "$ROOT_DEV"
fix_partuuid
return 0
}
@ -129,8 +147,12 @@ mount -t proc proc /proc
mount -t sysfs sys /sys
mount /boot
sed -i 's| quiet init=/usr/lib/raspi-config/init_resize.sh||' /boot/cmdline.txt
mount /boot -o remount,ro
mount / -o remount,rw
sed -i 's| init=/usr/lib/raspi-config/init_resize.sh||' /boot/cmdline.txt
if ! grep -q splash /boot/cmdline.txt; then
sed -i "s/ quiet//g" /boot/cmdline.txt
fi
sync
echo 1 > /proc/sys/kernel/sysrq

View File

@ -351,9 +351,9 @@ do_wifi_country() {
if [ $? -eq 0 ];then
if [ -e /etc/wpa_supplicant/wpa_supplicant.conf ]; then
if grep -q "^country=" /etc/wpa_supplicant/wpa_supplicant.conf ; then
sed -i "s/^country=.*/country=$COUNTRY/g" /etc/wpa_supplicant/wpa_supplicant.conf
sed -i --follow-symlinks "s/^country=.*/country=$COUNTRY/g" /etc/wpa_supplicant/wpa_supplicant.conf
else
sed -i "1i country=$COUNTRY" /etc/wpa_supplicant/wpa_supplicant.conf
sed -i --follow-symlinks "1i country=$COUNTRY" /etc/wpa_supplicant/wpa_supplicant.conf
fi
else
echo "country=$COUNTRY" > /etc/wpa_supplicant/wpa_supplicant.conf