-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxupdate.sh
executable file
·168 lines (145 loc) · 4.61 KB
/
xupdate.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
164
165
166
167
168
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export XDIR=$SCRIPT_DIR
export XADDONSDIR=$XDIR/package/addons
FEEDSDIR=$XDIR/package/feeds
ADDONSCFG=$XDIR/_addons.config
ADDONSNSS=$XDIR/_addons_nss.config
. ./xcommon.sh
OPT_FULL_UPDATE=false
USE_GITHUB_SRC=false
while getopts "f" opt; do
case $opt in
f) OPT_FULL_UPDATE=true;;
g) USE_GITHUB_SRC=true;;
esac
done
[ ! -d "$FEEDSDIR" ] && OPT_FULL_UPDATE=true
rm -rf tmp
if [ "$OPT_FULL_UPDATE" = "true" ]; then
rm -rf feeds/luci.tmp
rm -rf feeds/packages.tmp
#rm -rf feeds
#rm -rf package/feeds
rm -rf staging_dir/packages
rm -rf $XADDONSDIR
fi
#git reset --hard HEAD
git reset --hard HEAD~50
#git revert HEAD~50..HEAD
#git reset --hard HEAD
git fetch
[ "$?" != "0" ] && die "Can't fetch current repository"
git pull --force "origin" &> /dev/null
[ "$?" != "0" ] && die "Can't pull current repository"
CUR_BRANCH=$( git rev-parse --abbrev-ref HEAD )
git reset --hard origin/$CUR_BRANCH
[ "$?" != "0" ] && die "Can't reset current repository"
rm -f feeds.conf
cp -f feeds.conf.default feeds.conf
if [ "$USE_GITHUB_SRC" = "true" ]; then
sed -i -e 's|https://git.openwrt.org/feed/|https://github.com/openwrt/|' feeds.conf
sed -i -e 's|https://git.openwrt.org/project/|https://github.com/openwrt/|' feeds.conf
fi
feed_lst=$( get_cfg_feed_lst "$ADDONSCFG" )
for feed in $feed_lst; do
value=$( get_cfg_feed_url "$ADDONSCFG" $feed )
#echo "$feed = '$value'"
echo "src-git $feed $value" >> feeds.conf
done
if is_nss_repo "$XDIR"; then
feed_lst=$( get_cfg_feed_lst "$ADDONSNSS" )
for feed in $feed_lst; do
value=$( get_cfg_feed_url "$ADDONSNSS" $feed )
#echo "$feed = '$value'"
echo "src-git $feed $value" >> feeds.conf
done
fi
FULL_VERSION=$( grep '^VERSION_NUMBER:=$(if' $XDIR/include/version.mk 2>/dev/null )
[ -z "$FULL_VERSION" ] && { echo "ERROR: Cannot find VERSION_NUMBER"; exit 1; }
FULL_VERSION=$( echo $FULL_VERSION | cut -d"," -f3 | cut -d")" -f1 )
echo 'FULL_VERSION = "'$FULL_VERSION'"'
CUR_VER=
CUR_SNAPSHOT=
if [ "$FULL_VERSION" = "SNAPSHOT" ]; then
CUR_SNAPSHOT=1
echo "SNAPSHOT detected."
else
if ! echo "$FULL_VERSION" | grep -q "." ; then
echo "ERROR: Incorrect branch version!"
exit 13
fi
CUR_VER=${FULL_VERSION:0:5}
VER_DELIM=${FULL_VERSION:5:1}
if [ "$VER_DELIM" = "-" ]; then
CUR_SNAPSHOT=$CUR_VER
echo "snapshot detected."
fi
fi
echo 'CUR_VER = "'$CUR_VER'"'
function update_feed_head()
{
local FEEDNAME=$1
local FEEDURL=$2
local FEEDHEADLIST="$XDIR/feed_$FEEDNAME.list"
git ls-remote -h $FEEDURL > $FEEDHEADLIST
HEADHASH=$( grep "refs/heads/openwrt-$CUR_VER" $FEEDHEADLIST 2>/dev/null )
if [ -z "$HEADHASH" ]; then
echo "ERROR: Not found branch refs/heads/openwrt-$CUR_VER for feed $FEEDNAME"
exit 17
fi
HEADHASH=$( echo $HEADHASH | cut -d" " -f1 )
echo "For feed '$FEEDNAME' founded fresh hash = $HEADHASH"
# src-git packages https://git.openwrt.org/feed/packages.git^b5ed85f6e94aa08de1433272dc007550f4a28201
NEWLINE="src-git $FEEDNAME $FEEDURL^$HEADHASH"
NEWLINE=$( sed_adapt "$NEWLINE" )
sed -i "s/^src-git $FEEDNAME .*/$NEWLINE/g" feeds.conf
if ! grep -q "$NEWLINE" "feeds.conf" ; then
echo "ERROR: Cannot patch file feeds.conf"
exit 18
fi
echo "Changed URL for feed '$FEEDNAME' = $FEEDURL^$HEADHASH"
}
if [ "$CUR_SNAPSHOT" != "1" ]; then
update_feed_head packages https://github.com/openwrt/packages.git
update_feed_head luci https://github.com/openwrt/luci.git
update_feed_head routing https://github.com/openwrt/routing.git
update_feed_head telephony https://github.com/openwrt/telephony.git
fi
if [ "$OPT_FULL_UPDATE" = "true" ]; then
./scripts/feeds update -a
./scripts/feeds install -a
fi
CLONE_ADDONS=true
if [ "$CLONE_ADDONS" = "true" ]; then
mkdir -p $XADDONSDIR
pkg_lst=$( get_cfg_expkg_lst "$ADDONSCFG" )
for pkg in $pkg_lst; do
value=$( get_cfg_expkg_url "$ADDONSCFG" $pkg )
#echo "$pkg = '$value'"
url=$( echo "$value" | cut -d " " -f 1 )
branch=$( echo "$value" | cut -d " " -f 2 )
#echo "'$url' / '$branch'"
if [ ! -d "$XADDONSDIR/$pkg" ]; then
git clone $url -b $branch $XADDONSDIR/$pkg
[ "$?" != "0" ] && die "Can't clone repository '$url'"
fi
done
if [ "$OPT_FULL_UPDATE" = "true" ]; then
./scripts/feeds install -a
fi
fi
if [ "$OPT_FULL_UPDATE" = "true" ]; then
if [ -f "$XDIR/vermagic_update.sh" ]; then
./vermagic_update.sh ipq806x generic
./vermagic_update.sh qualcommax ipq807x
./vermagic_update.sh ramips mt7621
./vermagic_update.sh mediatek mt7622
./vermagic_update.sh mediatek filogic
fi
fi
if [ -f "$XDIR/luci_dispatcher.sh" ]; then
chmod 755 ./luci_dispatcher.sh
./luci_dispatcher.sh
fi
echo "All git sources updated!"