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/23 02:32] – [Instructions] typo vgaetera | docs:guide-user:advanced:opkg_extras [2023/10/03 18:19] – [Instructions] delay for networking to become ready 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 15: | Line 13: | ||
| * 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 32: | 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 53: | 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 | EOI | ||
| } | } | ||
| - | opkg_import() { | + | opkg_uci() { |
| - | local OPKG_BAK=" | + | local OPKG_OPT=" |
| - | if grep -q -e " | + | local OPKG_OPT=" |
| - | then local OPKG_DEST=" | + | if ! uci -q get opkg > /dev/null |
| - | else local OPKG_DEST=" | + | then opkg init |
| fi | fi | ||
| - | if [ -e "${OPKG_BAK}" ] | + | uci -q batch << EOI |
| - | then sed -n -e "s/\s${OPKG_DEST}$/ | + | delete opkg.' |
| - | | opkg uci | + | set opkg.' |
| + | $(sed -r -e " | ||
| + | del_list opkg.' | ||
| + | add_list opkg.' | ||
| + | commit opkg | ||
| + | EOI | ||
| + | } | ||
| + | |||
| + | opkg_import() { | ||
| + | local OPKG_OPT=" | ||
| + | if [ -e "${OPKG_OPT}" ] | ||
| + | then sed -n -r -e "s/\s(overlay|unknown)$/\ | ||
| + | \tipkg/ | ||
| + | | opkg uci main | ||
| 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}" "${1}")" | + | 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}" "${1}")" | + | 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 "${OPKG_OPT::1}" | |
| - | opkg_export_ri() { | + | (r) OPKG_INFO="/rom${OPKG_INFO}" |
| - | local OPKG_INFO="/ | + | (w) OPKG_INFO=" |
| - | find " | + | (o) OPKG_INFO="/ |
| + | esac | ||
| + | case " | ||
| + | (r) OPKG_TYPE=" | ||
| + | (i) OPKG_TYPE="f" | ||
| + | esac | ||
| + | find " | ||
| + | -type "${OPKG_TYPE}" 2> /dev/null \ | ||
| | sed -e " | | sed -e " | ||
| } | } | ||
| - | opkg_export_wr() { | + | opkg_export_run() { |
| - | 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=" | + | sed -n -e "/^Alternatives: |
| - | find " | + | {s/^\S*\s*//;s/,\s/\n/gp}" |
| - | } | + | | sort -n -t ":" |
| - | + | | while IFS=":" | |
| - | opkg_uci() { | + | do ln -f -s "${OPKG_ALT}" "${OPKG_LINK}" |
| - | local OPKG_PROF=" | + | |
| - | local OPKG_CMD=" | + | |
| - | local OPKG_UCI | + | |
| - | if ! uci -q get opkg > /dev/null | + | |
| - | 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/^(.*)\s(.*)$/\ | + | |
| - | del_list opkg.${OPKG_PROF}.\2=\1\n | + | |
| - | add_list opkg.${OPKG_PROF}.\2=\1/") | + | |
| - | EOI | + | |
| - | for OPKG_CMD in ${OPKG_CMD} | + | |
| - | do case "${OPKG_CMD}" | + | |
| - | (proc) OPKG_UCI=" | + | |
| - | (reinstall) OPKG_UCI="--force-reinstall" | + | |
| - | (*) OPKG_UCI="auto" | + | |
| - | esac | + | |
| - | if ! uci -q get opkg.defaults."${OPKG_CMD}" | + | |
| - | then uci set opkg.defaults."${OPKG_CMD}"=" | + | |
| - | fi | + | |
| done | done | ||
| - | uci commit opkg | ||
| } | } | ||
| - | opkg_uciget() { | + | opkg_newconf() { |
| - | local OPKG_UCI="$(uci -q get opkg.defaults."${1}" | + | local OPKG_OPT=" |
| - | local OPKG_UCI=" | + | find "${OPKG_OPT}" -name " |
| - | 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 . / | ||
| - | if uci -q get fstab.rwm | + | opkg restore " |
| - | && ! grep -q -e "\s/rwm\s" | + | /var/log/opkg-restore-" |
| - | then opkg restore | + | touch / |
| - | else opkg restore | + | |
| - | fi | + | |
| - | touch / | + | |
| lock -u / | lock -u / | ||
| reboot | reboot | ||
| + | break | ||
| fi | fi | ||
| + | done | ||
| EOF | EOF | ||
| cat << " | cat << " | ||
| Line 319: | Line 295: | ||
| 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 330: | Line 309: | ||
| 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 "" |
| . ./ | . ./ | ||
| </ | </ | ||