Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows busybox install #1077

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions distro/windows/EasyRSA-busybox.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo OFF
bin\busybox.exe sh bin\easyrsa-busybox-init.sh %*
Binary file added distro/windows/bin/busybox.exe
Binary file not shown.
145 changes: 145 additions & 0 deletions distro/windows/bin/easyrsa-busybox-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/bin/sh
# shellcheck disable=SC2161,SC1091,SC2028

# This script is a frontend designed to create & launch a POSIX shell
# environment suitable for use with Easy-RSA. mksh/Win32 is used with this
# project; use with other POSIX shells for Windows may require modification to
# this wrapper script.

setup_path="${EASYRSA:-$PWD}"
export PATH="$setup_path;$PATH"
export HOME="$setup_path"

# This prevents reading from a user's .mkshrc if they have one.
# A user who runs mksh for other purposes might have it
export ENV="/disable-env"

# Allow options
non_admin=""
while [ "$1" ]; do
case "$1" in
/[Nn][Aa]|/no-adm*|--no-adm*)
non_admin=1
echo "Using no-admin mode"
;;
*)
echo "Ignoring unknown option: '$1'"
esac
shift
done

# Access denied
access_denied() {
echo "Access error: $1"
cat << "ACCESS_DENIED_MSG"

To use Easy-RSA in a protected system directory, you must have
elevated privileges via 'Windows User Access Control'.
You can try 'run-as admin' but that may also fail.

It is recommended to use Easy-RSA in your User/home directory.

Please try using one of the following solutions:
* Use the Start Menu item: 'Start Easy-RSA Shell (Non-Admin)'
* Or, in a Non-Admin command prompt window, run two commands:

cd '\Program Files\Openvpn\easy-rsa\'
EasyRSA-Start.bat /no-admin

These will start EasyRSA in your user's 'home directory/easy-rsa'

Press enter to exit."
ACCESS_DENIED_MSG

#shellcheck disable=SC2162
read
exit 1
}

# Use home directory/easy-rsa
if [ "$non_admin" ]; then
[ "${HOMEDRIVE}" ] || \
access_denied "Undefined: HOMEDRIVE"
user_home_drv="${HOMEDRIVE}"

[ "${HOMEPATH}" ] || \
access_denied "Undefined: HOMEPATH"
eval "user_home_dir='\\${HOMEPATH}'"

# shellcheck disable=SC2154 # user_home_dir is not assigned
user_home="${user_home_drv}${user_home_dir}"

[ -d "$user_home" ] || \
access_denied "Missing: $user_home"

cd "$user_home" 2>/dev/null || \
access_denied "Access: $user_home"

if [ ! -d easy-rsa ]; then
mkdir easy-rsa 2>/dev/null || \
access_denied "mkdir: easy-rsa"
# Required test
[ -d easy-rsa ] || \
access_denied "Missing: easy-rsa"
fi

cd easy-rsa 2>/dev/null || \
access_denied "Access: easy-rsa"

export HOME="$PWD"
export PATH="$HOME;$PATH"
unset -v user_home_drv user_home_dir user_home
fi

# Check for broken administrator access
# https://github.com/OpenVPN/easy-rsa/issues/1072
[ -d "$HOME" ] || access_denied "-d HOME"
win_tst_d="$HOME"/easyrsa-write-test

# Required tests
mkdir "$win_tst_d" 2>/dev/null || access_denied "mkdir"
[ -d "$win_tst_d" ] || access_denied "-d"
echo 1 >"$win_tst_d"/1 2>/dev/null || access_denied "write"
[ -f "$win_tst_d"/1 ] || access_denied "-f"
rm -rf "$win_tst_d" 2>/dev/null || access_denied "rm"
[ ! -d "$win_tst_d" ] || access_denied "! -d"
unset -v win_tst_d
unset -f access_denied

# set_var is defined as any vars file needs it.
# This is the same as in easyrsa, but we _don't_ export
set_var() {
var="$1"
shift
value="$*"
eval "$var=\"\${$var-$value}\""
} #=> set_var()

# Check for a usable openssl bin, referencing vars if present
[ -r "vars" ] && EASYRSA_CALLER=1 . "vars" 2>/dev/null
if [ -z "$EASYRSA_OPENSSL" ] && ! which openssl.exe >/dev/null 2>&1; then
echo "WARNING: openssl isn't in your system PATH. The openssl binary must be"
echo " available in the PATH, defined in the 'vars' file, or defined in a"
echo " named environment variable. See README-Windows.txt for more info."
fi

[ -f "$setup_path/easyrsa" ] || {
echo "Missing easyrsa script. Expected to find it at: $setup_path/easyrsa"
exit 2
}

# Set prompt and welcome message
export PS1='
EasyRSA Shell
# '
echo ""
echo "Welcome to the EasyRSA 3 Shell for Windows."
echo "Easy-RSA 3 is available under a GNU GPLv2 license."
echo ""
echo "Invoke 'easyrsa' to call the program. Without commands, help is displayed."
echo ""
echo "Using directory: $HOME"
echo ""

# Drop to a shell and await input
"$setup_path"/bin/busybox.exe sh
Empty file modified distro/windows/bin/easyrsa-shell-init.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion wop-test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ copy "%WORK_DIR%\distro\windows\%SYS_ARCH%\*" "%WORK_DIR%\easyrsa3\bin"
copy "%WORK_DIR%\distro\windows\EasyRSA-Start.bat" "%WORK_DIR%\easyrsa3\EasyRSA-Start.bat"
PATH=%PATH%;%WORK_DIR%\easyrsa3\bin;C:\PROGRA~1\openssl

cmd /C "easyrsa3\bin\sh.exe wop-test.sh"
cmd /C "easyrsa3\bin\busybox.exe sh wop-test.sh"
IF ERRORLEVEL 1 (
echo Error occurred, Exit 1
exit /B 1 )
Expand Down
19 changes: 1 addition & 18 deletions wop-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,13 @@
cd easyrsa3 || { echo "ERROR: Cannot find easyrsa3 directory"; exit 1; }

setup_path="${EASYRSA:-$PWD}"
export PATH="$setup_path;$setup_path/bin;$PATH"
export PATH="$setup_path;$PATH"
export HOME="$setup_path"

# This prevents reading from a user's .mkshrc if they have one.
# A user who runs mksh for other purposes might have it
export ENV="/disable-env"

# Verify required externals are present
extern_list="which awk cat cp mkdir printf rm"
for f in $extern_list; do
if ! which "${f}.exe" >/dev/null 2>&1; then
echo ""
echo "FATAL: EasyRSA Shell init is missing a required external file:"
echo " ${f}.exe"
echo " Your installation is incomplete and cannot function without the required"
echo " files."
echo ""
echo " Press enter to exit."
#shellcheck disable=SC2162
read
exit 1
fi
done

# set_var is defined as any vars file needs it.
# This is the same as in easyrsa, but we _don't_ export
set_var() {
Expand Down