Skip to content

Commit

Permalink
Update forkrun.bash
Browse files Browse the repository at this point in the history
  • Loading branch information
jkool702 authored Aug 5, 2024
1 parent b9516cf commit 79f580c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions forkrun.bash
Original file line number Diff line number Diff line change
Expand Up @@ -1603,21 +1603,23 @@ EOF

forkrun_lseek_setup() {
## sets up a "lseek" bash builtin for x86_64 machines
local lseekPreFlag=false

type uname &>/dev/null && { [[ $(uname -m) == 'x86_64' ]] || return 1; }
[[ -f /proc/sys/kernel/arch ]] && { [[ "$(</proc/sys/kernel/arch)" == 'x86_64' ]] || return 1; }

enable lseek 2>/dev/null || {
[[ -f /usr/local/lib/bash/lseek ]] && lseekPreFlag=true
case "${USER}" in
root)
mkdir -p /usr/local/lib/bash
[[ -f /usr/local/lib/bash/lseek ]] && mv /usr/local/lib/bash/lseek /usr/local/lib/bash/lseek.old
${lseekPreFlag} && \mv /usr/local/lib/bash/lseek /usr/local/lib/bash/lseek.old
[[ "${BASH_LOADABLES_PATH}" == */usr/local/lib/bash* ]] || export BASH_LOADABLES_PATH=/usr/local/lib/bash:${BASH_LOADABLES_PATH}
curl -o /usr/local/lib/bash/lseek 'https://raw.githubusercontent.com/jkool702/forkrun/main/lseek_builtin/lseek'
;;
*)
mkdir -p /dev/shm/.forkrun.lseek
[[ -f /dev/shm/.forkrun.lseek/lseek ]] && mv /dev/shm/.forkrun.lseek/lseek /dev/shm/.forkrun.lseek/lseek.old
${lseekPreFlag} && \mv /dev/shm/.forkrun.lseek/lseek /dev/shm/.forkrun.lseek/lseek.old
[[ "${BASH_LOADABLES_PATH}" == */dev/shm/.forkrun.lseek* ]] || export BASH_LOADABLES_PATH=/dev/shm/.forkrun.lseek:${BASH_LOADABLES_PATH}
curl -o /dev/shm/.forkrun.lseek/lseek 'https://raw.githubusercontent.com/jkool702/forkrun/main/lseek_builtin/lseek'
;;
Expand All @@ -1644,8 +1646,10 @@ forkrun_lseek_setup() {
printf '\nWARNING: lseek functionality has not been enabled due to an unknown runtime error.\nIf you are on x86_64 and are using bash 4.0 or later, please file a github issue in the forkrun repo describing this error.\n' >&2
if [[ "${USER}" == 'root' ]]; then
\rm -f /usr/local/lib/bash/lseek
${lseekPreFlag} && mv /usr/local/lib/bash/lseek.old /usr/local/lib/bash/lseek
else
\rm -f /dev/shm/.forkrun.lseek/lseek
${lseekPreFlag} && mv /dev/shm/.forkrun.lseek/lseek.old /dev/shm/.forkrun.lseek/lseek
fi
return 1
;;
Expand Down

0 comments on commit 79f580c

Please sign in to comment.