GithubHelp home page GithubHelp logo

Comments (10)

miyagawa avatar miyagawa commented on September 25, 2024

I guess you either hardcode the path to head or cat (i.e. /usr/bin/head or /bin/cat) but that would make things a bit less portable. You can alternatively choose to blacklist head, cat commands from symlinking in shims, since putting them in the PATH makes no sense.

PPT's bin commands are fun experiments to reimplement UNIX commands in perl, but putting them in $PATH asks for problems.

from plenv.

tokuhirom avatar tokuhirom commented on September 25, 2024

Hmmm... I understand the problem, but I don't have a good idea to resolve
this issue.

On Fri, Feb 27, 2015 at 6:54 AM Tatsuhiko Miyagawa [email protected]
wrote:

I guess you either hardcode the path to head or cat (i.e. /usr/bin/head or
/bin/cat) but that would make things a bit less portable. You can
alternatively choose to blacklist head, cat commands from symlinking in
shims, since putting them in the PATH makes no sense.

PPT's bin commands are fun experiments to reimplement UNIX commands in
perl, but putting them in $PATH asks for problems.


Reply to this email directly or view it on GitHub
#78 (comment).

from plenv.

miyagawa avatar miyagawa commented on September 25, 2024

from plenv.

miyagawa avatar miyagawa commented on September 25, 2024

Another solution is to write cat/head in pure bash. I'm no bash expert but it doesn't seem that hard.

from plenv.

syohex avatar syohex commented on September 25, 2024

read which is a bash builtin function can be used instead of both head and cat like following the patch. However it is difficult(impossible?) to replace with chmod with bash functions.

diff --git a/libexec/plenv b/libexec/plenv
index a165f4b..a648499 100755
--- a/libexec/plenv
+++ b/libexec/plenv
@@ -12,7 +12,7 @@ if [ -n "$PLENV_DEBUG" ]; then
   set -x
 fi

-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | while read line; do echo -n $line; break; done)
 if [ -z "$READLINK" ]; then
   echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
   exit 1
diff --git a/libexec/plenv-hooks b/libexec/plenv-hooks
index 3b3f7d8..64d37b0 100755
--- a/libexec/plenv-hooks
+++ b/libexec/plenv-hooks
@@ -19,7 +19,7 @@ if [ -z "$PLENV_COMMAND" ]; then
   exit 1
 fi

-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | while read line; do echo -n $line; break; done)
 if [ -z "$READLINK" ]; then
     echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
     exit 1
diff --git a/libexec/plenv-init b/libexec/plenv-init
index d90ea07..915b0b8 100755
--- a/libexec/plenv-init
+++ b/libexec/plenv-init
@@ -27,7 +27,7 @@ if [ -z "$shell" ]; then
   shell="$(basename "${shell:-$SHELL}")"
 fi

-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | while line; do echo -n $line; break; done)
 if [ -z "$READLINK" ]; then
   echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
   exit 1
