-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrop_ver.sh
More file actions
executable file
·193 lines (166 loc) · 5.57 KB
/
drop_ver.sh
File metadata and controls
executable file
·193 lines (166 loc) · 5.57 KB
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
#!/bin/bash
set -e
# Saving arguments for later
ARGS=("$@")
# Setting usage message
USAGE="$0 - A simple bash script to create the latest Dropbox slackbuild.\n
Options - [path to dropbox.info] [-h||--help] [-y||--yes] [-n||--no]\n
\thelp\t- Print this message and exit.\n
\tyes\t- If set, package will be created, otherwise there is a prompt.\n
\tno\t- No matter what, always stop after version is prompted."
# Setting prompt message
PROMPT="Do you want to continue with the SlackBuild creation? (Y/N)"
# I don't want to go over millions of arguments
if [ ${#ARGS[@]} -gt 5 ] || [ ${#ARGS[@]} -lt 1 ]
then
echo -e "$USAGE"
exit 1
fi
# Setting flags
HELP=false
YES=false
NO=false
for ARG in "${ARGS[@]}"
do
if [[ $ARG == "-h" || $ARG == "--help" ]]
then
export HELP=true
fi
if [[ $ARG == "-y" || $ARG == "--yes" ]]
then
export YES=true
fi
if [[ $ARG == "-n" || $ARG == "--no" ]]
then
export NO=true
fi
done
# If HELP, lets echo and stop here.
if $HELP
then
echo -e "$USAGE"
exit 0
fi
# Creating a work space
TMP_DIR=/tmp/drop-ver
rm -rf $TMP_DIR
mkdir $TMP_DIR
LANDING="$TMP_DIR/dropbox-landing"
LATEST_PAGE="$TMP_DIR/latest_version-page"
# This is the URL with the most up-to-date release notes
URL="https://www.dropboxforum.com/t5/Desktop-client-builds/bd-p/101003016"
# Sourcing the info file
if [ -r "$1" ]
then
echo "Using $1 as source"
source "$1"
else
echo -e "$USAGE"
fi
# Some sanity
if [ ! "$VERSION" ] || [ ! "$DOWNLOAD" ]
then
echo "Invalid info file"
exit 1
fi
# Checking for latest changes
echo "Testing for latest online version"
lynx --dump "$URL" > "$TMP_DIR/dropbox-landing"
STABLE_LINK_NUMBER=$(grep -A2 "Most recent builds" "$LANDING" | grep "Stable" | cut -d "]" -f 1 | cut -d "[" -f 2)
STABLE_LINK_URL=$(grep http "$LANDING" | grep " ${STABLE_LINK_NUMBER}. " | awk '{print $NF}')
lynx --dump "$STABLE_LINK_URL" > "$LATEST_PAGE"
ONLINE_VER=$(head -n 1 "$LATEST_PAGE" | awk '{print $4}')
echo "Got latest online version: $ONLINE_VER"
# Is the online version larger then the current one?
BIGGER=$(echo -ne "$ONLINE_VER\n$VERSION" | sort -V | tail -n 1)
if [ "$BIGGER" != "$VERSION" ]
then
echo "Online version ($ONLINE_VER) is newer then current version ($VERSION)"
else
echo "Current version in the slackbuild is the latest"
if ! $YES
then
echo "$PROMPT"
read -r input
if ! [[ $input == "Y" || $input == "y" ]]
then
echo "Operation aborted by user"
exit 0
fi
fi
fi
# If we set -n, just exit after the versions are shown.
if $NO
then
exit 0
fi
# If we set -y continue, otherwise promt and decide later.
if ! $YES
then
echo "$PROMPT"
read -r input
if ! [[ $input == "Y" || $input == "y" ]]
then
echo "Operation aborted by user"
exit 0
fi
fi
set -x
ARCH_32_LINK_NUM=$(grep "Linux" "$LATEST_PAGE" | grep "Installer" | grep -E -o ".[0-9].x86 " | cut -d "]" -f 1)
ARCH_32_LINK_URL=$(grep http "$LATEST_PAGE" | grep " ${ARCH_32_LINK_NUM}. " | awk '{print $NF}')
FILE_32=$(echo "$ARCH_32_LINK_URL" | rev | cut -d "/" -f 1 | rev)
ARCH_64_LINK_NUM=$(grep "Linux" "$LATEST_PAGE" | grep "Installer" | grep -E -o ".[0-9].x86_64" | cut -d "]" -f 1)
ARCH_64_LINK_URL=$(grep http "$LATEST_PAGE" | grep " ${ARCH_64_LINK_NUM}. " | awk '{print $NF}')
FILE_64=$(echo "$ARCH_64_LINK_URL" | rev | cut -d "/" -f 1 | rev)
# Copying stuff elsewhere so we won't overwrite the original slackbuild.
INF_PATH=$(realpath "$1" | xargs dirname)
cp -R "$INF_PATH"/* $TMP_DIR
cd "$TMP_DIR" || exit 1
sed -i 's/'$VERSION'/'$ONLINE_VER'/g' dropbox.info
sed -i 's/:-'$VERSION'/:-'$ONLINE_VER'/g' dropbox.SlackBuild
# Resource the info file again, now with the new version info.
source dropbox.info
# Getting the binaries
echo "Downloading packages."
wget -nc "$ARCH_32_LINK_URL"
wget -nc "$ARCH_64_LINK_URL"
# Getting the new md5s from the downloaded files and replacing them in
# the info file.
MD5_32=$(md5sum "$FILE_32" | cut -d " " -f 1)
MD5_64=$(md5sum "$FILE_64" | cut -d " " -f 1)
LOG_LINE=$(grep -nr "SlackBuild changelog" dropbox.SlackBuild | cut -d ":" -f 1)
ENTRY_LINE=$(( LOG_LINE + 1 ))
sed -i 's/'$MD5SUM'/'$MD5_32'/g' dropbox.info
sed -i 's/'$MD5SUM_x86_64'/'$MD5_64'/g' dropbox.info
sed -i "${ENTRY_LINE}i# $(date +%d/%b/%Y) * Updated to latest version $ONLINE_VER" dropbox.SlackBuild
echo "SlackBuild was updated to version $ONLINE_VER"
ENTRY_NUM=$(grep -nr "\#.*/20" dropbox.SlackBuild | wc -l)
if [ "$ENTRY_NUM" -gt 15 ]
then
LAST_ENTRY=$(grep -nr "\#.*/20" dropbox.SlackBuild | tail -n 1 | cut -d ":" -f 1)
ENTRY_END=$(grep -nr "###" dropbox.SlackBuild | tail -n -1 | cut -d ":" -f 1)
ENTRY_END=$(( "$ENTRY_END" - 1 ))
sed -i "${LAST_ENTRY},${ENTRY_END}d" dropbox.SlackBuild
fi
# Copying the new .info and .SlackBuild back to the original path and
# packaging the new slackbuild.
cp -a dropbox.info dropbox.SlackBuild "$INF_PATH"
cd "$INF_PATH" || exit 1
cd ..
rm -rf dropbox.tar.gz
tar cf dropbox.tar dropbox
gzip -9 dropbox.tar
# Summarizing it up in CLI, Notify and Zenity.
echo "$TMP_DIR contains the latest script and binary packages should you want to create a packge."
if command -v notify-send &> /dev/null
then
notify-send "New Dropbox Version" "Dropbox version $ONLINE_VER is ready to be created in $TMP_DIR" &> /dev/null &
else
echo "Can't find notify-send so not using that"
fi
if command -v zenity &> /dev/null
then
zenity --info --title "New Dropbox Version" --text "There is a new Dropbox version $ONLINE_VER waiting to be created in $TMP_DIR" &> /dev/null &
else
echo "Can't find zenity so not using that"
fi