[5ec3a0b] | 1 | #!/bin/sh |
---|
| 2 | # |
---|
| 3 | # Download all the needed static js assets and put them in the |
---|
| 4 | # proper place |
---|
| 5 | # |
---|
| 6 | |
---|
| 7 | # Hints on curl: |
---|
| 8 | # -L - needed to follow redirections, which is needed for downloading release |
---|
| 9 | # tarballs from github |
---|
| 10 | # -O - keep the remote file name when saving it locally |
---|
| 11 | # -# - show progress bar |
---|
| 12 | |
---|
| 13 | # Set curl, unzip and tar full paths + default parameters/options |
---|
| 14 | GET="`which curl` -L -O -#" |
---|
| 15 | UNZIP="`which unzip` -q" |
---|
| 16 | TAR="`which tar` -zxf" |
---|
| 17 | |
---|
| 18 | # Temp dir where compressed files are downloaded, uncompressed, etc |
---|
| 19 | TMP=ow/static/tmp |
---|
| 20 | # Destination directory for all the components |
---|
| 21 | COMPONENTS=ow/static/components |
---|
| 22 | # Cache file, to keep track of which components have been installed |
---|
| 23 | # already |
---|
| 24 | CACHE=$COMPONENTS/js_deps.cache |
---|
| 25 | # Full path to where we run the script from |
---|
| 26 | CURRENT=`pwd` |
---|
| 27 | |
---|
| 28 | # Some repeated messages all over the script |
---|
| 29 | ALREADY_INSTALLED="is already installed, use --reinstall to install again" |
---|
| 30 | |
---|
| 31 | if [ ! -d ${CURRENT}/ow ]; then |
---|
| 32 | echo "Error: Please run this script inside the OpenWorkouts repository" |
---|
| 33 | exit 1 |
---|
| 34 | fi |
---|
| 35 | |
---|
| 36 | if [ ! -d ${TMP} ]; then |
---|
| 37 | mkdir ${TMP} |
---|
| 38 | fi |
---|
| 39 | |
---|
| 40 | if [ ! -d ${COMPONENTS} ]; then |
---|
| 41 | mkdir ${COMPONENTS} |
---|
| 42 | fi |
---|
| 43 | |
---|
| 44 | if [ ! -f ${CACHE} ]; then |
---|
| 45 | touch ${CACHE} |
---|
| 46 | fi |
---|
| 47 | |
---|
| 48 | # Look for the --reinstall parameter, which forces the reinstall of any |
---|
| 49 | # installed components |
---|
| 50 | REINSTALL=1 |
---|
| 51 | if [ "$1" == "--reinstall" ]; then |
---|
| 52 | REINSTALL=0 |
---|
| 53 | fi |
---|
| 54 | |
---|
| 55 | check_cache() { |
---|
| 56 | # Check the cache file, see if we can skip installing a component |
---|
| 57 | # |
---|
| 58 | # Expects 2 parameters, first one is the component name, second is |
---|
| 59 | # the version of that component |
---|
| 60 | grep -q "$1-$2" $CACHE |
---|
| 61 | res=$? |
---|
| 62 | return "$res" |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | # The next few functions will take care of download and "install" each |
---|
| 66 | # component. |
---|
| 67 | # |
---|
| 68 | # To Upgrade a component to a new version, change VERSION inside the function |
---|
| 69 | # and run the script. Fix the code inside the function if needed |
---|
| 70 | # |
---|
| 71 | # To Add a new component, add a new function, using one of the existing as |
---|
| 72 | # a base start. Some of them download js/css files directly, some of them |
---|
| 73 | # grab a zipped file or a tarball and uncompress it, copying over the needed |
---|
| 74 | # data to the proper place, just try to find out what fits best for the new |
---|
| 75 | # component and start from there. |
---|
| 76 | # |
---|
| 77 | # HINT: when installing a new component, comment the lines calling all the other |
---|
| 78 | # components install functions, so you do not have to wait for all components to |
---|
| 79 | # be installed. |
---|
| 80 | |
---|
| 81 | jquery() { |
---|
| 82 | NAME="jquery" |
---|
| 83 | VERSION=3.3.1 |
---|
| 84 | URL=https://code.jquery.com/${NAME}-${VERSION}.js |
---|
| 85 | check_cache ${NAME} ${VERSION} |
---|
| 86 | in_cache=$? |
---|
| 87 | if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then |
---|
| 88 | echo "${NAME}-${VERSION} $ALREADY_INSTALLED" |
---|
| 89 | else |
---|
| 90 | echo "> Installing ${NAME} ${VERSION}" |
---|
| 91 | if [ -d ${COMPONENTS}/${NAME} ]; then |
---|
| 92 | # Clean up, delete previous install before installing |
---|
| 93 | rm -r ${COMPONENTS}/${NAME} |
---|
| 94 | fi |
---|
| 95 | mkdir ${COMPONENTS}/${NAME} |
---|
| 96 | cd ${COMPONENTS}/${NAME} |
---|
| 97 | ${GET} ${URL} |
---|
| 98 | # Better to have a simple jquery.js, so we do not have to set an |
---|
| 99 | # specific version when loading it in the templates or assets |
---|
| 100 | ln -sf ${NAME}-${VERSION}.js ${NAME}.js |
---|
| 101 | cd ${CURRENT} |
---|
| 102 | echo "${NAME}-${VERSION}" >> ${CACHE} |
---|
| 103 | echo "< Installed ${NAME} ${VERSION}" |
---|
| 104 | fi |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | easy_autocomplete() { |
---|
| 108 | NAME="EasyAutocomplete" |
---|
| 109 | VERSION=1.3.4 |
---|
| 110 | URL=https://github.com/pawelczak/${NAME}/archive/${VERSION}.tar.gz |
---|
| 111 | check_cache ${NAME} ${VERSION} |
---|
| 112 | in_cache=$? |
---|
| 113 | if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then |
---|
| 114 | echo "${NAME}-${VERSION} $ALREADY_INSTALLED" |
---|
| 115 | else |
---|
| 116 | echo "> Installing ${NAME} ${VERSION}" |
---|
| 117 | if [ -d ${COMPONENTS}/${NAME} ]; then |
---|
| 118 | # Clean up, delete previous install before installing |
---|
| 119 | rm -r ${COMPONENTS}/${NAME} |
---|
| 120 | fi |
---|
| 121 | cd ${TMP} |
---|
| 122 | ${GET} ${URL} |
---|
| 123 | ${TAR} ${VERSION}.tar.gz |
---|
| 124 | cd ${CURRENT} |
---|
| 125 | mv ${TMP}/${NAME}-${VERSION}/dist ${COMPONENTS}/${NAME} |
---|
| 126 | echo "${NAME}-${VERSION}" >> ${CACHE} |
---|
| 127 | echo "< Installed ${NAME} ${VERSION}" |
---|
| 128 | fi |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | leaflet() { |
---|
| 132 | NAME="Leaflet" |
---|
| 133 | VERSION=1.3.4 |
---|
| 134 | URL=https://github.com/${NAME}/${NAME}/archive/v${VERSION}.tar.gz |
---|
| 135 | check_cache ${NAME} ${VERSION} |
---|
| 136 | in_cache=$? |
---|
| 137 | if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then |
---|
| 138 | echo "${NAME}-${VERSION} $ALREADY_INSTALLED" |
---|
| 139 | else |
---|
| 140 | echo "> Installing ${NAME} ${VERSION}" |
---|
| 141 | if [ -d ${COMPONENTS}/${NAME} ]; then |
---|
| 142 | # Clean up, delete previous install before installing |
---|
| 143 | rm -r ${COMPONENTS}/${NAME} |
---|
| 144 | fi |
---|
| 145 | cd ${TMP} |
---|
| 146 | ${GET} ${URL} |
---|
| 147 | ${TAR} v${VERSION}.tar.gz |
---|
| 148 | cd ${CURRENT} |
---|
| 149 | mv ${TMP}/${NAME}-${VERSION}/dist ${COMPONENTS}/${NAME} |
---|
| 150 | echo "${NAME}-${VERSION}" >> ${CACHE} |
---|
| 151 | echo "< Installed ${NAME} ${VERSION}" |
---|
| 152 | fi |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | leaflet_gpx() { |
---|
| 157 | NAME="leaflet-gpx" |
---|
| 158 | VERSION=1.4.0 |
---|
| 159 | URL=https://github.com/mpetazzoni/${NAME}/archive/v${VERSION}.tar.gz |
---|
| 160 | check_cache ${NAME} ${VERSION} |
---|
| 161 | in_cache=$? |
---|
| 162 | if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then |
---|
| 163 | echo "${NAME}-${VERSION} $ALREADY_INSTALLED" |
---|
| 164 | else |
---|
| 165 | echo "> Installing ${NAME} ${VERSION}" |
---|
| 166 | if [ -d ${COMPONENTS}/${NAME} ]; then |
---|
| 167 | # Clean up, delete previous install before installing |
---|
| 168 | rm -r ${COMPONENTS}/${NAME} |
---|
| 169 | fi |
---|
| 170 | cd ${TMP} |
---|
| 171 | ${GET} ${URL} |
---|
| 172 | ${TAR} v${VERSION}.tar.gz |
---|
| 173 | cd ${CURRENT} |
---|
| 174 | mv ${TMP}/${NAME}-${VERSION} ${COMPONENTS}/${NAME} |
---|
| 175 | echo "${NAME}-${VERSION}" >> ${CACHE} |
---|
| 176 | echo "< Installed ${NAME} ${VERSION}" |
---|
| 177 | fi |
---|
| 178 | } |
---|
| 179 | |
---|
[a0085a2] | 180 | leaflet_elevation() { |
---|
[5f05e83] | 181 | NAME="leaflet-elevation" |
---|
| 182 | VERSION="0.0.8" |
---|
| 183 | URL=https://github.com/Raruto/${NAME}/archive/${VERSION}.tar.gz |
---|
[a0085a2] | 184 | check_cache ${NAME} ${VERSION} |
---|
| 185 | in_cache=$? |
---|
| 186 | if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then |
---|
| 187 | echo "${NAME}-${VERSION} $ALREADY_INSTALLED" |
---|
| 188 | else |
---|
| 189 | echo "> Installing ${NAME} ${VERSION}" |
---|
| 190 | if [ -d ${COMPONENTS}/${NAME} ]; then |
---|
| 191 | # Clean up, delete previous install before installing |
---|
| 192 | rm -r ${COMPONENTS}/${NAME} |
---|
| 193 | fi |
---|
| 194 | cd ${TMP} |
---|
| 195 | ${GET} ${URL} |
---|
| 196 | ${TAR} ${VERSION}.tar.gz |
---|
| 197 | cd ${CURRENT} |
---|
| 198 | mv ${TMP}/${NAME}-${VERSION} ${COMPONENTS}/${NAME} |
---|
| 199 | echo "${NAME}-${VERSION}" >> ${CACHE} |
---|
| 200 | echo "< Installed ${NAME} ${VERSION}" |
---|
| 201 | fi |
---|
| 202 | } |
---|
[5ec3a0b] | 203 | |
---|
[8e5f92c] | 204 | pickadate() { |
---|
| 205 | NAME="pickadate" |
---|
| 206 | VERSION=3.5.6 |
---|
| 207 | URL=https://github.com/amsul/${NAME}.js/archive/${VERSION}.tar.gz |
---|
| 208 | check_cache ${NAME} ${VERSION} |
---|
| 209 | in_cache=$? |
---|
| 210 | if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then |
---|
| 211 | echo "${NAME}-${VERSION} $ALREADY_INSTALLED" |
---|
| 212 | else |
---|
| 213 | echo "> Installing ${NAME} ${VERSION}" |
---|
| 214 | if [ -d ${COMPONENTS}/${NAME} ]; then |
---|
| 215 | # Clean up, delete previous install before installing |
---|
| 216 | rm -r ${COMPONENTS}/${NAME} |
---|
| 217 | fi |
---|
| 218 | mkdir ${COMPONENTS}/${NAME} |
---|
| 219 | cd ${TMP} |
---|
| 220 | ${GET} ${URL} |
---|
| 221 | ${TAR} ${VERSION}.tar.gz |
---|
| 222 | cd ${CURRENT} |
---|
| 223 | mv ${TMP}/${NAME}.js-${VERSION}/lib/* ${COMPONENTS}/${NAME} |
---|
| 224 | echo "${NAME}-${VERSION}" >> ${CACHE} |
---|
| 225 | echo "< Installed ${NAME} ${VERSION}" |
---|
| 226 | fi |
---|
| 227 | } |
---|
| 228 | |
---|
[6d1b54b] | 229 | d3() { |
---|
| 230 | NAME="d3" |
---|
| 231 | VERSION=5.7.0 |
---|
| 232 | URL=https://github.com/${NAME}/${NAME}/releases/download/v${VERSION}/${NAME}.zip |
---|
| 233 | check_cache ${NAME} ${VERSION} |
---|
| 234 | in_cache=$? |
---|
| 235 | if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then |
---|
| 236 | echo "${NAME}-${VERSION} $ALREADY_INSTALLED" |
---|
| 237 | else |
---|
| 238 | echo "> Installing ${NAME} ${VERSION}" |
---|
| 239 | if [ -d ${COMPONENTS}/${NAME} ]; then |
---|
| 240 | # Clean up, delete previous install before installing |
---|
| 241 | rm -r ${COMPONENTS}/${NAME} |
---|
| 242 | fi |
---|
| 243 | cd ${TMP} |
---|
| 244 | ${GET} ${URL} |
---|
| 245 | ${UNZIP} ${NAME}.zip -d ${NAME} |
---|
| 246 | cd ${CURRENT} |
---|
| 247 | mv ${TMP}/${NAME} ${COMPONENTS}/ |
---|
| 248 | echo "${NAME}-${VERSION}" >> ${CACHE} |
---|
| 249 | echo "< Installed ${NAME} ${VERSION}" |
---|
| 250 | fi |
---|
| 251 | } |
---|
| 252 | |
---|
[778d53d] | 253 | jquery_dropdown() { |
---|
| 254 | # We need version "master", as the latest release does not work properly |
---|
| 255 | NAME="jquery-dropdown" |
---|
| 256 | VERSION=master |
---|
| 257 | URL=https://github.com/soundasleep/${NAME}/archive/${VERSION}.tar.gz |
---|
| 258 | check_cache ${NAME} ${VERSION} |
---|
| 259 | in_cache=$? |
---|
| 260 | if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then |
---|
| 261 | echo "${NAME}-${VERSION} $ALREADY_INSTALLED" |
---|
| 262 | else |
---|
| 263 | echo "> Installing ${NAME} ${VERSION}" |
---|
| 264 | if [ -d ${COMPONENTS}/${NAME} ]; then |
---|
| 265 | # Clean up, delete previous install before installing |
---|
| 266 | rm -r ${COMPONENTS}/${NAME} |
---|
| 267 | fi |
---|
| 268 | mkdir ${COMPONENTS}/${NAME} |
---|
| 269 | cd ${TMP} |
---|
| 270 | ${GET} ${URL} |
---|
| 271 | ${TAR} ${VERSION}.tar.gz |
---|
| 272 | cd ${CURRENT} |
---|
| 273 | mv ${TMP}/${NAME}-${VERSION}/jquery.dropdown.{css,js} ${COMPONENTS}/${NAME} |
---|
| 274 | echo "${NAME}-${VERSION}" >> ${CACHE} |
---|
| 275 | echo "< Installed ${NAME} ${VERSION}" |
---|
| 276 | fi |
---|
| 277 | } |
---|
| 278 | |
---|
[6d1b54b] | 279 | |
---|
[5ec3a0b] | 280 | echo "Installing JS dependencies in ${COMPONENTS}" |
---|
| 281 | |
---|
| 282 | jquery |
---|
| 283 | easy_autocomplete |
---|
| 284 | leaflet |
---|
| 285 | leaflet_gpx |
---|
[a0085a2] | 286 | leaflet_elevation |
---|
[8e5f92c] | 287 | pickadate |
---|
[6d1b54b] | 288 | d3 |
---|
[778d53d] | 289 | jquery_dropdown |
---|
[6d1b54b] | 290 | |
---|
[5ec3a0b] | 291 | |
---|
| 292 | # Clean up, remove the tmp directory |
---|
| 293 | echo "Cleaning up temp storage" |
---|
| 294 | rm -r ${TMP} |
---|