Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
| docs:guide-user:advanced:opkg_extras [2021/09/22 02:27] – [Instructions] vgaetera | docs:guide-user:advanced:opkg_extras [2023/10/05 19:56] – [Instructions] avoid rebooting on the init profile for extroot and rootpt-resize vgaetera | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Opkg extras ====== | ====== Opkg extras ====== | ||
| - | {{section> | + | {{section> |
| ===== Introduction ===== | ===== Introduction ===== | ||
| - | * This instruction extends [[docs: | + | * This instruction extends |
| - | * Follow [[docs: | + | |
| - | * Follow [[docs: | + | |
| * Follow the [[docs: | * Follow the [[docs: | ||
| Line 11: | Line 9: | ||
| * Save, restore and roll back Opkg profiles. | * Save, restore and roll back Opkg profiles. | ||
| * Support automatic and custom profiles. | * Support automatic and custom profiles. | ||
| + | * Support RWM, overlay and extroot setup. | ||
| * Identify user-removed/ | * Identify user-removed/ | ||
| * Restore automatically after firmware upgrade. | * Restore automatically after firmware upgrade. | ||
| * Upgrade all upgradable packages. | * Upgrade all upgradable packages. | ||
| - | * Find new configurations. | + | |
| + | | ||
| ===== Implementation ===== | ===== Implementation ===== | ||
| * Wrap Opkg calls to provide a seamless invocation method. | * Wrap Opkg calls to provide a seamless invocation method. | ||
| * Rely on [[docs: | * Rely on [[docs: | ||
| - | * Identify package types with [[man> | + | * Identify package types with [[man> |
| - | * Support importing [[https:// | + | * Support importing [[https:// |
| - | * Use [[docs: | + | * Use [[docs: |
| * Utilize lockfiles with [[https:// | * Utilize lockfiles with [[https:// | ||
| * Perform [[man> | * Perform [[man> | ||
| - | * Write and read non-interactive logs with [[docs: | ||
| * Fetch the default profile to restore and roll back from UCI, unless specified manually. | * Fetch the default profile to restore and roll back from UCI, unless specified manually. | ||
| * Take precedence for remove over install to avoid package conflicts while restoring profile. | * Take precedence for remove over install to avoid package conflicts while restoring profile. | ||
| Line 31: | Line 30: | ||
| ===== Commands ===== | ===== Commands ===== | ||
| - | ^ Opkg sub-command ^ Description ^ | + | ^ Sub-command ^ Description ^ |
| - | | '' | + | | '' |
| + | | '' | ||
| | '' | | '' | ||
| - | | '' | + | | '' |
| - | | '' | + | | '' |
| | '' | | '' | ||
| - | | '' | + | | '' |
| | '' | | '' | ||
| - | | '' | + | | '' |
| | '' | | '' | ||
| - | | '' | + | | '' |
| - | | '' | + | | '' |
| - | | '' | + | |
| ===== Instructions ===== | ===== Instructions ===== | ||
| + | Copy the following text and paste it in a SSH or serial console of the device | ||
| <code bash> | <code bash> | ||
| # Configure profile | # Configure profile | ||
| Line 52: | Line 52: | ||
| opkg() { | opkg() { | ||
| local OPKG_CMD=" | local OPKG_CMD=" | ||
| - | if ! type opkg_" | + | local OPKG_UCI=" |
| - | then command opkg "${@}" | + | case "${OPKG_CMD}" |
| - | else shift | + | (init|uci|import|save|restore|rollback|upgr\ |
| - | opkg_" | + | |export|proc|reinstall|altlink|newconf) |
| - | fi | + | (*) command opkg " |
| + | esac | ||
| } | } | ||
| - | opkg_help() { | + | opkg_init() { |
| - | cat << EOI | + | uci import opkg < /dev/null |
| - | opkg [help|import|save|restore|rollback|upgr\ | + | uci -q batch << EOI |
| - | |export|proc|reinstall|newconf|uci|uciget] | + | set opkg.defaults=' |
| - | opkg upgr [au|oi] | + | set opkg.defaults.import='/ |
| - | opkg export [ai|au|ri|wr|wi|or|oi|ur|ui|pr|pi] | + | set opkg.defaults.restore='init main' |
| + | set opkg.defaults.rollback=' | ||
| + | set opkg.defaults.upgr=' | ||
| + | set opkg.defaults.export=' | ||
| + | set opkg.defaults.proc=' | ||
| + | set opkg.defaults.reinstall=' | ||
| + | set opkg.defaults.newconf='/ | ||
| + | EOI | ||
| + | } | ||
| + | |||
| + | opkg_uci() { | ||
| + | local OPKG_OPT=" | ||
| + | local OPKG_OPT=" | ||
| + | if ! uci -q get opkg > /dev/null | ||
| + | then opkg init | ||
| + | fi | ||
| + | uci -q batch << EOI | ||
| + | delete opkg.' | ||
| + | set opkg.' | ||
| + | $(sed -r -e " | ||
| + | del_list opkg.' | ||
| + | add_list opkg.' | ||
| + | commit | ||
| EOI | EOI | ||
| } | } | ||
| opkg_import() { | opkg_import() { | ||
| - | local OPKG_BAK=" | + | local OPKG_OPT=" |
| - | if grep -q -e " | + | if [ -e "${OPKG_OPT}" ] |
| - | then local OPKG_DEST=" | + | then sed -n -r -e "s/\s(overlay|unknown)$/\ |
| - | else local OPKG_DEST=" | + | \tipkg/ |
| - | fi | + | | opkg uci main |
| - | if [ -e "${OPKG_BAK}" ] | + | |
| - | then sed -n -e "s/\s${OPKG_DEST}$/ | + | |
| - | | opkg uci | + | |
| fi | fi | ||
| } | } | ||
| opkg_save() { | opkg_save() { | ||
| - | local OPKG_PROF=" | + | local OPKG_WR=" |
| + | local OPKG_WI="$(opkg export wi)" | ||
| local OPKG_UR=" | local OPKG_UR=" | ||
| local OPKG_UI=" | local OPKG_UI=" | ||
| + | if uci -q get fstab.rwm > /dev/null \ | ||
| + | && grep -q -e " | ||
| + | then { | ||
| + | sed -e " | ||
| + | sed -e " | ||
| + | } | opkg uci init | ||
| + | fi | ||
| { | { | ||
| sed -e " | sed -e " | ||
| sed -e " | sed -e " | ||
| - | } | opkg uci " | + | } | opkg uci main |
| - | rm -f " | + | rm -f " |
| - | local OPKG_PROF=" | + | |
| - | local OPKG_WR=" | + | |
| - | local OPKG_WI=" | + | |
| - | { | + | |
| - | sed -e " | + | |
| - | sed -e " | + | |
| - | } | opkg uci "${OPKG_PROF}" | + | |
| - | rm -f "${OPKG_WR}" | + | |
| } | } | ||
| opkg_restore() { | opkg_restore() { | ||
| - | local OPKG_PROF="$(opkg uciget "${OPKG_CMD}" | + | local OPKG_OPT="${1:-${OPKG_UCI}}" |
| + | local OPKG_CONF="${OPKG_OPT}" | ||
| + | for OPKG_CONF in ${OPKG_CONF} | ||
| + | do | ||
| local OPKG_AI=" | local OPKG_AI=" | ||
| local OPKG_PR=" | local OPKG_PR=" | ||
| local OPKG_PI=" | local OPKG_PI=" | ||
| - | opkg proc remove $(grep -x -f " | + | grep -x -f " |
| - | opkg proc install $(grep -v -x -f " | + | | opkg proc remove |
| + | grep -v -x -f " | ||
| + | | opkg proc install | ||
| rm -f " | rm -f " | ||
| + | done | ||
| } | } | ||
| opkg_rollback() { | opkg_rollback() { | ||
| - | local OPKG_PROF="$(opkg uciget "${OPKG_CMD}" | + | local OPKG_OPT="${1:-${OPKG_UCI}}" |
| + | local OPKG_CONF="${OPKG_OPT}" | ||
| local OPKG_UR=" | local OPKG_UR=" | ||
| local OPKG_UI=" | local OPKG_UI=" | ||
| local OPKG_PR=" | local OPKG_PR=" | ||
| local OPKG_PI=" | local OPKG_PI=" | ||
| - | opkg restore | + | if uci -q get opkg."${OPKG_CONF}" |
| - | opkg proc remove | + | then opkg restore "${OPKG_CONF}" |
| - | opkg proc install $(grep -v -x -f " | + | grep -v -x -f " |
| + | | opkg proc remove | ||
| + | grep -v -x -f " | ||
| + | | opkg proc install | ||
| + | fi | ||
| rm -f " | rm -f " | ||
| } | } | ||
| opkg_upgr() { | opkg_upgr() { | ||
| - | local OPKG_ARG=" | + | local OPKG_OPT=" |
| - | if ! type opkg_"${OPKG_CMD}_${OPKG_ARG}" | + | case "${OPKG_OPT}" |
| - | then opkg help | + | (ai|oi) |
| - | else shift | + | esac | opkg proc upgrade |
| - | opkg_" | + | |
| - | fi | + | |
| } | } | ||
| - | opkg_upgr_au() { | + | opkg_upgr_type() { |
| local OPKG_AI=" | local OPKG_AI=" | ||
| - | local OPKG_AU=" | ||
| - | opkg proc upgrade $(grep -x -f " | ||
| - | rm -f " | ||
| - | } | ||
| - | |||
| - | opkg_upgr_oi() { | ||
| local OPKG_OI=" | local OPKG_OI=" | ||
| local OPKG_AU=" | local OPKG_AU=" | ||
| - | opkg proc upgrade | + | case "${OPKG_OPT:: |
| - | rm -f " | + | (a) grep -x -f "${OPKG_AI}" " |
| + | (o) grep -x -f " | ||
| + | esac | ||
| + | rm -f " | ||
| } | } | ||
| opkg_export() { | opkg_export() { | ||
| - | local OPKG_ARG=" | + | local OPKG_OPT=" |
| - | local OPKG_EXP=" | + | local OPKG_TEMP=" |
| - | if ! type opkg_"${OPKG_CMD}_${OPKG_ARG}" | + | case "${OPKG_OPT}" in |
| - | then opkg help | + | (ai|au) opkg_"${OPKG_CMD}"_cmd ;; |
| - | else shift | + | (ri|wr|wi|or|oi) |
| - | opkg_" | + | (ur|ui) opkg_"${OPKG_CMD}"_run ;; |
| - | cat << EOI | + | (pr|pi) opkg_"${OPKG_CMD}"_uci ;; |
| - | ${OPKG_EXP} | + | esac > "${OPKG_TEMP}" |
| - | EOI | + | echo "${OPKG_TEMP}" |
| - | fi | + | |
| } | } | ||
| - | opkg_export_ai() { | + | opkg_export_cmd() { |
| - | opkg list-installed | + | local OPKG_TYPE |
| + | case " | ||
| + | (i) OPKG_TYPE=" | ||
| + | (u) OPKG_TYPE=" | ||
| + | esac | ||
| + | opkg list-" | ||
| + | | sed -e " | ||
| } | } | ||
| - | opkg_export_au() { | + | opkg_export_type() { |
| - | opkg list-upgradable | + | local OPKG_INFO="/ |
| + | local OPKG_TYPE | ||
| + | case " | ||
| + | (r) OPKG_INFO="/ | ||
| + | (w) OPKG_INFO="/ | ||
| + | (o) OPKG_INFO="/ | ||
| + | esac | ||
| + | case " | ||
| + | (r) OPKG_TYPE=" | ||
| + | (i) OPKG_TYPE=" | ||
| + | esac | ||
| + | find " | ||
| + | -type "${OPKG_TYPE}" | ||
| + | | sed -e "s/^.*\///;s/\.control$//" | ||
| } | } | ||
| - | opkg_export_ri() { | + | opkg_export_run() { |
| - | local OPKG_INFO="/ | + | |
| - | find " | + | |
| - | | sed -e " | + | |
| - | } | + | |
| - | + | ||
| - | opkg_export_wr() { | + | |
| - | local OPKG_INFO="/ | + | |
| - | find " | + | |
| - | | sed -e " | + | |
| - | } | + | |
| - | + | ||
| - | opkg_export_wi() { | + | |
| - | local OPKG_INFO="/ | + | |
| - | find " | + | |
| - | | sed -e " | + | |
| - | } | + | |
| - | + | ||
| - | opkg_export_or() { | + | |
| - | local OPKG_INFO="/ | + | |
| - | find " | + | |
| - | | sed -e " | + | |
| - | } | + | |
| - | + | ||
| - | opkg_export_oi() { | + | |
| - | local OPKG_INFO="/ | + | |
| - | find " | + | |
| - | | sed -e " | + | |
| - | } | + | |
| - | + | ||
| - | opkg_export_ur() { | + | |
| local OPKG_AI=" | local OPKG_AI=" | ||
| local OPKG_RI=" | local OPKG_RI=" | ||
| - | grep -v -x -f " | + | case " |
| + | (r) grep -v -x -f " | ||
| + | (i) grep -v -x -f " | ||
| + | esac | ||
| rm -f " | rm -f " | ||
| } | } | ||
| - | opkg_export_ui() { | + | opkg_export_uci() { |
| - | local OPKG_AI="$(opkg export ai)" | + | local OPKG_TYPE |
| - | local OPKG_RI=" | + | case "${OPKG_OPT: |
| - | grep -v -x -f " | + | (r) OPKG_TYPE="rpkg" |
| - | rm -f "${OPKG_AI}" | + | (i) OPKG_TYPE="ipkg" |
| - | } | + | esac |
| - | + | uci -q get opkg." | |
| - | opkg_export_pr() { | + | | sed -e " |
| - | uci -q get opkg." | + | |
| - | } | + | |
| - | + | ||
| - | opkg_export_pi() { | + | |
| - | uci -q get opkg."${OPKG_PROF}".ipkg | sed -e " | + | |
| } | } | ||
| opkg_proc() { | opkg_proc() { | ||
| - | local OPKG_OPT=" | + | local OPKG_OPT=" |
| local OPKG_CMD=" | local OPKG_CMD=" | ||
| local OPKG_PKG | local OPKG_PKG | ||
| - | shift | + | while read -r OPKG_PKG |
| - | for OPKG_PKG | + | do opkg " |
| - | do | + | |
| - | if [ " | + | |
| - | then / | + | |
| - | fi | + | |
| - | opkg " | + | |
| - | if [ " | + | |
| - | then hash -r | + | |
| - | fi | + | |
| done | done | ||
| } | } | ||
| opkg_reinstall() { | opkg_reinstall() { | ||
| - | local OPKG_OPT=" | + | local OPKG_OPT=" |
| opkg install " | opkg install " | ||
| } | } | ||
| - | opkg_newconf() { | + | opkg_altlink() { |
| - | local OPKG_PATH="${1:-/etc}" | + | sed -n -e "/ |
| - | find "${OPKG_PATH}" | + | {s/ |
| + | | sort -n -t ":" | ||
| + | | while IFS=":" | ||
| + | do ln -f -s "${OPKG_ALT}" "${OPKG_LINK}" | ||
| + | done | ||
| } | } | ||
| - | opkg_uci() { | + | opkg_newconf() { |
| - | local OPKG_PROF=" | + | local OPKG_OPT="${1:-${OPKG_UCI}}" |
| - | if ! uci -q show opkg > /dev/null | + | find "${OPKG_OPT}" -name "*-opkg" |
| - | then uci import opkg < /dev/null | + | |
| - | fi | + | |
| - | uci -q batch << EOI | + | |
| - | delete opkg.${OPKG_PROF} | + | |
| - | set opkg.defaults=opkg | + | |
| - | set opkg.custom=opkg | + | |
| - | set opkg.${OPKG_PROF}=opkg | + | |
| - | $(sed -r -e "s/ | + | |
| - | add_list opkg.${OPKG_PROF}.\2=\1/" | + | |
| - | commit opkg | + | |
| - | EOI | + | |
| - | } | + | |
| - | + | ||
| - | opkg_uciget() { | + | |
| - | local OPKG_UCI=" | + | |
| - | local OPKG_UCI=" | + | |
| - | local OPKG_UCI=" | + | |
| - | cat << EOI | + | |
| - | ${OPKG_UCI} | + | |
| - | EOI | + | |
| } | } | ||
| EOF | EOF | ||
| . / | . / | ||
| - | # Restore packages automatically | + | # Configure hotplug |
| mkdir -p / | mkdir -p / | ||
| cat << " | cat << " | ||
| - | if [ ! -e / | + | OPKG_CONF=" |
| + | for OPKG_CONF in ${OPKG_CONF} | ||
| + | do if [ ! -e / | ||
| && lock -n / | && lock -n / | ||
| + | && sleep 10 \ | ||
| && opkg update | && opkg update | ||
| - | then | + | then . / |
| - | . / | + | opkg restore " |
| - | if uci -q get opkg.rwm &> /dev/null | + | /var/log/opkg-restore-" |
| - | then opkg restore | + | touch / |
| - | else opkg restore | + | |
| - | fi | + | |
| - | touch / | + | |
| lock -u / | lock -u / | ||
| - | reboot | + | case " |
| + | (init) ;; | ||
| + | (*) reboot | ||
| + | esac | ||
| + | break | ||
| fi | fi | ||
| + | done | ||
| EOF | EOF | ||
| cat << " | cat << " | ||
| Line 305: | Line 298: | ||
| opkg rollback | opkg rollback | ||
| - | # Set up a custom | + | # Set up Opkg profiles |
| - | uci set opkg.defaults.restore=" | + | uci set opkg.defaults.restore=" |
| - | uci -q delete | + | uci set opkg.init=" |
| + | uci add_list opkg.init.ipkg=" | ||
| + | uci add_list opkg.init.ipkg=" | ||
| + | uci add_list opkg.init.ipkg=" | ||
| + | uci set opkg.custom=" | ||
| uci add_list opkg.custom.rpkg=" | uci add_list opkg.custom.rpkg=" | ||
| uci add_list opkg.custom.rpkg=" | uci add_list opkg.custom.rpkg=" | ||
| - | uci -q delete opkg.custom.ipkg | ||
| uci add_list opkg.custom.ipkg=" | uci add_list opkg.custom.ipkg=" | ||
| uci add_list opkg.custom.ipkg=" | uci add_list opkg.custom.ipkg=" | ||
| Line 316: | Line 312: | ||
| uci commit opkg | uci commit opkg | ||
| - | # Check hotplug | + | # Check Opkg log |
| - | logread | + | tail -f / |
| # Upgrade packages | # Upgrade packages | ||
| opkg update | opkg update | ||
| opkg upgr | opkg upgr | ||
| + | |||
| + | # Maintenance | ||
| + | opkg altlink | ||
| + | opkg newconf | ||
| </ | </ | ||
| ===== Automated ===== | ===== Automated ===== | ||
| <code bash> | <code bash> | ||
| - | uclient-fetch -O opkg-extras.sh " | + | wget -U "" |
| . ./ | . ./ | ||
| </ | </ | ||