forked from PeterPawn/modfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_modscripts
executable file
·96 lines (96 loc) · 4.2 KB
/
run_modscripts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /bin/sh
# vim: set tabstop=4 shiftwidth=4 syntax=sh highlight=on
# SPDX-License-Identifier: GPL-2.0-or-later
modfs_version=0.8.2-140120231234
usage()
{
printf "run_modscripts, version 0.2\n\n"
printf "(C) 2020 P. Haemmerlein ([email protected])\n\n"
printf "Usage:\n"
printf " ${0##*/} fritzos_directory [modscript_directory]\n\n"
printf "Apply all 'modscript' files found in the directory from 2nd argument\n"
printf "(or './modscripts', if the argument was omitted) to the unpacked\n"
printf "FRITZ!OS firmware structure in the specified directory.\n\n"
printf "Access flags of 'modscript' files will be ignored and any existing\n"
printf "'custom_modscripts' file gets ignored, too.\n\n"
printf "Only the 'install' and 'postcheck' steps will be executed for each found\n"
printf "script, any precheck action is skipped.\n\n"
printf "Provide only the 'modscript' files in the directory (from 2nd argument),\n"
printf "which you want to get applied. Duplicate invocations of a script (what\n"
printf "may lead to duplicate modifications and finally to misbehavior of the\n"
printf "modified firmware) are not handled here.\n"
printf "Additional required scripts will be searched in './bin/scripts', ensure\n"
printf "the usual directory structure of the 'modfs' project is present.\n"
printf "The final exit code of this script will be the maximum of any exit code\n"
printf "from 'postcheck' calls to the provided/applied scripts.\n"
}
if [ -z "$1" ]; then
usage 1>&2
exit 1
fi
export MODFS_DIR="$(pwd)"
target_dir="$(readlink -f -- "$1")"
if ! [ -d "$1" ]; then
printf "The specified firmware directory (\"%s\") is invalid.\a\n" "$target_dir" 1>&2
exit 1
fi
scripts_dir="$(readlink -f -- "${2:-./modscripts}")"
if ! [ -d "$1" ]; then
printf "Directory for modifications (\"%s\") is not a valid one.\a\n" "$scripts_dir" 1>&2
exit 1
fi
tempdir="${TMP:-${TMPDIR:-/tmp}}"
if ! [ -x "$(command -v busybox 2>/dev/null)" ]; then
printf "Missing a BusyBox file for this system.\a\n" 1>&2
exit 1
fi
busybox="$(command -v busybox)"
if ! [ -x "bin/scripts/extract_version_values" ]; then
printf "Missing support files, unpack/provide the whole directory structure from 'modfs' project.\a\n" 1>&2
exit 1
fi
version_values="$(bin/scripts/extract_version_values "$target_dir" -m MODFS_ 2>/dev/null)"
if [ -z "$version_values" ]; then
printf "\"%s\" seems to be not an unpacked FRITZ!OS structure - so this script was unable to extract needed values from this directory.\a\n" "$target_dir" 1>&2
exit 1
fi
export TARGET_KERNEL_VERSION="$(printf "%s\n" "$version_values" | sed -n -e "s|^MODFS_KernelVersion=\"\(.*\)\"\$|\1|p")"
export TARGET_SYSTEM_VERSION="$(printf "%s\n" "$version_values" | sed -n -e "s|^MODFS_Version=\"\(.*\)\"\$|\1|p")"
export TARGET_SYSTEM_SUBVERSION="$(printf "%s\n" "$version_values" | sed -n -e "s|^MODFS_Subversion=\"\(.*\)\"\$|\1|p")"
export TARGET_SYSTEM_DATE="$(printf "%s\n" "$version_values" | sed -n -e "s|^MODFS_Date=\"\(.*\)\"\$|\1|p")"
export TARGET_BRANDINGS="$(printf "%s\n" "$version_values" | sed -n -e "s|^MODFS_Brandings=\"\(.*\)\"\$|\1|p")"
eval export $(printf "%s\n" "$version_values" | sed -e ":x;\$!N;s/\n/ /;tx")
set -- $TARGET_BRANDINGS
while [ -n "$1" ]; do
if [ "$1" = "avm" ]; then
export TARGET_BRANDING="avm"
break
elif [ "$1" = "avme" ]; then
export TARGET_BRANDING="avme"
break
fi
shift
done
if [ -z "$TARGET_BRANDING" ]; then
set -- $TARGET_BRANDINGS
export TARGET_BRANDING="$1"
fi
export TMP="$tempdir"
export TMPDIR="$tempdir"
export HWRevision="000"
mkdir -p "bin/000/" 2>/dev/null
[ -x "bin/000/busybox" ] || ln -sf "$busybox" "bin/000/busybox" 2>/dev/null
export home=.
maxpostrc=0
for modscript in $(find "$scripts_dir" -maxdepth 1 -type f -or -type l | sort); do
printf "Running script '%s' ...\n" "${modscript##*/}" 1>&2
$busybox sh "$modscript" "de" "$target_dir" "auto" "install"
rc=$?
$busybox sh "$modscript" "de" "$target_dir" "auto" "postcheck"
postrc=$?
printf "Finished script '%s', rc=%d\n" "${modscript##*/}" "$rc" 1>&2
[ $postrc -ne 0 ] && printf "\033[91mPost-check for script \"%s\" failed, rc=%d\n\033[0m" "${modscript##*/}" "$postrc" 1>&2
[ $postrc -gt $maxpostrc ] && maxpostrc=$postrc
done
printf "%s\n" "$modfs_version" > "$target_dir/etc/.modfs_version"
exit $maxpostrc