diff --git a/libexec/plenv-rehash b/libexec/plenv-rehash
index 31b8b47..52e1a6f 100755
--- a/libexec/plenv-rehash
+++ b/libexec/plenv-rehash
@@ -40,7 +40,7 @@ remove_prototype_shim() {
 # technique is fast, uses less disk space than unique files, and also
 # serves as a locking mechanism.
 create_prototype_shim() {
-  cat > "$PROTOTYPE_SHIM_PATH" <<SH
+  $(read -r -d '' shim <<SH
 #!/usr/bin/env bash
 set -e
 [ -n "\$PLENV_DEBUG" ] && set -x
@@ -59,6 +59,7 @@ fi
 export PLENV_ROOT="$PLENV_ROOT"
 exec "$(command -v plenv)" exec "\$program" "\$@"
 SH
+echo "$shim" > "$PROTOTYPE_SHIM_PATH")
   chmod +x "$PROTOTYPE_SHIM_PATH"
 }

bash is difficult :-(

from plenv.

syohex avatar syohex commented on September 25, 2024

I can install PerlPowerTools with following patch(gist).

diff --git a/libexec/plenv b/libexec/plenv
index a165f4b..8b3c47e 100755
--- a/libexec/plenv
+++ b/libexec/plenv
@@ -12,12 +12,25 @@ if [ -n "$PLENV_DEBUG" ]; then
   set -x
 fi

-READLINK=$(type -p greadlink readlink | head -1)
+head1() {
+  while read line do
+  do
+    echo $line
+    break;
+  done
+}
+
+READLINK=$(type -p greadlink readlink | head1)
 if [ -z "$READLINK" ]; then
   echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
   exit 1
 fi

+export PLENV_CMD_CAT=$(type -p /bin/cat /usr/bin/cat | head1)
+export PLENV_CMD_LN=$(type -p /bin/ln /usr/bin/ln | head1)
+export PLENV_CMD_CHMOD=$(type -p /bin/chmod /usr/bin/chmod | head1)
+export PLENV_CMD_RM=$(type -p /bin/rm /usr/bin/rm | head1)
+
 resolve_link() {
   $READLINK "$1"
 }
diff --git a/libexec/plenv-hooks b/libexec/plenv-hooks
index 3b3f7d8..61d2e80 100755
--- a/libexec/plenv-hooks
+++ b/libexec/plenv-hooks
@@ -19,7 +19,7 @@ if [ -z "$PLENV_COMMAND" ]; then
   exit 1
 fi

-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | while read line; do echo $line; break; done)
 if [ -z "$READLINK" ]; then
     echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
     exit 1
diff --git a/libexec/plenv-init b/libexec/plenv-init
index 8bbf0b7..8c3856d 100755
--- a/libexec/plenv-init
+++ b/libexec/plenv-init
@@ -27,7 +27,7 @@ if [ -z "$shell" ]; then
   shell="$(basename "${shell:-$SHELL}")"
 fi

-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | while read line; do echo $line; break; done)
 if [ -z "$READLINK" ]; then
   echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
   exit 1
@@ -119,7 +119,7 @@ fi
 commands=(`plenv-commands --sh`)
 case "$shell" in
 fish )
-  cat <<EOS
+  $PLENV_CMD_CAT <<EOS
 function plenv
   set command \$argv[1]
   set -e argv[1]
@@ -134,7 +134,7 @@ end
 EOS
   ;;
 ksh )
