@@ -261,53 +261,96 @@ module_options+=(
261261#
262262armbian_fw_manipulate () {
263263
264- function=$1
264+ local function=$1
265+ local version=$2
266+
267+ [[ -n $version ]] && local version=" =${version} "
265268
266269 # fallback to current
267270 [[ -z $BRANCH ]] && BRANCH=" current"
268271
269- ARMBIAN_PACKAGES=(
272+ # packages to install
273+ local armbian_packages=(
270274 " linux-u-boot-${BOARD} -${BRANCH} "
271275 " linux-image-${BRANCH} -${LINUXFAMILY} "
272276 " linux-dtb-${BRANCH} -${LINUXFAMILY} "
273- " linux-headers-${BRANCH} -${LINUXFAMILY} "
274277 " armbian-config"
275- " armbian-zsh"
276- " armbian-bsp-cli-${BOARD} -${BRANCH} "
278+ " armbian-zsh"
277279 )
278280
279- if [[ " ${function} " == reinstall ]]; then
280- debconf-apt-progress -- apt-get update
281+ # reinstall headers only if they were previously installed
282+ if are_headers_installed; then
283+ local armbian_packages+=" linux-headers-${BRANCH} -${LINUXFAMILY} "
281284 fi
282285
283- PACKAGES =" "
284- for PACKAGE in " ${ARMBIAN_PACKAGES [@]} "
286+ local packages =" "
287+ for pkg in " ${armbian_packages [@]} "
285288 do
286289 if [[ " ${function} " == reinstall ]]; then
287- apt search $PACKAGE 2> /dev/null | grep " ^$PACKAGE " > /dev/null
288- if [[ $? -eq 0 ]]; then PACKAGES +=" $PACKAGE " ; fi
290+ apt search " $pkg " 2> /dev/null | grep " ^$pkg " > /dev/null
291+ if [[ $? -eq 0 ]]; then packages +=" $pkg ${version} " ; fi
289292 else
290- if check_if_installed $PACKAGE ; then
291- PACKAGES +=" $PACKAGE "
293+ if check_if_installed $pkg ; then
294+ packages +=" $pkg ${version} "
292295 fi
293296 fi
294297 done
295298
296- case $function in
297- unhold) apt-mark unhold ${PACKAGES} | show_infobox ;;
298- hold) apt-mark hold ${PACKAGES} | show_infobox ;;
299- reinstall)
300- debconf-apt-progress -- apt-get -y --download-only install ${PACKAGES}
301- debconf-apt-progress -- apt-get -y purge ${PACKAGES}
302- debconf-apt-progress -- apt-get -y install ${PACKAGES}
303- debconf-apt-progress -- apt-get -y autoremove
304- ;;
305- * ) return ;;
306- esac
307-
299+ for pkg in " ${packages[@]} "
300+ do
301+ case $function in
302+ unhold) apt-mark unhold ${pkg} | show_infobox ;;
303+ hold) apt-mark hold ${pkg} | show_infobox ;;
304+ reinstall)
305+ apt_install_wrapper apt-get -y --download-only --allow-change-held-packages --allow-downgrades install " ${pkg} "
306+ apt_install_wrapper apt-get -y purge " ${pkg} "
307+ apt_install_wrapper apt-get -y --allow-change-held-packages --allow-downgrades install " ${pkg} "
308+ apt_install_wrapper apt-get -y autoremove
309+ ;;
310+ * ) return ;;
311+ esac
312+ done
308313}
309314
310315
316+ module_options+=(
317+ [" switch_kernels,author" ]=" Igor"
318+ [" switch_kernels,ref_link" ]=" "
319+ [" switch_kernels,feature" ]=" "
320+ [" switch_kernels,desc" ]=" Switching to alternative kernels"
321+ [" switch_kernels,example" ]=" "
322+ [" switch_kernels,status" ]=" Active"
323+ )
324+ #
325+ # @description Switch between alternative kernels
326+ #
327+ function switch_kernels () {
328+
329+ # we only allow switching kerneles that are in the test pool
330+ [[ -z " ${KERNEL_TEST_TARGET} " ]] && KERNEL_TEST_TARGET=" legacy,current,edge"
331+ local kernel_test_target=" (" $( echo $KERNEL_TEST_TARGET | sed " s/,/|/g" ) " )"
332+ local current_kernel_version=$( dpkg -l | grep ' ^ii' | grep linux-image | awk ' {print $2"="$3}' )
333+
334+ IFS=$' \n '
335+ local LIST=()
336+ for line in $( \
337+ apt-cache show " linux-image-${kernel_test_target} -${LINUXFAMILY} " | grep -E " Package:|Version:|version:|family" \
338+ | grep -v " Config-Version" | sed -n -e ' s/^.*: //p' | sed ' s/\.$//g' | xargs -n3 -d' \n' | sed " s/ /=/" \
339+ | grep -v ${current_kernel_version} ) ; do
340+ LIST+=($( echo $line | awk -F ' ' ' {print $1 " "}' ) $( echo $line | awk -F ' ' ' {print "v"$2}' ) )
341+ done
342+ unset IFS
343+ local list_length=$(( ${# LIST[@]} / 2 )) ;
344+ if [ " $list_length " -eq 0 ]; then
345+ dialog --backtitle " $BACKTITLE " --title " Warning " --msgbox " \nNo other kernels available!" 7 32
346+ else
347+ local target_version=$( whiptail --separate-output --title " Select kernel" --menu " ed" $(( ${list_length} + 7 )) 80 $(( ${list_length} )) " ${LIST[@]} " 3>&1 1>&2 2>&3 )
348+ if [ $? -eq 0 ] && [ -n " ${target_version} " ]; then
349+ armbian_fw_manipulate " reinstall" " ${target_version/* =/ } "
350+ fi
351+ fi
352+ }
353+
311354
312355module_options+=(
313356[" connect_bt_interface,author" ]=" Igor Pecovnik"
@@ -356,7 +399,7 @@ function connect_bt_interface(){
356399 if [[ $( echo " $BT_EXEC " | grep " Connection successful" ) != " " ]]; then
357400 show_message <<< " \nYour device is ready to use!"
358401 else
359- show_message <<< " \nError connecting. Try again!"
402+ show_message <<< " \nError connecting. Try again!"
360403 fi
361404 fi
362405 fi
@@ -570,18 +613,18 @@ function execute_command() {
570613
571614 # Extract commands
572615 local commands=$( jq -r --arg id " $id " '
573- .menu[] |
574- .. |
575- objects |
576- select(.id == $id) |
616+ .menu[] |
617+ .. |
618+ objects |
619+ select(.id == $id) |
577620 .command[]?' " $json_file " )
578621
579622 # Check if a prompt exists
580623 local prompt=$( jq -r --arg id " $id " '
581- .menu[] |
582- .. |
583- objects |
584- select(.id == $id) |
624+ .menu[] |
625+ .. |
626+ objects |
627+ select(.id == $id) |
585628 .prompt?' " $json_file " )
586629
587630 # If a prompt exists, display it and wait for user confirmation
@@ -676,7 +719,7 @@ show_menu(){
676719
677720 # Get the input and convert it into an array of options
678721 inpu_raw=$( cat)
679- # Remove the lines before -h
722+ # Remove the lines before -h
680723 input=$( echo " $inpu_raw " | sed ' s/-\([a-zA-Z]\)/\1/' | grep ' ^ [a-zA-Z] ' | grep -v ' \[' )
681724 options=()
682725 while read -r line; do
@@ -693,7 +736,7 @@ show_menu(){
693736 echo " $choice "
694737 else
695738 exit 0
696- fi
739+ fi
697740
698741 }
699742
@@ -777,7 +820,7 @@ function get_user_continue_secure() {
777820 fi
778821 else
779822 echo " Error: Invalid function"
780-
823+
781824 exit 1
782825 fi
783826}
0 commit comments