Skip to content

Commit

Permalink
Add dtoverlay management
Browse files Browse the repository at this point in the history
Signed-off-by: Gunjan Gupta <[email protected]>
  • Loading branch information
viraniac authored and igorpecovnik committed Oct 6, 2024
1 parent 48c095c commit e8b4012
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/armbian-configng/config.ng.jobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,19 @@
"author": "Igor Pecovnik",
"condition": "[ -f /etc/armbian-distribution-status ] && release_upgrade rolling verify"
}
]
]
},
{
"id": "S28",
"description": "Manage device tree overlays",
"command": [
"manage_dtoverlays"
],
"status": "Active",
"doc_link": "",
"src_reference": "",
"author": "Gunjan Gupta",
"condition": "[ -n $OVERLAYDIR ] && [ -n $BOOT_SOC ]"
}
]
},
Expand Down
52 changes: 52 additions & 0 deletions lib/armbian-configng/config.ng.system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,55 @@ function adjust_motd() {
# adjust motd config
sed -i "s/^MOTD_DISABLE=.*/MOTD_DISABLE=\"$INSERT\"/g" /etc/default/armbian-motd
}

module_options+=(
["manage_dtoverlays,author"]="Gunjan Gupta"
["manage_dtoverlays,ref_link"]=""
["manage_dtoverlays,feature"]="dtoverlays"
["manage_dtoverlays,desc"]="Enable/disable device tree overlays"
["manage_dtoverlays,example"]="manage_dtoverlays"
["manage_dtoverlays,status"]="Active"
)
#
# @description Enable/disable device tree overlays
#
function manage_dtoverlays () {
# check if user agree to enter this area
local changes="false"
local overlayconf="/boot/armbianEnv.txt"
while true; do
local options=()
j=0
available_overlays=$(ls -1 ${OVERLAYDIR}/*.dtbo | sed "s#^${OVERLAYDIR}/##" | sed 's/.dtbo//g' | grep $BOOT_SOC | tr '\n' ' ')
for overlay in ${available_overlays}; do
local status="OFF"
grep '^fdt_overlays' ${overlayconf} | grep -qw ${overlay} && status=ON
options+=( "$overlay" "" "$status")
done
selection=$(whiptail --title "Manage devicetree overlays" --cancel-button "Back" \
--ok-button "Save" --checklist "\nUse <space> to toggle functions and save them.\nExit when you are done.\n " \
0 0 0 "${options[@]}" 3>&1 1>&2 2>&3)
exit_status=$?
case $exit_status in
0)
changes="true"
newoverlays=$(echo $selection | sed 's/"//g')
sed -i "s/^fdt_overlays=.*/fdt_overlays=$newoverlays/" ${overlayconf}
if ! grep -q "^fdt_overlays" ${overlayconf}; then echo "fdt_overlays=$newoverlays" >> ${overlayconf}; fi
sync
;;
1)
if [[ "$changes" == "true" ]]; then
whiptail --title " Reboot required " --yes-button "Reboot" \
--no-button "Cancel" --yesno "A reboot is required to apply the changes. Shall we reboot now?" 7 34
if [[ $? = 0 ]]; then
reboot
fi
fi
break
;;
255)
;;
esac
done
}

0 comments on commit e8b4012

Please sign in to comment.