-  cat <<EOS
+  $PLENV_CMD_CAT <<EOS
 function plenv {
   typeset command
 EOS
@@ -149,7 +149,7 @@ esac

 if [ "$shell" != "fish" ]; then
 IFS="|"
-cat <<EOS
+$PLENV_CMD_CAT <<EOS
   command="\$1"
   if [ "\$#" -gt 0 ]; then
     shift
diff --git a/libexec/plenv-local b/libexec/plenv-local
index c2ae93f..b3b2b44 100755
--- a/libexec/plenv-local
+++ b/libexec/plenv-local
@@ -36,12 +36,12 @@ fi
 PLENV_VERSION="$1"

 if [ "$PLENV_VERSION" = "--unset" ]; then
-  rm -f .perl-version .plenv-version
+  $PLENV_CMD_RM -f .perl-version .plenv-version
 elif [ -n "$PLENV_VERSION" ]; then
   previous_file="$(PLENV_VERSION= plenv-version-origin || true)"
   plenv-version-file-write .perl-version "$PLENV_VERSION"
   if [ "$previous_file" -ef .plenv-version ]; then
-    rm -f .plenv-version
+    $PLENV_CMD_RM -f .plenv-version
     { echo "plenv: removed existing \`.plenv-version' file and migrated"
       echo "       local version specification to \`.perl-version' file"
     } >&2
diff --git a/libexec/plenv-rehash b/libexec/plenv-rehash
index 31b8b47..13c976c 100755
--- a/libexec/plenv-rehash
+++ b/libexec/plenv-rehash
@@ -31,7 +31,7 @@ set +o noclobber
 trap remove_prototype_shim EXIT

 remove_prototype_shim() {
-  rm -f "$PROTOTYPE_SHIM_PATH"
+  $PLENV_CMD_RM -f "$PROTOTYPE_SHIM_PATH"
 }

 # The prototype shim file is a script that re-execs itself, passing
@@ -40,7 +40,7 @@ remove_prototype_shim() {
 # technique is fast, uses less disk space than unique files, and also
 # serves as a locking mechanism.
 create_prototype_shim() {
-  cat > "$PROTOTYPE_SHIM_PATH" <<SH
+  $PLENV_CMD_CAT > "$PROTOTYPE_SHIM_PATH" <<SH
 #!/usr/bin/env bash
 set -e
 [ -n "\$PLENV_DEBUG" ] && set -x
@@ -59,7 +59,7 @@ fi
 export PLENV_ROOT="$PLENV_ROOT"
 exec "$(command -v plenv)" exec "\$program" "\$@"
 SH
-  chmod +x "$PROTOTYPE_SHIM_PATH"
+  $PLENV_CMD_CHMOD +x "$PROTOTYPE_SHIM_PATH"
 }

 # If the contents of the prototype shim file differ from the contents
@@ -68,7 +68,7 @@ SH
 remove_outdated_shims() {
   for shim in *; do
     if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then
-      for shim in *; do rm -f "$shim"; done
+      for shim in *; do $PLENV_CMD_RM -f "$shim"; done
     fi
     break
   done
@@ -108,7 +108,7 @@ register_shim() {
 install_registered_shims() {
   local shim
   for shim in "${registered_shims[@]}"; do
-    [ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
+    [ -e "$shim" ] || $PLENV_CMD_LN -f "$PROTOTYPE_SHIM_PATH" "$shim"
   done
 }

@@ -120,7 +120,7 @@ remove_stale_shims() {
   local shim
   for shim in *; do
     if [[ "$registered_shims_index" != *"/$shim/"* ]]; then
-      rm -f "$shim"
+      $PLENV_CMD_RM -f "$shim"
     fi
   done
 }
diff --git a/libexec/plenv-version-file-read b/libexec/plenv-version-file-read
index 976924c..97fd97b 100755
--- a/libexec/plenv-version-file-read
+++ b/libexec/plenv-version-file-read
@@ -14,7 +14,7 @@ if [ -e "$VERSION_FILE" ]; then
     if [ -z "$version" ] && [ -n "$word" ]; then
       version="$word"
     fi
-  done < <( cat "$VERSION_FILE" && echo )
+  done < <( $PLENV_CMD_CAT "$VERSION_FILE" && echo )

   if [ -n "$version" ]; then
     echo "$version"
diff --git a/plenv.d/rehash/rehash_cpanm.bash b/plenv.d/rehash/rehash_cpanm.bash
index 740eadd..901adaf 100755
--- a/plenv.d/rehash/rehash_cpanm.bash
+++ b/plenv.d/rehash/rehash_cpanm.bash
@@ -25,4 +25,4 @@ done
 exit \$rc
 SH

-chmod +x "$CPANM_SHIM_PATH"
+$PLENV_CMD_CHMOD +x "$CPANM_SHIM_PATH"

NOTE How to clean up

Installing PerlPowerTools is dangerous . Many tools(cpanm etc) cannot work after install
PerlPowerTools.

  1. Remove shims directory(rm -rf ~/.plenv/shims)
  2. Uninstalling PerlPowerTools(~/.plenv/versions/your_perl_version/bin/cpanm --uninstall PerlPowerTools)
  3. Re-generate symbolic links(plenv rehash)

from plenv.

miyagawa avatar miyagawa commented on September 25, 2024

@syohex the patch looks good to me!

I agree about the dangerous aspect of PPT, was wondering if I should make a PR on there to stop installing these executables by default.

from plenv.

syohex avatar syohex commented on September 25, 2024

@miyagawa Thanks for reviewing. I have sent PR #79.

from plenv.

briandfoy avatar briandfoy commented on September 25, 2024

Is this something because the PerlPowerTools version of head needs to be fixed to work like the real head you were expecting or because plenv gets confused because any file of that name (no matter what it does) will cause it to be confused?

I'll make a change to PerlPowerTools to not install into perl's bin, but this seems to be a fundamental flaw in plenv. I've done similar things locally with my own tools and run into this problem. This means even though I change PerlPowerTools, you still have this problem if someone does something similar. For instance, LWP used to install a "head", as I recall.

from plenv.

miyagawa avatar miyagawa commented on September 25, 2024

@briandfoy yes it's fixed in #79

from plenv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.