Closed fabern closed 4 years ago
Thanks for letting me know.
Seems like a portable solution is not that easy.
I am trying to decide what is the best portable way that can be implemented in bash.
Then I will make a new version with it and publish here.
This problem is so stupid and so annoying.
I have a working portable solution for realpath
, but I am still struggling to have a portable GNU readlink -f
solution.
The BSD readlink could be OK, since the non canonicalized version of the path should be ok to install. But then it does not work for the current folder (./
or no folder reference). Which is beyond stupid and I really can't understand why on earth it would behave like this.
It is 2020 and this is still a big problem for many scripts.
Branch v2.5 is being tested and should fix this.
https://github.com/tavinus/pdfScale/tree/v2.5
The Installer and the Upgrader should now work on MacOSX (can you please test them for me?)
Please note that the Upgrader will end up failing because it will download the old version from the master branch (for now). But if the installer of the new version works, the upgrader will also work after merging it to the master branch.
EDIT
v2.5.2 fixes a problem with curl redirects that was breaking upgrades.
Thanks for checking the issue. Installation says successful, but afterwards permission denied
when trying to use the program. I'm installing not from master
but from the branch v2.5
.
bernharf@bernstein:~|⇒ curl -s -o /tmp/pdfScale.sh 'https://raw.githubusercontent.com/tavinus/pdfScale/v2.5/pdfScale.sh' && bash /tmp/pdfScale.sh --install
pdfScale.sh v2.5.2 - Self Install
Current location : /tmp/pdfScale.sh
Target location : /usr/local/bin/pdfscale
cp: /usr/local/bin/pdfscale: Permission denied
There was an error when trying to install pdfScale.
Do you want to try again with sudo (as root)? Y/y to continue > Y
Password:
Success! Program installed!
> /usr/local/bin/pdfscale
But using doesn't work:
bernharf@bernstein:~|⇒ /usr/local/bin/pdfscale
zsh: permission denied: /usr/local/bin/pdfscale
bernharf@bernstein:~|⇒ ls -thal /usr/local/bin/pdfscale
-rw-r--r-- 1 root admin 92K Apr 4 15:11 /usr/local/bin/pdfscale
Modifying user rights to have it executable doesn't change anything for my user:
bernharf@bernstein:~|⇒ sudo chmod u+rwx /usr/local/bin/pdfscale
Password:
bernharf@bernstein:~|⇒ ls -thal /usr/local/bin/pdfscale
-rwxr--r-- 1 root admin 92K Apr 4 15:11 /usr/local/bin/pdfscale
bernharf@bernstein:~|⇒ /usr/local/bin/pdfscale -p
zsh: permission denied: /usr/local/bin/pdfscale
However, when sudo
ing the last command then I successfully get a list of the formats.
Regarding the Upgrader. It seems to work when using sudo
:
bernharf@bernstein:~|⇒ sudo pdfscale --upgrade
pdfscale v2.5.2 - Self Upgrade
Preparing download to temp folder
> /tmp/pdfScale_20200404-153717.tar.gz
Downloading file with curl
Extracting compressed file
Current Version is: 2.5.2
Downloaded Version is: 2.4.9
Seems like the downloaded version is older that the one installed.
It is basically a miracle or you have came from the future with this version!
BE CAREFUL NOT TO DELETE THE BETA/ALPHA VERSION WITH THIS UPDATE!
Are you sure that you want to replace the current installation with the downloaded one?
Y/y to continue, anything else to cancel > n
Exiting... (cancelled by user)
Cleaning up downloaded files from /tmp
> /tmp/pdfScale_20200404-153717.tar.gz > Ok
> /tmp/pdfScale-master > Ok
That is rather weird.
When I tested here (was on Yosemite) it didn't even ask for sudo and I could just call pdfscale without the full path.
Since /usr/local
is not a "normal" BSD/Mac folder, it is only created after homebrew is installed (so the permissions may vary).
The weirdest part is it being able to install but not setting the proper execution permissions. Even more weird is that you could not apply the execution flag manually.
What happens if you just
sudo chmod +x /usr/local/bin/pdfscale
/usr/local/bin/pdfscale -p
I wonder if zsh is doing something weird.
Can you also try from bash?
Both the upgrader and the installer should ask for sudo automatically if needed. Meaning that you should be able to just run without sudo and it will ask for it if needed. No harm on calling it with sudo from the start though, it should just install as root in that case (but set execution to everyone).
Usually the permissions of files is maintained on copies, but it seems like this is not the case here.
What happens is that we download the new version, set it to executable and run it. Then it will copy itself to the desired location (and here it should maintain the execution flag, but it is not doing that).
I will add a chmod
call after the install to reapply the execution flag and then we can see if it solves the issue.
Will push it in a few minutes
Ok, new version (v2.5.3) is there. Can you test it please?
curl -s -o /tmp/pdfScale.sh 'https://raw.githubusercontent.com/tavinus/pdfScale/v2.5/pdfScale.sh' && bash /tmp/pdfScale.sh --install
Then
/usr/local/bin/pdfscale --upgrade
NOTE You can change the installation path if you want, just pass it to the installer as a parameter
pdfscale --install /my/custom/path
The upgrader will install in place (will keep current location, whatever it is).
Executing sudo chmod +x /usr/local/bin/pdfscale
fixed the existing installation v2.5.2
. Resulting in an executable, workgin file. Essentially it moved the rights from -rwxr--r--
to -rwxr-xr-x
.
I have not tried on bash.
v2.5.3
installs but with a short hiccup, requesting root access for installation:
bernharf@bernstein:~/switchdrive/Documents/Job/Anstellung 2019 WSL/Doktorat/Literature/Library/Kirchner-2019-Hydrol. Earth Syst. Sci.|
⇒ curl -s -o /tmp/pdfScale.sh 'https://raw.githubusercontent.com/tavinus/pdfScale/v2.5/pdfScale.sh' && bash /tmp/pdfScale.sh --install
pdfScale.sh v2.5.3 - Self Install
Current location : /tmp/pdfScale.sh
Target location : /usr/local/bin/pdfscale
The target file already exists: /usr/local/bin/pdfscale
Y/y to overwrite, anything else to cancel > y
Target will be replaced!
cp: /usr/local/bin/pdfscale: Permission denied
There was an error when trying to install pdfScale.
Do you want to try again with sudo (as root)? Y/y to continue > y
Success! Program installed!
> /usr/local/bin/pdfscale
bernharf@bernstein:~|⇒ pdfscale -p
pdfscale v2.5.3
It might be that my install is somewhat non-standard. I'm using brew
but don't master all the intricacies of access rights.
On another computer - the one from my initial post in October – update to v2.5.3
works without an issue. On that computer access rights of /usr/local/bin/pdfscale
were already on -rwxr-xr-x
.
Cool. Seems solved then.
The difficult part is always finding a solution that is portable and works everywhere.
I think that your chmod call ( chmod u+rwx
) was setting it executable only for root (which is the owner of the file).
chmod +x
sets it executable on all levels (user-group-everyone), which is the default for system-wide apps.
I just noticed that the two computers differ in their output to ls -thal /usr/local/bin/pdfscale
.
While the computer where it works shows:
-rwxr-xr-x 1 [username] admin
,
the one with the difficulties showed
-rwxr-xr-x 1 root admin
i.e. root
instead of [username]
.
So on one computer the owner was root
while on the other it was the active user...
Okay, probably due to some mistake of mine. ^^ Thanks for your time and efforts!
There is no problem that the ownership is different (or root), as long as it is executable to everyone.
Usually it is owned by root with permissions to be executed by others (when system installed).
Hi Tavinus,
On macOS (10.14.6) I got an error trying to use the install script.
Current location is not detected. This is probably linked to trying to use readlink on macOS. https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
My workaround to this was by installing
brew install coreutils
and then modifying thepdfScale.sh
to usegreadlink
instead ofreadlink
following the answer: https://stackoverflow.com/a/4031502Best regards, Fabian