Skip to content

Commit be55d5c

Browse files
committed
Add kernel switching functionality
1 parent 67ed506 commit be55d5c

3 files changed

Lines changed: 96 additions & 43 deletions

File tree

lib/armbian-configng/config.ng.functions.sh

Lines changed: 80 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -261,53 +261,96 @@ module_options+=(
261261
#
262262
armbian_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

312355
module_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
}

lib/armbian-configng/config.ng.jobs.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,17 @@
320320
"src_reference": "",
321321
"author": "Igor Pecovnik",
322322
"condition": "command -v overlayroot-chroot > /dev/null 2>&1 && findmnt -k /media/root-ro | tail -1 | grep -w /media/root-ro > /dev/null 2>&1"
323+
},
324+
{
325+
"id": "S23",
326+
"description": "Install alternative kernels",
327+
"prompt": "Switching between kernels might change functionality of your device. \n\nIt might fail to boot!",
328+
"command": [ "switch_kernels" ],
329+
"status": "Active",
330+
"doc_link": "",
331+
"src_reference": "",
332+
"author": "Igor Pecovnik",
333+
"condition": ""
323334
}
324335
]
325336
},

lib/armbian-configng/config.ng.system.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ function install_de (){
3838
# get user who executed this script
3939
if [ $SUDO_USER ]; then local user=$SUDO_USER; else local user=`whoami`; fi
4040

41-
#debconf-apt-progress --
41+
#debconf-apt-progress --
4242
apt-get update
43-
#debconf-apt-progress --
43+
#debconf-apt-progress --
4444
apt-get -o Dpkg::Options::="--force-confold" -y --install-recommends install armbian-${DISTROID}-desktop-$1 # armbian-bsp-desktop-${BOARD}-${BRANCH}
4545

4646
# clean apt cache
@@ -190,15 +190,14 @@ if [[ "$1" == "enable" ]]; then
190190
[[ ! -f /etc/overlayroot.conf ]] && cp /etc/overlayroot.conf.dpkg-new /etc/overlayroot.conf
191191
sed -i "s/^overlayroot=.*/overlayroot=\"tmpfs\"/" /etc/overlayroot.conf
192192
sed -i "s/^overlayroot_cfgdisk=.*/overlayroot_cfgdisk=\"enabled\"/" /etc/overlayroot.conf
193-
else
193+
else
194194
overlayroot-chroot rm /etc/overlayroot.conf > /dev/null 2>&1
195195
debconf-apt-progress -- apt-get -y purge overlayroot cryptsetup cryptsetup-bin
196196
fi
197197
# reboot is mandatory
198198
reboot
199199
}
200200

201-
202201
module_options+=(
203202
["toggle_ssh_lastlog,author"]="tearran"
204203
["toggle_ssh_lastlog,ref_link"]=""
@@ -225,5 +224,5 @@ else
225224
}' "${SDCARD}/etc/ssh/sshd_config"
226225
sudo service ssh restart
227226
fi
228-
229-
}
227+
}
228+
}

0 commit comments

Comments
 (0)