sixfab / Sixfab_RPi_3G-4G-LTE_Base_Shield

It is repository of quickstart instructions for Sixfab Raspberry Pi 3G/4G/LTE Base Shield
MIT License
33 stars 34 forks source link

qmi_install.sh fails to extract quectel-CM.zip #6

Open rmlamarche opened 3 years ago

rmlamarche commented 3 years ago

Because of the fact that this script needs to be run with sudo and runs whoami in a few places under the hood, it fails to unzip quectel-CM.zip (because sudo whoami returns root, but the default home directory on raspi os is /home/pi).

It seems this recent commit is where this was introduced: https://github.com/sixfab/Sixfab_RPi_3G-4G-LTE_Base_Shield/commit/a669005d480605e2cae75e5d384d0f30f929f331

I would suggest that the /home/$(whoami)/files/... bit be removed altogether, and that the script just uses the current working directory (something like ./files/ or ./quectel-cm-files/ etc.). I'm happy to try to contribute on this, but I don't have a raspi handy for a few days so it will be tricky to test.

Here is a sample output:

pi@raspberrypi:~ $ sudo ./qmi_install.sh
Clean Old Files
Change directory to /home/root
./qmi_install.sh: 24: cd: can't cd to /home/root
Downloading source files
--2020-11-20 16:54:37--  https://github.com/sixfab/Sixfab_RPi_3G-4G-LTE_Base_Shield/raw/master/tutorials/QMI_tutorial/src/quectel-CM.zip
Resolving github.com (github.com)... 140.82.114.4
Connecting to github.com (github.com)|140.82.114.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/sixfab/Sixfab_RPi_3G-4G-LTE_Base_Shield/master/tutorials/QMI_tutorial/src/quectel-CM.zip [following]
--2020-11-20 16:54:38--  https://raw.githubusercontent.com/sixfab/Sixfab_RPi_3G-4G-LTE_Base_Shield/master/tutorials/QMI_tutorial/src/quectel-CM.zip
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 199.232.64.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|199.232.64.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 148627 (145K) [application/zip]
Saving to: ‘quectel-CM.zip’

quectel-CM.zip                            100%[==================================================================================>] 145.14K  --.-KB/s    in 0.1s

2020-11-20 16:54:38 (1.40 MB/s) - ‘quectel-CM.zip’ saved [148627/148627]

Archive:  quectel-CM.zip
checkdir:  cannot create extraction directory: /home/root/files
           No such file or directory
Checking Kernel
5.4.65+ based kernel contains driver
Installing udhcpc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  udhcpc
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 24.3 kB of archives.
After this operation, 39.9 kB of additional disk space will be used.
Get:1 http://raspbian.mirror.constant.com/raspbian buster/main armhf udhcpc armhf 1:1.30.1-4 [24.3 kB]
Fetched 24.3 kB in 1s (25.0 kB/s)
Selecting previously unselected package udhcpc.
(Reading database ... 55377 files and directories currently installed.)
Preparing to unpack .../udhcpc_1%3a1.30.1-4_armhf.deb ...
Unpacking udhcpc (1:1.30.1-4) ...
Setting up udhcpc (1:1.30.1-4) ...
Processing triggers for man-db (2.8.5-2) ...
Copying udhcpc default script
cp: cannot stat '/home/root/files/quectel-CM/default.script': No such file or directory
chmod: cannot access '/usr/share/udhcpc/default.script': No such file or directory
Change directory to /home/root/files/quectel-CM
./qmi_install.sh: 61: cd: can't cd to /home/root/files/quectel-CM
make: *** No targets specified and no makefile found.  Stop.
chmod: cannot access '/home/root/files/quectel-CM': No such file or directory
After reboot please follow commands mentioned below
go to /home/root/files/quectel-CM and run sudo ./quectel-CM -s [YOUR APN]
Press ENTER key to reboot

https://github.com/sixfab/Sixfab_RPi_3G-4G-LTE_Base_Shield/blob/a669005d480605e2cae75e5d384d0f30f929f331/tutorials/QMI_tutorial/qmi_install.sh#L15

rmlamarche commented 3 years ago

As a follow-up thought, executing who am i instead of whoami will get the current session user, regardless of sudo/elevation:

Something like this might work if you don't wish to change the behavior too much:

DIR=/home/$(who am i | awk '{print $1}')/files

This still relies on the home directory of the user being in /home/username/files however. Tilde expansion is probably the way to go if you wish to force this into the user's $HOME/files directory

jsonpoindexter commented 2 years ago

I also got this to extract properly (after I had removed pi and used a different username) by replacing all pi references with $SUDO_USER