Skip to content

Commit

Permalink
Add support for headers manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Dec 6, 2024
1 parent 59ed783 commit 59afff1
Showing 1 changed file with 60 additions and 10 deletions.
70 changes: 60 additions & 10 deletions tools/modules/system/module_armbian_firmware.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#declare -A module_options
module_options+=(
["module_armbian_firmware,author"]="@igorpecovnik"
["module_armbian_firmware,feature"]="module_armbian_firmware"
["module_armbian_firmware,example"]="select install show hold unhold repository help"
["module_armbian_firmware,example"]="select install show hold unhold repository headers help"
["module_armbian_firmware,desc"]="Module for Armbian firmware manipulating."
["module_armbian_firmware,status"]="review"
)
Expand Down Expand Up @@ -85,14 +86,16 @@ function module_armbian_firmware() {

;;

"${commands[1]}") # purge old and install selected kernel from desired branch and version
"${commands[1]}") # purge old and install new packages from desired branch and version

# input parameters
local branch=$2
local version=$3
local hide=$3
local headers=$5

# generate list
${module_options["module_armbian_firmware,feature"]} ${commands[2]} "${branch}" "${version}" "hide"
${module_options["module_armbian_firmware,feature"]} ${commands[2]} "${branch}" "${version}" "hide" "" "$headers"

# purge and install
for pkg in "${packages[@]}"; do
Expand All @@ -102,10 +105,12 @@ function module_armbian_firmware() {
if [[ $? == 0 ]]; then
apt_install_wrapper apt-get -y purge ${purge_pkg}
apt_install_wrapper apt-get -y --autoremove --allow-downgrades install ${pkg}
if [[ -z "${headers}" ]]; then
if $DIALOG --title " Reboot required " --yes-button "Reboot" --no-button "Cancel" --yesno \
"A reboot is required to apply the changes. Shall we reboot now?" 7 34; then
reboot
fi
fi
fi
done

Expand All @@ -117,6 +122,7 @@ function module_armbian_firmware() {
local version="$3"
local hide="$4"
local repository="$5"
local headers="$6"

# if branch is not defined, we use the one that is currently installed
[[ -z $branch ]] && local branch=$BRANCH
Expand All @@ -130,18 +136,27 @@ function module_armbian_firmware() {
"linux-dtb-${branch}-${LINUXFAMILY}"
)

# install headers only if they were previously installed
if dpkg -l | grep -E "linux-headers" >/dev/null; then
armbian_packages+=("linux-headers-${branch}-${LINUXFAMILY}")
fi

# install full firmware if it was installed previously
if dpkg -l | grep -E "armbian-firmware-full" >/dev/null; then
armbian_packages+=("armbian-firmware-full")
else
armbian_packages+=("armbian-firmware")
fi

# install headers only if they were previously installed
if dpkg -l | grep -E "linux-headers" >/dev/null; then
armbian_packages+=("linux-headers-${branch}-${LINUXFAMILY}")
fi

# only install headers if parameter headers == true
if [[ "${headers}" == true ]]; then
armbian_packages=("linux-headers-${branch}-${LINUXFAMILY}")
armbian_packages+=(
"build-essential"
"git"
)
fi

# when we select a specific version of Armbian, we need to make sure that version exists
# for each package we want to install. In case desired version does not exists, it installs
# package without specifying version. This prevent breaking install in case some
Expand Down Expand Up @@ -236,10 +251,39 @@ function module_armbian_firmware() {

# if we are not only checking status, it reinstall firmware automatically
[[ "$status" != "status" ]] && ${module_options["module_armbian_firmware,feature"]} ${commands[1]}
;;

"${commands[6]}") # installs kernel headers

# input parameters
local command=$2
local version=$3

# if version is not set, use the one from installed kernel
if [[ "${command}" == "install" ]]; then
if [[ -f /etc/armbian-release ]]; then
[[ -z "${version}" ]] && version=$(dpkg -l | grep '^ii' | grep linux-image | awk '{print $3}')
${module_options["module_armbian_firmware,feature"]} ${commands[1]} "" "${version}" "" "true"
else
# for non armbian builds
apt_install_wrapper apt-get install "linux-headers-$(uname -r | sed 's/'-$(dpkg --print-architecture)'//')"
fi
elif [[ "${command}" == "remove" ]]; then
${module_options["module_armbian_firmware,feature"]} ${commands[2]} "" "${version}" "hide" "" "true"
apt_install_wrapper apt-get -y purge ${packages[@]}
else
${module_options["module_armbian_firmware,feature"]} ${commands[2]} "" "${version}" "hide" "" "true"
if check_if_installed ${packages[@]}; then
return 0
else
return 1
fi
fi

;;

"${commands[6]}")

"${commands[7]}")
echo -e "\nUsage: ${module_options["module_armbian_firmware,feature"]} <command> <switches>"
echo -e "Commands: ${module_options["module_armbian_firmware,example"]}"
echo "Available commands:"
Expand All @@ -249,10 +293,16 @@ function module_armbian_firmware() {
echo -e "\thold \t- Mark $title packages as held back. \t switches: [status] returns true or false"
echo -e "\tunhold \t- Unset $title packages set as held back."
echo -e "\trepository\t- Selects repository and performs update. \t switches: [ stable | rolling ]"
echo -e "\theaders \t- Kernel headers management. \t switches: [ install | remove | status ]"
echo
;;
*)
${module_options["module_armbian_firmware,feature"]} ${commands[6]}
${module_options["module_armbian_firmware,feature"]} ${commands[7]}
;;
esac
}

#apt_install_wrapper=LC_ALL=C
#source /etc/armbian-release
#DIALOG=whiptail
#module_armbian_firmware "$1" "$2" "$3" "$4" "$5"

0 comments on commit 59afff1

Please sign in to comment.