Skip to content
Merged
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
173 changes: 134 additions & 39 deletions lang/python/python-package-install.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,140 @@
#!/bin/sh
set -e

process_filespec() {
local src_dir="$1"
local dst_dir="$2"
local filespec="$3"
echo "$filespec" | (
IFS='|'
while read fop fspec fperm; do
local fop=`echo "$fop" | tr -d ' \t\n'`
if [ "$fop" = "+" ]; then
if [ ! -e "${src_dir}${fspec}" ]; then
echo "File not found '${src_dir}${fspec}'"
exit 1
fi
dpath=`dirname "$fspec"`
if [ -z "$fperm" ]; then
dperm=`stat -c "%a" ${src_dir}${dpath}`
fi
mkdir -p -m$dperm ${dst_dir}${dpath}
echo "copying: '$fspec'"
cp -fpR ${src_dir}${fspec} ${dst_dir}${dpath}/
if [ -n "$fperm" ]; then
chmod -R $fperm ${dst_dir}${fspec}
fi
elif [ "$fop" = "-" ]; then
echo "removing: '$fspec'"
rm -fR ${dst_dir}${fspec}
elif [ "$fop" = "=" ]; then
echo "setting permissions: '$fperm' on '$fspec'"
chmod -R $fperm ${dst_dir}${fspec}
fi
done
)

log() {
printf '%s\n' "$*"
}

error() {
printf 'Error: %s\n' "$*" >&2
}

path_exists() {
local dir="$1"
local path="$2"

[ -n "$(find "$dir"/$path -print -quit 2>/dev/null)" ]
}

file_dir_chmod() {
local dir="$1"
local path="$2"
local file_mode="$3"
local dir_mode="$4"
shift; shift; shift; shift;

if [ -n "$file_mode" ]; then
find "$dir"/$path -type f "$@" -exec chmod "$file_mode" -- '{}' +
fi

if [ -n "$dir_mode" ]; then
find "$dir"/$path -type d "$@" -exec chmod "$dir_mode" -- '{}' +
fi
}

src_dir="$1"
dst_dir="$2"
src="$1"
dest="$2"
filespec="$3"

process_filespec "$src_dir" "$dst_dir" "$filespec" || {
echo "process filespec error-ed"
if [ -z "$src" ]; then
error "Missing source directory"
exit 1
}
fi
if [ -z "$dest" ]; then
error "Missing destination directory"
exit 1
fi

while IFS='|' read -r cmd path file_mode dir_mode; do

# trim whitespace

cmd="${cmd#"${cmd%%[![:space:]]*}"}"
cmd="${cmd%"${cmd##*[![:space:]]}"}"

path="${path#"${path%%[![:space:]]*}"}"
path="${path%"${path##*[![:space:]]}"}"

file_mode="${file_mode#"${file_mode%%[![:space:]]*}"}"
file_mode="${file_mode%"${file_mode##*[![:space:]]}"}"

dir_mode="${dir_mode#"${dir_mode%%[![:space:]]*}"}"
dir_mode="${dir_mode%"${dir_mode##*[![:space:]]}"}"


if [ -z "$cmd" ] || [ "$cmd" != "${cmd#\#}" ]; then
continue
fi

if [ -z "$path" ]; then
error "Missing path for \"$cmd\""
exit 1
fi

case "$cmd" in
+)
log "Copying: \"$path\""

if ! path_exists "$src" "$path"; then
error "\"$src/$path\" not found"
exit 1
fi

dir="${path%/*}"
mkdir -p "$dest/$dir"
cp -fpR "$src"/$path "$dest/$dir/"

file_dir_chmod "$dest" "$path" "$file_mode" "$dir_mode"
;;

-)
log "Removing: \"$path\""

if ! path_exists "$dest" "$path"; then
error "\"$dest/$path\" not found"
exit 1
fi

rm -fR -- "$dest"/$path
;;

=)
log "Setting recursive permissions \"${file_mode:-(none)}\"/\"${dir_mode:-(none)}\" on \"$path\""

if ! path_exists "$dest" "$path"; then
error "\"$dest/$path\" not found"
exit 1
fi

if [ -z "$file_mode$dir_mode" ]; then
error "Missing recursive permissions for \"$path\""
exit 1
fi

file_dir_chmod "$dest" "$path" "$file_mode" "$dir_mode"
;;

==)
log "Setting permissions \"${file_mode:-(none)}\"/\"${dir_mode:-(none)}\" on \"$path\""

if ! path_exists "$dest" "$path"; then
error "\"$dest/$path\" not found"
exit 1
fi

if [ -z "$file_mode$dir_mode" ]; then
error "Missing permissions for \"$path\""
exit 1
fi

file_dir_chmod "$dest" "$path" "$file_mode" "$dir_mode" -maxdepth 0
;;

*)
error "Unknown command \"$cmd\""
exit 1
;;
esac

done << EOF
$filespec
EOF
3 changes: 2 additions & 1 deletion lang/python/python3-package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PYTHON3:=python$(PYTHON3_VERSION)

PYTHON3PATH:=$(PYTHON3_LIB_DIR):$(STAGING_DIR)/$(PYTHON3_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)

-include $(PYTHON3_LIB_DIR)/config-$(PYTHON3_VERSION)/Makefile-vars
-include $(PYTHON3_LIB_DIR)/openwrt/Makefile-vars

# These configure args are needed in detection of path to Python header files
# using autotools.
Expand All @@ -39,6 +39,7 @@ PYTHON3_VARS = \
CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON3_INC_DIR)" \
LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
_PYTHON_HOST_PLATFORM="$(_PYTHON_HOST_PLATFORM)" \
_PYTHON_SYSCONFIGDATA_NAME="_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH)" \
PYTHONPATH="$(PYTHON3PATH)" \
PYTHONDONTWRITEBYTECODE=1 \
_python_sysroot="$(STAGING_DIR)" \
Expand Down
Loading