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/26 05:16] – major code refactoring 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 54: | Line 54: | ||
| local OPKG_UCI=" | local OPKG_UCI=" | ||
| case " | case " | ||
| - | (init|uci|import|save|restore|rollback\ | + | (init|uci|import|save|restore|rollback|upgr\ |
| - | |upgr|export|newconf|proc|reinstall) opkg_" | + | |export|proc|reinstall|altlink|newconf) opkg_" |
| (*) command opkg " | (*) command opkg " | ||
| esac | esac | ||
| Line 63: | Line 63: | ||
| uci import opkg < /dev/null | uci import opkg < /dev/null | ||
| uci -q batch << EOI | uci -q batch << EOI | ||
| - | set opkg.defaults=opkg | + | set opkg.defaults='opkg' |
| - | set opkg.defaults.import=/ | + | set opkg.defaults.import='/ |
| - | set opkg.defaults.save=auto | + | set opkg.defaults.restore='init main' |
| - | set opkg.defaults.restore=auto | + | set opkg.defaults.rollback=' |
| - | set opkg.defaults.rollback=auto | + | set opkg.defaults.upgr='ai' |
| - | set opkg.defaults.upgr=ai | + | set opkg.defaults.export='ai' |
| - | set opkg.defaults.export=ai | + | set opkg.defaults.proc='--force-depends' |
| - | set opkg.defaults.proc=--force-depends | + | set opkg.defaults.reinstall='--force-reinstall' |
| - | set opkg.defaults.reinstall=--force-reinstall | + | set opkg.defaults.newconf='/etc' |
| - | set opkg.defaults.newconf=/ | + | |
| EOI | EOI | ||
| } | } | ||
| opkg_uci() { | opkg_uci() { | ||
| - | local OPKG_OPT=" | + | local OPKG_OPT=" |
| + | local OPKG_OPT=" | ||
| if ! uci -q get opkg > /dev/null | if ! uci -q get opkg > /dev/null | ||
| then opkg init | then opkg init | ||
| fi | fi | ||
| uci -q batch << EOI | uci -q batch << EOI | ||
| - | delete opkg.${OPKG_OPT} | + | delete opkg.'${OPKG_OPT}' |
| - | set opkg.${OPKG_OPT}=opkg | + | set opkg.'${OPKG_OPT}'='opkg' |
| $(sed -r -e " | $(sed -r -e " | ||
| - | del_list opkg.${OPKG_OPT}.\2=\1\n\ | + | del_list opkg.'${OPKG_OPT}'.'\2'='\1'\n\ |
| - | add_list opkg.${OPKG_OPT}.\2=\1/" | + | add_list opkg.'${OPKG_OPT}'.'\2'='\1'/") |
| commit opkg | commit opkg | ||
| EOI | EOI | ||
| Line 93: | Line 93: | ||
| opkg_import() { | opkg_import() { | ||
| local OPKG_OPT=" | local OPKG_OPT=" | ||
| - | local OPKG_TYPE | ||
| - | if grep -q -e " | ||
| - | then OPKG_TYPE=" | ||
| - | else OPKG_TYPE=" | ||
| - | fi | ||
| if [ -e " | if [ -e " | ||
| - | then sed -n -e "s/\s${OPKG_TYPE}$/ | + | then sed -n -r -e "s/\s(overlay|unknown)$/\ |
| - | | opkg uci auto | + | \tipkg/ |
| + | | opkg uci main | ||
| fi | fi | ||
| } | } | ||
| opkg_save() { | opkg_save() { | ||
| - | local OPKG_OPT=" | ||
| local OPKG_WR=" | local OPKG_WR=" | ||
| local OPKG_WI=" | local OPKG_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 " | ||
| sed -e " | sed -e " | ||
| - | } | opkg uci rwm | + | } | opkg uci init |
| + | fi | ||
| { | { | ||
| sed -e " | sed -e " | ||
| sed -e " | sed -e " | ||
| - | } | opkg uci " | + | } | opkg uci main |
| rm -f " | rm -f " | ||
| } | } | ||
| Line 123: | Line 121: | ||
| opkg_restore() { | opkg_restore() { | ||
| local OPKG_OPT=" | local OPKG_OPT=" | ||
| - | local OPKG_CFG=" | + | local OPKG_CONF=" |
| + | for OPKG_CONF in ${OPKG_CONF} | ||
| + | do | ||
| local OPKG_AI=" | local OPKG_AI=" | ||
| local OPKG_PR=" | local OPKG_PR=" | ||
| Line 132: | 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_CFG=" | + | 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=" | ||
| - | if uci -q get opkg > /dev/null | + | if uci -q get opkg." |
| - | then opkg restore "${OPKG_OPT}" | + | then opkg restore "${OPKG_CONF}" |
| grep -v -x -f " | grep -v -x -f " | ||
| | opkg proc remove | | opkg proc remove | ||
| Line 171: | Line 172: | ||
| opkg_export() { | opkg_export() { | ||
| local OPKG_OPT=" | local OPKG_OPT=" | ||
| - | local OPKG_EXP=" | + | local OPKG_TEMP=" |
| case " | case " | ||
| (ai|au) opkg_" | (ai|au) opkg_" | ||
| Line 177: | Line 178: | ||
| (ur|ui) opkg_" | (ur|ui) opkg_" | ||
| (pr|pi) opkg_" | (pr|pi) opkg_" | ||
| - | esac > "${OPKG_EXP}" | + | esac > "${OPKG_TEMP}" |
| - | echo "${OPKG_EXP}" | + | echo "${OPKG_TEMP}" |
| } | } | ||
| Line 224: | Line 225: | ||
| (i) OPKG_TYPE=" | (i) OPKG_TYPE=" | ||
| esac | esac | ||
| - | uci -q get opkg." | + | uci -q get opkg." |
| | sed -e " | | sed -e " | ||
| } | } | ||
| Line 240: | Line 241: | ||
| local OPKG_OPT=" | local OPKG_OPT=" | ||
| opkg install " | opkg install " | ||
| + | } | ||
| + | |||
| + | opkg_altlink() { | ||
| + | sed -n -e "/ | ||
| + | {s/ | ||
| + | | sort -n -t ":" | ||
| + | | while IFS=":" | ||
| + | do ln -f -s " | ||
| + | done | ||
| } | } | ||
| Line 249: | Line 259: | ||
| . / | . / | ||
| - | # 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 283: | 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 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 set opkg.custom=" | ||
| uci add_list opkg.custom.rpkg=" | uci add_list opkg.custom.rpkg=" | ||
| Line 293: | 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 "" |
| . ./ | . ./ | ||
| </ | </ | ||