This repository has been archived by the owner on Dec 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
entware-setup.sh
executable file
·123 lines (102 loc) · 3.07 KB
/
entware-setup.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
#!/bin/sh
BOLD="\033[1m"
NORM="\033[0m"
INFO="$BOLD Info: $NORM"
ERROR="$BOLD *** Error: $NORM"
WARNING="$BOLD * Warning: $NORM"
INPUT="$BOLD => $NORM"
i=1 # Will count available partitions (+ 1)
cd /tmp
echo -e "$INFO This script will guide you through the Entware installation."
echo -e "$INFO Script modifies \"entware\" folder only on the chosen drive,"
echo -e "$INFO no other data will be changed. Existing installation will be"
echo -e "$INFO replaced with this one. Also some start scripts will be installed,"
echo -e "$INFO the old ones will be saved on Entware partition with name"
echo -e "$INFO like /tmp/mnt/sda1/jffs_scripts_backup.tgz"
echo
case $(uname -m) in
armv7l)
PART_TYPES='ext2|ext3|ext4'
INST_URL='http://pkg.entware.net/binaries/armv7/installer/entware_install.sh'
;;
mips)
PART_TYPES='ext2|ext3'
INST_URL='http://pkg.entware.net/binaries/mipsel/installer/installer.sh'
;;
*)
echo "This is unsupported platform, sorry."
;;
esac
echo -e "$INFO Looking for available partitions..."
for mounted in `/bin/mount | grep -E "$PART_TYPES" | cut -d" " -f3` ; do
isPartitionFound="true"
echo "[$i] --> $mounted"
eval mounts$i=$mounted
i=`expr $i + 1`
done
if [ $i == "1" ] ; then
echo -e "$ERROR No $PART_TYPES partitions available. Exiting..."
exit 1
fi
echo -en "$INPUT Please enter partition number or 0 to exit\n$BOLD[0-`expr $i - 1`]$NORM: "
read partitionNumber
if [ "$partitionNumber" == "0" ] ; then
echo -e $INFO Exiting...
exit 0
fi
if [ "$partitionNumber" -gt `expr $i - 1` ] ; then
echo -e "$ERROR Invalid partition number! Exiting..."
exit 1
fi
eval entPartition=\$mounts$partitionNumber
echo -e "$INFO $entPartition selected.\n"
entFolder=$entPartition/entware
if [ -d $entFolder ] ; then
echo -e "$WARNING Found previous installation, saving..."
mv $entFolder $entFolder-old_`date +\%F_\%H-\%M`
fi
echo -e "$INFO Creating $entFolder folder..."
mkdir $entFolder
if [ -d /tmp/opt ] ; then
echo -e "$WARNING Deleting old /tmp/opt symlink..."
rm /tmp/opt
fi
echo -e "$INFO Creating /tmp/opt symlink..."
ln -s $entFolder /tmp/opt
echo -e "$INFO Creating /jffs scripts backup..."
tar -czf $entPartition/jffs_scripts_backup_`date +\%F_\%H-\%M`.tgz /jffs/scripts/* >/dev/nul
echo -e "$INFO Modifying start scripts..."
cat > /jffs/scripts/services-start << EOF
#!/bin/sh
RC='/opt/etc/init.d/rc.unslung'
i=30
until [ -x "\$RC" ] ; do
i=\$((\$i-1))
if [ "\$i" -lt 1 ] ; then
logger "Could not start Entware"
exit
fi
sleep 1
done
\$RC start
EOF
chmod +x /jffs/scripts/services-start
cat > /jffs/scripts/services-stop << EOF
#!/bin/sh
/opt/etc/init.d/rc.unslung stop
EOF
chmod +x /jffs/scripts/services-stop
cat > /jffs/scripts/post-mount << EOF
#!/bin/sh
if [ "\$1" = "__Partition__" ] ; then
ln -nsf \$1/entware /tmp/opt
fi
EOF
eval sed -i 's,__Partition__,$entPartition,g' /jffs/scripts/post-mount
chmod +x /jffs/scripts/post-mount
if [ "$(nvram get jffs2_scripts)" != "1" ] ; then
echo -e "$INFO Enabling custom scripts and configs from /jffs..."
nvram set jffs2_scripts=1
nvram commit
fi
wget -qO - $INST_URL | sh