-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentware-install.sh
163 lines (138 loc) · 3.5 KB
/
entware-install.sh
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
#!/bin/sh
set -e
cleanup() {
echo "Encountered error. Cleaning up and quitting..."
# get out of /opt so it can be unmounted
cd /home/root
if [ -d /opt ]
then
umount /opt
rm /opt -rf
fi
if [ -d /home/root/.entware ]
then
rm /home/root/.entware -rf
fi
if [ -f /etc/systemd/system/opt.mount ]
then
rm /etc/systemd/system/opt.mount
fi
}
trap cleanup ERR
unset LD_LIBRARY_PATH
unset LD_PRELOAD
echo "Info: Checking for prerequisites and creating folders..."
if [ -d /opt ]
then
echo "Failsafe: folder /opt exists! Quitting..."
exit 1
else
if [ -d /home/root/.entware ]
then
echo "Failsafe: folder /home/root/.entware exists! Quitting..."
exit 1
else
mkdir /opt
# mount /opt in /home for more storage space
mkdir -p /home/root/.entware
mount --bind /home/root/.entware /opt
fi
fi
# create systemd mount unit to mount over /opt on reboot
cat >/etc/systemd/system/opt.mount <<EOF
[Unit]
Description=Bind mount over /opt to give entware more space
DefaultDependencies=no
Conflicts=umount.target
Before=local-fs.target umount.target
[Mount]
What=/home/root/.entware
Where=/opt
Type=none
Options=bind
[Install]
WantedBy=local-fs.target
EOF
systemctl daemon-reload
systemctl enable opt.mount
# no need to create many folders. entware-opt package creates most
for folder in bin etc lib/opkg tmp var/lock
do
if [ -d "/opt/$folder" ]
then
echo "Warning: Folder /opt/$folder exists!"
echo "Warning: In case of error please clean /opt folder and try again."
else
mkdir -p /opt/$folder
fi
done
echo "Deploying opkg package manager..."
DLOADER="ld-linux-aarch64.so.1"
URL=http://bin.entware.net/aarch64-k3.10/installer
wget $URL/opkg -O /opt/bin/opkg
chmod 755 /opt/bin/opkg
wget $URL/opkg.conf -O /opt/etc/opkg.conf
wget $URL/ld-2.27.so -O /opt/lib/ld-2.27.so
wget $URL/libc-2.27.so -O /opt/lib/libc-2.27.so
wget $URL/libgcc_s.so.1 -O /opt/lib/libgcc_s.so.1
wget $URL/libpthread-2.27.so -O /opt/lib/libpthread-2.27.so
# validate integrity of downloaded files
precomputed_hash="39bd1d783909ea0eb63f6e9888935e6b -"
hash=$(cat /opt/bin/* /opt/etc/* /opt/lib/* | md5sum)
if [ "$hash" = "$precomputed_hash" ]
then
echo "File integrity check: pass."
else
echo "File integrity check: fail."
exit 1
fi
cd /opt/lib
chmod 755 ld-2.27.so
ln -s ld-2.27.so $DLOADER
ln -s libc-2.27.so libc.so.6
ln -s libpthread-2.27.so libpthread.so.0
/opt/bin/opkg update
/opt/bin/opkg install entware-opt wget wget-ssl ca-certificates
# switch to wget compiled w/ ssl for https
rm /opt/bin/wget
ln -s /opt/libexec/wget-ssl /opt/bin/wget
sed -i 's|http://|https://|g' /opt/etc/opkg.conf
# Fix for multiuser environment
chmod 777 /opt/tmp
# now try create symlinks - it is a std installation
if [ -f /etc/passwd ]
then
ln -sf /etc/passwd /opt/etc/passwd
else
cp /opt/etc/passwd.1 /opt/etc/passwd
fi
if [ -f /etc/group ]
then
ln -sf /etc/group /opt/etc/group
else
cp /opt/etc/group.1 /opt/etc/group
fi
if [ -f /etc/shells ]
then
ln -sf /etc/shells /opt/etc/shells
else
cp /opt/etc/shells.1 /opt/etc/shells
fi
if [ -f /etc/shadow ]
then
ln -sf /etc/shadow /opt/etc/shadow
fi
if [ -f /etc/gshadow ]
then
ln -sf /etc/gshadow /opt/etc/gshadow
fi
if [ -f /etc/localtime ]
then
ln -sf /etc/localtime /opt/etc/localtime
fi
if [ -f $FILE ]; then
echo 'PATH=/opt/bin:/opt/sbin:$PATH' >> ~/.bashrc
else
echo 'PATH=/opt/bin:/opt/sbin:$PATH' > ~/.bashrc
fi
echo "Entware installation: successful."