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 19:40] – [Commands] 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 ^ |
| - | | '' | + | | '' |
| + | | '' | ||
| | '' | | '' | ||
| - | | '' | + | | '' |
| - | | '' | + | | '' |
| | '' | | '' | ||
| | '' | | '' | ||
| Line 42: | Line 41: | ||
| | '' | | '' | ||
| | '' | | '' | ||
| - | | '' | + | | '' |
| - | | '' | + | | '' |
| ===== 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=" | ||
| - | local OPKG_ARG="$(opkg uci get " | + | local OPKG_UCI=" |
| - | local OPKG_OPT=" | + | case " |
| - | if ! type opkg_" | + | (init|uci|import|save|restore|rollback|upgr\ |
| - | then command opkg " | + | |export|proc|reinstall|altlink|newconf) opkg_" |
| - | else shift | + | (*) command opkg " |
| - | opkg_" | + | esac |
| - | fi | + | |
| } | } | ||
| - | 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] | + | set opkg.defaults=' |
| - | opkg upgr [ai|oi] | + | set opkg.defaults.import='/ |
| - | opkg export | + | set opkg.defaults.restore='init main' |
| - | opkg uci [get|set|init] | + | set opkg.defaults.rollback=' |
| + | set opkg.defaults.upgr='ai' | ||
| + | set opkg.defaults.export='ai' | ||
| + | set opkg.defaults.proc=' | ||
| + | set opkg.defaults.reinstall=' | ||
| + | set opkg.defaults.newconf='/ | ||
| EOI | EOI | ||
| } | } | ||
| - | opkg_import() { | + | opkg_uci() { |
| - | local OPKG_TYPE | + | local OPKG_OPT="${1:-${OPKG_UCI}}" |
| - | if grep -q -e "^overlayfs:" | + | local OPKG_OPT="${OPKG_OPT: |
| - | then OPKG_TYPE="overlay" | + | if ! uci -q get opkg > /dev/null |
| - | else OPKG_TYPE=" | + | then opkg init |
| fi | fi | ||
| - | if [ -e "${OPKG_ARG}" ] | + | uci -q batch << EOI |
| - | then sed -n -e "s/\s${OPKG_TYPE}$/ | + | delete opkg.' |
| - | | opkg uci set auto | + | 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 | ||
| } | } | ||
| Line 88: | Line 105: | ||
| 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 " | ||
| sed -e " | sed -e " | ||
| - | } | opkg uci set rwm | + | } | opkg uci init |
| + | fi | ||
| { | { | ||
| sed -e " | sed -e " | ||
| sed -e " | sed -e " | ||
| - | } | opkg uci set " | + | } | opkg uci main |
| rm -f " | rm -f " | ||
| } | } | ||
| opkg_restore() { | opkg_restore() { | ||
| - | local OPKG_OPT=" | + | local OPKG_OPT=" |
| + | local OPKG_CONF=" | ||
| + | for OPKG_CONF in ${OPKG_CONF} | ||
| + | do | ||
| local OPKG_AI=" | local OPKG_AI=" | ||
| local OPKG_PR=" | local OPKG_PR=" | ||
| Line 109: | Line 132: | ||
| | opkg proc install | | opkg proc install | ||
| rm -f " | rm -f " | ||
| + | done | ||
| } | } | ||
| opkg_rollback() { | opkg_rollback() { | ||
| - | local OPKG_OPT=" | + | local OPKG_OPT=" |
| + | local OPKG_CONF=" | ||
| 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 "${OPKG_ARG}" | + | if uci -q get opkg." |
| + | then opkg restore "${OPKG_CONF}" | ||
| grep -v -x -f " | grep -v -x -f " | ||
| | opkg proc remove | | opkg proc remove | ||
| grep -v -x -f " | grep -v -x -f " | ||
| | opkg proc install | | opkg proc install | ||
| + | fi | ||
| rm -f " | rm -f " | ||
| } | } | ||
| opkg_upgr() { | opkg_upgr() { | ||
| - | case "${OPKG_ARG}" in | + | local OPKG_OPT=" |
| - | (ai|oi) opkg_" | + | case "${OPKG_OPT}" in |
| - | esac | + | (ai|oi) opkg_" |
| + | esac | opkg proc upgrade | ||
| } | } | ||
| - | opkg_upgr_path() { | + | opkg_upgr_type() { |
| local OPKG_AI=" | local OPKG_AI=" | ||
| local OPKG_OI=" | local OPKG_OI=" | ||
| local OPKG_AU=" | local OPKG_AU=" | ||
| - | case "${OPKG_ARG::1}" in | + | case "${OPKG_OPT::1}" in |
| - | (a) grep -x -f " | + | (a) grep -x -f " |
| - | | opkg proc upgrade | + | (o) grep -x -f " |
| - | (o) grep -x -f " | + | |
| - | | opkg proc upgrade | + | |
| esac | esac | ||
| rm -f " | rm -f " | ||
| Line 145: | Line 171: | ||
| opkg_export() { | opkg_export() { | ||
| - | local OPKG_EXP=" | + | local OPKG_OPT=" |
| - | case "${OPKG_ARG}" in | + | local OPKG_TEMP=" |
| + | case "${OPKG_OPT}" in | ||
| (ai|au) opkg_" | (ai|au) opkg_" | ||
| - | (ri|wr|wi|or|oi) opkg_" | + | (ri|wr|wi|or|oi) opkg_" |
| (ur|ui) opkg_" | (ur|ui) opkg_" | ||
| (pr|pi) opkg_" | (pr|pi) opkg_" | ||
| - | esac > "${OPKG_EXP}" | + | esac > "${OPKG_TEMP}" |
| - | cat << EOI | + | echo "${OPKG_TEMP}" |
| - | ${OPKG_EXP} | + | |
| - | EOI | + | |
| } | } | ||
| opkg_export_cmd() { | opkg_export_cmd() { | ||
| - | case "${OPKG_ARG:1}" in | + | local OPKG_TYPE |
| + | case "${OPKG_OPT:1}" in | ||
| (i) OPKG_TYPE=" | (i) OPKG_TYPE=" | ||
| (u) OPKG_TYPE=" | (u) OPKG_TYPE=" | ||
| Line 166: | Line 192: | ||
| } | } | ||
| - | opkg_export_path() { | + | opkg_export_type() { |
| local OPKG_INFO="/ | local OPKG_INFO="/ | ||
| local OPKG_TYPE | local OPKG_TYPE | ||
| - | case "${OPKG_ARG::1}" in | + | case "${OPKG_OPT::1}" in |
| (r) OPKG_INFO="/ | (r) OPKG_INFO="/ | ||
| (w) OPKG_INFO="/ | (w) OPKG_INFO="/ | ||
| (o) OPKG_INFO="/ | (o) OPKG_INFO="/ | ||
| esac | esac | ||
| - | case "${OPKG_ARG:1}" in | + | case "${OPKG_OPT:1}" in |
| (r) OPKG_TYPE=" | (r) OPKG_TYPE=" | ||
| (i) OPKG_TYPE=" | (i) OPKG_TYPE=" | ||
| Line 186: | Line 212: | ||
| local OPKG_AI=" | local OPKG_AI=" | ||
| local OPKG_RI=" | local OPKG_RI=" | ||
| - | case "${OPKG_ARG:1}" in | + | case "${OPKG_OPT:1}" in |
| (r) grep -v -x -f " | (r) grep -v -x -f " | ||
| (i) grep -v -x -f " | (i) grep -v -x -f " | ||
| Line 195: | Line 221: | ||
| opkg_export_uci() { | opkg_export_uci() { | ||
| local OPKG_TYPE | local OPKG_TYPE | ||
| - | case "${OPKG_ARG:1}" in | + | case "${OPKG_OPT:1}" in |
| (r) OPKG_TYPE=" | (r) OPKG_TYPE=" | ||
| (i) OPKG_TYPE=" | (i) OPKG_TYPE=" | ||
| esac | esac | ||
| - | uci -q get opkg." | + | uci -q get opkg." |
| | sed -e " | | sed -e " | ||
| } | } | ||
| opkg_proc() { | opkg_proc() { | ||
| + | local OPKG_OPT=" | ||
| local OPKG_CMD=" | local OPKG_CMD=" | ||
| local OPKG_PKG | local OPKG_PKG | ||
| while read -r OPKG_PKG | while read -r OPKG_PKG | ||
| - | do | + | do opkg " |
| - | if [ " | + | |
| - | && [ " | + | |
| - | then / | + | |
| - | fi | + | |
| - | opkg " | + | |
| - | if [ " | + | |
| - | then hash -r | + | |
| - | fi | + | |
| done | done | ||
| } | } | ||
| opkg_reinstall() { | opkg_reinstall() { | ||
| + | local OPKG_OPT=" | ||
| opkg install " | opkg install " | ||
| } | } | ||
| - | opkg_newconf() { | + | opkg_altlink() { |
| - | find "${OPKG_ARG}" -name "*-opkg" | + | sed -n -e "/ |
| + | {s/ | ||
| + | | sort -n -t ":" \ | ||
| + | | while IFS=":" | ||
| + | do ln -f -s "${OPKG_ALT}" | ||
| + | done | ||
| } | } | ||
| - | opkg_uci() { | + | opkg_newconf() { |
| - | case " | + | local OPKG_OPT=" |
| - | (get|set|init) opkg_" | + | find "${OPKG_OPT}" |
| - | esac | + | |
| - | } | + | |
| - | + | ||
| - | opkg_uci_get() { | + | |
| - | local OPKG_UCI="$(uci -q get opkg.defaults."${1}" | + | |
| - | local OPKG_UCI=" | + | |
| - | cat << EOI | + | |
| - | ${OPKG_UCI} | + | |
| - | EOI | + | |
| - | } | + | |
| - | + | ||
| - | opkg_uci_set() { | + | |
| - | opkg uci init | + | |
| - | uci -q batch << EOI | + | |
| - | delete opkg.${OPKG_ARG} | + | |
| - | set opkg.${OPKG_ARG}=opkg | + | |
| - | $(sed -r -e "s/^(.*)\s(.*)$/ | + | |
| - | del_list | + | |
| - | add_list opkg.${OPKG_ARG}.\2=\1/ | + | |
| - | commit opkg | + | |
| - | EOI | + | |
| - | } | + | |
| - | + | ||
| - | opkg_uci_init() { | + | |
| - | if ! uci -q get opkg > /dev/null | + | |
| - | then uci -q batch << EOI | + | |
| - | import opkg | + | |
| - | set opkg.defaults=opkg | + | |
| - | set opkg.defaults.import=/ | + | |
| - | set opkg.defaults.save=auto | + | |
| - | set opkg.defaults.restore=auto | + | |
| - | set opkg.defaults.rollback=auto | + | |
| - | set opkg.defaults.upgr=ai | + | |
| - | set opkg.defaults.export=ai | + | |
| - | set opkg.defaults.proc=--force-depends | + | |
| - | set opkg.defaults.reinstall=--force-reinstall | + | |
| - | set opkg.defaults.newconf=/ | + | |
| - | set opkg.custom=opkg | + | |
| - | EOI | + | |
| - | fi | + | |
| } | } | ||
| 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 308: | 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 319: | 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 "" |
| . ./ | . ./ | ||
| </ | </ | ||