Skip to content

Commit

Permalink
fix: [#264] make DESTDIR properly configured in header
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick330602 committed Nov 12, 2023
1 parent c818f00 commit b6fa4b7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ For contributing, there are several functions and variables built-in the header
- `wslu_util_name` - current utility name
- `wslu_version` - wslu version, written by `VERSION`
- `wslu_prefix` - the location `wslu` installed to, written by the `PREFIX` during the make.
- `wslu_dest_dir` - the location `wslu` installed to, written by the `DESTDIR` during the make.
- `wslu_debug` - the variable used for calling utility across. This will allow calling the `--debug` option for other `wslu` utilities inside script easier.
- Formatting: `black`, `red`, `green`, `brown`, `blue`, `purple`, `cyan`, `yellow`, `white`, `dark_gray`, `light_red`, `light_green`, `light_blue`, `light_purple`, `light_cyan`, `light_gray`, `orange`, `light_orange`, `deep_purple`, `bold`, `reset`
- Indicator: `info`, `input_info`, `error`, `warn`
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ VERTMP = $(shell cat ./VERSION)

all: doc
[ -d $(OUTPATH) ] || mkdir $(OUTPATH)
sed -e 's/VERSIONPLACEHOLDER/'$(VERTMP)'/' -e 's|PREFIXPLACEHOLDER|'$(PREFIX)'|' $(HEADER) > $(HEADER).tmp; \
sed -e 's/VERSIONPLACEHOLDER/'$(VERTMP)'/' -e 's|PREFIXPLACEHOLDER|'$(PREFIX)'|' -e 's|DESTDIRPLACEHOLDER|'$(DESTDIR)'|' $(HEADER) > $(HEADER).tmp; \
for file in $(SOURCES); do \
cat $(HEADER).tmp $$file > $(OUTPATH)/`basename $$file`; \
mv $(OUTPATH)/`basename $$file` $(OUTPATH)/`basename $$file .sh`; \
Expand Down
17 changes: 9 additions & 8 deletions src/wslu-header
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ wslu_util_name=$(basename "$wslu_util_fullpath")
# Version
wslu_version=VERSIONPLACEHOLDER
wslu_prefix="PREFIXPLACEHOLDER"
wslu_dest_dir="DESTDIRPLACEHOLDER"

# Speed up script by using unicode.
LC_ALL=C
Expand Down Expand Up @@ -150,20 +151,20 @@ function error_echo {
}

# source default config
if [ -f "${wslu_prefix}/share/wslu/conf" ]; then
if [ -f "${wslu_dest_dir}${wslu_prefix}/share/wslu/conf" ]; then
debug_echo "source default setting"
source "${wslu_prefix}/share/wslu/conf"
source "${wslu_dest_dir}${wslu_prefix}/share/wslu/conf"
fi

# source user-defined config
if [ -f "${wslu_prefix}/share/wslu/custom.conf" ]; then
debug_echo "${wslu_prefix}/share/wslu/custom.conf found, sourcing"
source "${wslu_prefix}/share/wslu/custom.conf"
if [ -f "${wslu_dest_dir}${wslu_prefix}/share/wslu/custom.conf" ]; then
debug_echo "${wslu_dest_dir}${wslu_prefix}/share/wslu/custom.conf found, sourcing"
source "${wslu_dest_dir}${wslu_prefix}/share/wslu/custom.conf"
fi

if [ -f "/etc/wslu/conf" ]; then
debug_echo "/etc/wslu/conf found, sourcing"
source "/etc/wslu/conf"
if [ -f "${wslu_dest_dir}/etc/wslu/conf" ]; then
debug_echo "${wslu_dest_dir}/etc/wslu/conf found, sourcing"
source "${wslu_dest_dir}/etc/wslu/conf"
fi

if [ -f "/etc/wslu/custom.conf" ]; then
Expand Down
8 changes: 4 additions & 4 deletions src/wslvar.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# shellcheck shell=bash
var_type=1
var_type=${WSLVAR_DEFAULT_VARTYPE:-1}

help_short="wslvar [-sl] NAME\nwslvar [-hvSL]"

Expand All @@ -25,7 +25,7 @@ function cl_destoryer {

function caller {
if [ "$*" != "" ]; then
case $WSLVAR_DEFAULT_VARTYPE in
case $var_type in
1) p="$(cl_destoryer "$(call_sys "$@")")";;
2) p="$(cl_destoryer "$(call_shell "$@")")";;
*) error_echo "Invalid variable type. Aborted." 22;;
Expand All @@ -38,8 +38,8 @@ function caller {

while [ "$1" != "" ]; do
case "$1" in
-s|--sys) WSLVAR_DEFAULT_VARTYPE=1; shift;;
-l|--shell) WSLVAR_DEFAULT_VARTYPE=2; shift;;
-s|--sys) var_type=1; shift;;
-l|--shell) var_type=2; shift;;
-S|--getsys) view_sys; exit;;
-L|--getshell) view_shell; exit;;
-h|--help) help "$0" "$help_short"; exit;;
Expand Down

0 comments on commit b6fa4b7

Please sign in to comment.