forked from openwrt-stuff/firmware-mod-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.inc
209 lines (200 loc) · 6.74 KB
/
shared.inc
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/sh
SHARED_VERSION="$( cat firmware_mod_kit_version.txt )"
#
# Title: shared.inc
# Author: Jeremy Collake <[email protected]>
#
# Shared functions
#
#
#
#################################################################
WarningPrompt ()
{
read -p " [ Press any key to contrinue, or abort now with break signal (CTRL-C) ]"
}
#################################################################
PlatformIdentify ()
{
SYSNAME=`uname`
if [ "$SYSNAME" = "Linux" ]; then
echo " LINUX system detected. Compatibility ok."
elif [ `expr "$SYSNAME" : "Darwin"` = 6 ]; then
echo " OS X system detected. **BETA TESTING**"
echo " This platform is not well tested."
WarningPrompt
elif [ `expr "$SYSNAME" : "CYGWIN"` = 6 ]; then
echo " CYGWIN system detected. **BETA TESTING** Built images may have problems."
echo " This platform is not well tested."
WarningPrompt
else
echo " Unknown system detected. Compatibility state is unknown."
WarningPrompt
fi
}
#################################################################
TestFileSystemExit ()
{
INPUT_FILE=$1
WORKING_DIR=$2
echo " Testing file system of $WORKING_DIR ..."
mkdir -p "$WORKING_DIR" >> /dev/null 2>&1
rm "$WORKING_DIR/test12345612.tmp" >> /dev/null 2>&1
echo test > "$WORKING_DIR/test12345612.tmp"
if [ -e "$WORKING_DIR/teST12345612.tmp" ]; then
echo " WARNING: File system $WORKING_DIR is not case sensitive."
echo " For some firmwares this can cause troubles in the"
echo " built images that result in runtime errata or"
echo " even refuse to boot."
if [ $EXIT_ON_FS_PROBLEM = "1" ]; then
rm "$WORKING_DIR/test12345612.tmp" >> /dev/null 2>&1
exit 2
else
WarningPrompt
fi
fi
if [ ! -e "$WORKING_DIR/test12345612.tmp" ]; then
echo " ERROR: File system $WORKING_DIR is not writable."
rm "$WORKING_DIR/test12345612.tmp" >> /dev/null 2>&1
exit 3
fi
rm "$WORKING_DIR/test12345612.tmp" >> /dev/null 2>&1
}
#################################################################
# LinkToolsBinraries (srcfolder, destfolder)
#LinkToolsBinaries ()
#{
## deprecated v0.44
# ln -s -f $1/asustrx $2/asustrx
# ln -s -f $1/untrx $2/untrx
# ln -s -f $1/mksquashfs $2/mksquashfs
# ln -s -f $1/mksquashfs-lzma $2/mksquashfs-lzma
# ln -s -f $1/unsquashfs $2/unsquashfs
# ln -s -f $1/unsquashfs-lzma $2/unsquashfs-lzma
# ln -s -f $1/addpattern $2/addpattern
#}
#################################################################
CleanCWD ()
{
make clean >> cleanup.log 2>&1
rm -f src/*.log >> cleanup.log 2>&1
rm -f *.log >> cleanup.log 2>&1
rm -f *.o >> cleanup.log 2>&1
rm -f asustrx >> cleanup.log 2>&1
rm -f trx >> cleanup.log 2>&1
rm -f untrx >> cleanup.log 2>&1
rm -f addpattern >> cleanup.log 2>&1
rm -f mksquashfs >> cleanup.log 2>&1
rm -f mksquashfs-lzma >> cleanup.log 2>&1
rm -f unsquashfs >> cleanup.log 2>&1
rm -f unsquashfs-lzma >> cleanup.log 2>&1
# cygwin
rm -f asustrx.exe >> cleanup.log 2>&1
rm -f trx.exe >> cleanup.log 2>&1
rm -f untrx.edxe >> cleanup.log 2>&1
rm -f addpattern.exe >> cleanup.log 2>&1
rm -f mksquashfs.exe >> cleanup.log 2>&1
rm -f mksquashfs-lzma.exe >> cleanup.log 2>&1
rm -f unsquashfs.exe >> cleanup.log 2>&1
rm -f unsquashfs-lzma.exe >> cleanup.log 2>&1
# old name for untrx, deprecated
rm -f extfirmware* >> cleanup.log 2>&1
# trx replaced with asustrx
rm -f trx.c >> cleanup.log 2>&1
}
Cleanup ()
{
CleanCWD
cd src
CleanCWD
cd ..
}
#################################################################
# BuildTools ( LOG_FILE )
#
#
BuildTools ()
{
local LOG_FILE="$1"
#################################################################
echo " Building tools ..."
#make -C src > $LOG_FILE 2>&1
cd src
./configure && make > $LOG_FILE 2>&1
cd -
if [ $? = 0 ]; then
echo " Build seems successful."
else
echo " ERROR - Build did not succeed. Check log file, you are probably"
echo " missing one or more necessary pre-requisites. See docs for"
echo " a list of pre-requsites."
if [ -e "src/untrx" ]; then
echo " CONTINUING anyway, attempting to use pre-built binaries (x32 linux)"
else
exit 1
fi
fi
#################################################################
local UNAME2=`uname`
if [ `expr "$UNAME2" : "CYGWIN"` = 6 ]; then
ln -s -f "src/asustrx.exe" "src/asustrx" >> $LOG_FILE 2>&1
ln -s -f "src/untrx.exe" "src/untrx" >> $LOG_FILE 2>&1
ln -s -f "src/addpattern.exe" "src/addpattern" >> $LOG_FILE 2>&1
ln -s -f "src/squashfs-3.0/mksquashfs-lzma.exe" "src/squashfs-3.0/mksquashfs-lzma" >> $LOG_FILE 2>&1
ln -s -f "src/squashfs-3.0/unsquashfs-lzma.exe" "src/squashfs-3.0/unsquashfs-lzma" >> $LOG_FILE 2>&1
ln -s -f "src/squashfs-3.0/mksquashfs.exe" "src/squashfs-3.0/mksquashfs" >> $LOG_FILE 2>&1
ln -s -f "src/squashfs-3.0/unsquashfs.exe" "src/squashfs-3.0/unsquashfs" >> $LOG_FILE 2>&1
fi
#################################################################
# cygwin: this can not be called before above block (no *. bins exist)
#LinkToolsBinaries "src" "."
}
#################################################################
# DeprecateOldVersion ()
#
# This is to automatically cleanup stuff that's been moved or removed
# since older versions. Aren't I nice?
#
DeprecateOldVersion ()
{
echo " Detected leftover stuff from an old version, cleaning"
mkdir "src_backup" >> upgrade.log 2>&1
mv "*.c" "src_old_backup" >> upgrade.log 2>&1
mv "*.h" "src_old_backup" >> upgrade.log 2>&1
mv "lzma" "src_old_backup" >> upgrade.log 2>&1
mv "Makefile" "src_old_backup" >> upgrade.log 2>&1
mv src/cramfs-1.1 src_backup/ >> upgrade.log 2>&1
# remove symbolic links from v0.43 and below
rm "mksquashfs" >> upgrade.log 2>&1
rm "unsquashfs" >> upgrade.log 2>&1
rm "mksquashfs-lzma" >> upgrade.log 2>&1
rm "unsquashfs-lzma" >> upgrade.log 2>&1
rm "untrx" >> upgrade.log 2>&1
rm "asustrx" >> upgrade.log 2>&1
rm "addpattern" >> upgrade.log 2>&1
# remove old sources
mv src/untrx.c src_old_backup >> upgrade.log 2>&1
mv src/mksquashfs* src_old_backup >> upgrade.log 2>&1
mv src/unsquashfs* src_old_backup >> upgrade.log 2>&1
mv src/read_* src_old_backup >> upgrade.log 2>&1
mv src/sort* src_old_backup >> upgrade.log 2>&1
mv src/global.h src_old_backup >> upgrade.log 2>&1
Cleanup
}
TestIsRootAndExitIfNot()
{
if [ $(id -u) != "0" ]; then
echo " ERROR: You must be 'root' when extracting and building some images."
echo " This is because some images need to create devices in your fs."
echo " For DD-WRT, do NOT extract or build as root, use standard user."
exit 1
fi
}
TestIsRoot()
{
if [ $(id -u) != "0" ]; then
echo " WARNING: You must be 'root' when extracting and building some images."
echo " This is because some images need to create devices in your fs."
echo " For DD-WRT, do NOT extract or build as root, use standard user."
fi
}