007revad / Synology_app_mover

Easily move Synology packages from 1 volume to another volume
MIT License
391 stars 26 forks source link

[Bug/Improvement] Incompatibility with Entware #125

Closed OrpheeGT closed 1 month ago

OrpheeGT commented 1 month ago

Hello,

I'm using entware on a daily basis, and it seems to be imcompatible with your script

it does not handle "sleep 0.3" and seems to manage filesystem size by %...

https://github.com/Entware/Entware/wiki/Install-on-Synology-NAS

I had to disable/unload entware from /etc/profile to run the script correctly.

007revad commented 1 month ago

What do these commands return?

type bash
bash --version
OrpheeGT commented 1 month ago
root@NAS:~# type bash
bash is /bin/bash
root@NAS:~# bash --version
GNU bash, version 4.4.23(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
root@NAS:~# whereis bash
bash: /usr/bin/bash
root@NAS:~# env
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
USER=root
PAGER=more
PWD=/root
HOME=/root
TMP=/opt/tmp
PGDATA=/var/services/pgsql
SHELL=/bin/ash
TERM=xterm
SHLVL=1
TEMP=/opt/tmp
TERMINFO=/opt/share/terminfo
LOGNAME=root
PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
_=/opt/bin/env
root@NAS:~#
root@NAS:~# whereis sleep
sleep: /opt/bin/sleep /usr/bin/sleep
root@NAS:~# sleep 0.3
sleep: invalid number '0.3'
root@NAS:~# sort --check=quiet --version-sort
sort: unrecognized option '--check=quiet'
BusyBox v1.36.1 (2024-02-22 20:34:43 UTC) multi-call binary.

Usage: sort [-nru] [FILE]...

Sort lines of text

        -n      Sort numbers
        -r      Reverse sort order
        -s      Stable (don't sort ties alphabetically)
        -u      Suppress duplicate lines
        -z      NUL terminated input and output
root@NAS:~# whereis sort
sort: /opt/bin/sort /usr/bin/sort
root@NAS:~# ll /opt/bin/sort
lrwxrwxrwx    1 root     root            16 May 15 17:30 /opt/bin/sort -> /opt/bin/busybox
root@NAS:~# ll /opt/bin/sleep 
lrwxrwxrwx    1 root     root            16 May 15 17:30 /opt/bin/sleep -> /opt/bin/busybox

Busybox...

root@NAS:~# /opt/bin/busybox
BusyBox v1.36.1 (2024-02-22 20:34:43 UTC) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
Licensed under GPLv2. See source distribution for detailed
copyright notices.

Usage: busybox [function [arguments]...]
   or: busybox --list
   or: function [arguments]...

        BusyBox is a multi-call binary that combines many common Unix
        utilities into a single executable.  Most people will create a
        link to busybox for each function they wish to use and BusyBox
        will act like whatever it was invoked as.

Currently defined functions:
        [, [[, addgroup, adduser, ar, arping, ash, awk, base64, basename, blkid, blockdev, brctl, bunzip2, bzcat, cat, chgrp, chmod, chown, chroot, clear, cmp, cp, crond, crontab, cryptpw, cut, date, dd,
        delgroup, deluser, devmem, df, diff, dirname, dmesg, dos2unix, du, echo, egrep, env, expr, false, fgrep, find, free, fsync, getty, grep, gunzip, gzip, halt, head, hexdump, hostid, hostname, id,
        ifconfig, insmod, iostat, ip, ipaddr, ipcalc, iplink, ipneigh, iproute, iprule, iptunnel, kill, killall, klogd, less, ln, lock, logger, login, losetup, ls, lsmod, lsusb, md5sum, mkdir, mkfifo,
        mknod, mkswap, mktemp, more, mount, mv, nc, netmsg, netstat, nice, nslookup, ntpd, od, passwd, patch, pgrep, pidof, ping, ping6, pivot_root, poweroff, printf, ps, pwd, readlink, reboot, renice,
        reset, rev, rm, rmdir, rmmod, route, run-parts, sed, seq, setconsole, setserial, sh, sha1sum, sha256sum, sha512sum, sleep, sort, start-stop-daemon, stat, strings, stty, su, swapoff, swapon,
        switch_root, sync, sysctl, syslogd, tail, tar, tee, telnet, telnetd, test, time, top, touch, tr, traceroute, true, tty, udhcpc, umount, uname, uniq, unix2dos, unlink, unlzma, unxz, unzip, uptime,
        usleep, vconfig, vi, wc, wget, which, xargs, xz, xzcat, yes, zcat

An easy workaround would be to force /usr/bin/

Or remove /opt/bin from $PATH at script launch...

same applies for printf

# whereis printf
printf: /opt/bin/printf /usr/bin/printf
root@NAS:~# ll /opt/bin/printf
lrwxrwxrwx    1 root     root            16 May 15 17:30 /opt/bin/printf -> /opt/bin/busybox
# echo $PATH
/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin

Edit : An idea :

root@NAS:~# echo $PATH
/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
root@NAS:~# PATH=$(echo $PATH | sed -e 's/\/opt\/bin:\/opt\/sbin://')
root@NAS:~# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin

Or maybe think larger and check if any of binary used is linked to busybox... someone else could use another solution than Entware and using busybox...

root@NAS:/opt/bin# ll |grep busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 [ -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 [[ -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 ar -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 awk -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 base64 -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 basename -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 bunzip2 -> /opt/bin/busybox
-rwsr-xr-x    1 root     root        545616 Feb 12  2024 busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 bzcat -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 cat -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 chgrp -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 chmod -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 chown -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 clear -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 cmp -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 cp -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 crontab -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 cryptpw -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 cut -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 date -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 dd -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 df -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 diff -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 dirname -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 dmesg -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 dos2unix -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 du -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 echo -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 env -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 expr -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 false -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 free -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 fsync -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 gunzip -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 gzip -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 head -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 hexdump -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 hostid -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 hostname -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 id -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 iostat -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 ipcalc -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 kill -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 killall -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 ln -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 lock -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 logger -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 login -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 ls -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 md5sum -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 mkdir -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 mkfifo -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 mknod -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 more -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 mount -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 mv -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 netmsg -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 nice -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 nslookup -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 passwd -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 patch -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 pgrep -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 pidof -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 ping -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 ping6 -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 printf -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 pwd -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 readlink -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 renice -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 reset -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 rev -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 rm -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 rmdir -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 run-parts -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 sed -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 seq -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 setserial -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 sha1sum -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 sha256sum -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 sha512sum -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 sleep -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 sort -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 strings -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 stty -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 su -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 sync -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 tail -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 tar -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 tee -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 telnet -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 test -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 time -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 top -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 touch -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 tr -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 traceroute -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 true -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 tty -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 umount -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 uname -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 uniq -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 unix2dos -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 unlink -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 unlzma -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 unxz -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 uptime -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 usleep -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 vi -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 wc -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 which -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 xz -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 xzcat -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 yes -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 zcat -> /opt/bin/busybox
root@NAS:/opt/bin#
root@NAS:/opt/sbin# ll |grep busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 addgroup -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 adduser -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 arping -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 blkid -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 blockdev -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 brctl -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 chroot -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 crond -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 delgroup -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 deluser -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 devmem -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 getty -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 halt -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 ipaddr -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 iplink -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 ipneigh -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 iproute -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 iprule -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 iptunnel -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 klogd -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 losetup -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 mkswap -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 ntpd -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 pivot_root -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 poweroff -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 reboot -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 setconsole -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 start-stop-daemon -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 swapoff -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 swapon -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 switch_root -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 syslogd -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 telnetd -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 udhcpc -> /opt/bin/busybox
lrwxrwxrwx    1 root     root            16 May 15 17:30 vconfig -> /opt/bin/busybox
007revad commented 1 month ago

Are you using v.3.160 or v4.0.71 of the script?

Did the script stop after those errors? Or did it finish and they were the only errors?

Did you use Entware to install ash or dash? EDIT I just realised you installed busybox.

I can't test my scripts with a #!/bin/ash shebang using shellcheck because when you set the shebang to #!/bin/ash it checks the script as if it was dash. I did check it with #!/bin/ash and #!/bin/sh

The only time I use Entware is to install bash on my Asustor NAS because it's OS uses busybox and it's /bin/bash is a symlink to to /bin/ash and ash is a symlink to /bin/busybox... and busybox caused too many errors when I was making an Asustor version of my Synology Plex Backup script, like:

${var,,}         variable expansion causes an error
|&           piping stdout and stderr causes an error
2> >  and  >&2       redirection causes an error
[[ "$var" != "a b" ]]    causes an error

I used to use the #!/bin/bash shebang but it caused issues for edge cases like yours, so I changed it to #!/sur/bin/env bash. In your case changing the script's shebang to #!/bin/bash should solve your issue.

I'll change sleep to /usr/bin/sleep du to /usr/bin/du.

Or I could add: export PATH=$(echo $PATH | sed -e 's/\/opt\/bin:\/opt\/sbin://') near the top of the script.

OrpheeGT commented 1 month ago

I was using v4.0.71

to be honest with the flood of errors about sleep, and sort in error too, I was not very confident about move consistancy.

But in the end it seemed it moved values anyway.

It seems busybox is a part of Entware default installation...

I tried to uninstall it, but it fails :

root@NAS:~# opkg remove busybox
Refusing to remove essential package busybox.
        Removing an essential package may lead to an unusable system, but if
        you enjoy that kind of pain, you can force opkg to proceed against
        its will with the option: --force-removal-of-essential-packages
No packages removed.

I may try to force remove with -f ...

if you chose /usr/bin/ there is also "sort" to address. Maybe the export part would be the best.

With busybox, everytime the script start, it checks for new version...

Apart from that, I don't think it is related, but I had an issue with FS type check for container manager...

Source and target were both ext4, and script always cancelled saying the source and target were not the same something like "source ext4 is not the same as target ext4" I removed this check from the script to be able to make the move. image

Edit :

Removed Busybox

root@NAS:~# opkg remove busybox --force-removal-of-essential-packages
Removing essential package busybox under your coercion.
        If your system breaks, you get to keep both pieces
Removing package busybox from root...
root@NAS:~#

But I guess some others could also encounter the issue... I would go for removing /opt/ from PATH if I had to choose.

007revad commented 1 month ago

This should be solved in v4.0.72 https://github.com/007revad/Synology_app_mover/releases