浏览代码

scripts/kernel_bump: Run script relative to the script dir

Determine the target directory based on the script location, which might
work better in some cases, but at least also allows the script to be ran
from with any location in the OpenWRT repository.

Signed-off-by: Olliver Schinagl <[email protected]>
Olliver Schinagl 1 年之前
父节点
当前提交
9f0cc3eb11
共有 1 个文件被更改,包括 14 次插入10 次删除
  1. 14 10
      scripts/kernel_bump.sh

+ 14 - 10
scripts/kernel_bump.sh

@@ -59,6 +59,7 @@ usage()
 	echo "    -t  Target version of kernel (e.g. 'v6.6' [TARGET_VERSION]')"
 	echo "    -t  Target version of kernel (e.g. 'v6.6' [TARGET_VERSION]')"
 	echo
 	echo
 	echo 'All options can also be passed in environment variables (listed between [BRACKETS]).'
 	echo 'All options can also be passed in environment variables (listed between [BRACKETS]).'
+	echo 'Note that this script must be run from within the OpenWrt git repository.'
 	echo 'Example: scripts/kernel_bump.sh -p realtek -s v6.1 -t v6.6'
 	echo 'Example: scripts/kernel_bump.sh -p realtek -s v6.1 -t v6.6'
 }
 }
 
 
@@ -74,6 +75,8 @@ cleanup()
 
 
 init()
 init()
 {
 {
+	src_file="$(readlink -f "${0}")"
+	src_dir="${src_file%%"${src_file##*'/'}"}"
 	initial_branch="$(git rev-parse --abbrev-ref HEAD)"
 	initial_branch="$(git rev-parse --abbrev-ref HEAD)"
 	initial_commitish="$(git rev-parse HEAD)"
 	initial_commitish="$(git rev-parse HEAD)"
 
 
@@ -82,6 +85,11 @@ init()
 		exit 1
 		exit 1
 	fi
 	fi
 
 
+	if [ -n "${src_dir##*'/scripts/'}" ]; then
+		echo "This script '${src_file}' is not in the scripts subdirectory, this is unexpected, cannot continue."
+		exit 1
+	fi
+
 	source_version="${source_version#v}"
 	source_version="${source_version#v}"
 	target_version="${target_version#v}"
 	target_version="${target_version#v}"
 
 
@@ -90,20 +98,16 @@ init()
 
 
 bump_kernel()
 bump_kernel()
 {
 {
-	platform_name="${platform_name##*'/'}"
-
-	if [ -z "${platform_name:-}" ]; then
-		platform_name="${PWD##*'/'}"
+	if [ -z "${platform_name}" ] || \
+	   [ -d "${PWD}/image" ]; then
+		platform_name="${PWD}"
 	fi
 	fi
+	platform_name="${platform_name##*'/'}"
 
 
-	if [ "${PWD##*'/'}" = "${platform_name}" ]; then
-		_target_dir='./'
-	else
-		_target_dir="target/linux/${platform_name}"
-	fi
+	_target_dir="${src_dir}/../target/linux/${platform_name}"
 
 
 	if [ ! -d "${_target_dir}/image" ]; then
 	if [ ! -d "${_target_dir}/image" ]; then
-		e_err 'Cannot find target linux directory.'
+		e_err "Cannot find target linux directory '${_target_dir:-not defined}'. Not in a platform directory, or -p not set."
 		exit 1
 		exit 1
 	fi
 	fi