Skip to content

Commit

Permalink
Merge pull request #63 from gdcc/localinstall
Browse files Browse the repository at this point in the history
Local Install support
  • Loading branch information
qqmyers committed May 24, 2024
2 parents 19c7d07 + 889013c commit 5229ffc
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ or, to just change between versions after you've switched to using the gdcc repo

update externaltool set toolurl=REPLACE(toolurl, 'v1.2', 'v1.3');

## Fully Local Installation
By default, previewers reference several JavaScript libraries and style files from their original web locations. If you would like to have a local installation that doesn't require access to other websites, you can use the localinstall.sh script. Download the repository to your local machine, change to the root directory where the localinstall.sh script is and run

./localinstall.sh previewers/v1.4 https://<your host>/<your base path to the previewers>

and the script will download all external JavaScript and css files required by the previewers for the version you specified and will update the example configuration commands in the 6.1curlcommands.md, 5.2curlcommands.md and pre5.2curlcommands.md files to reference your local URL. In the case above, using the parameters previewers/v1.4 and https://example.com/path would result example curl commands where the TextPreview.html would be available at https://example.com/path/previewers/v1.4/TextPreview.html.

## How do they work?

Expand Down
70 changes: 70 additions & 0 deletions localinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

dirLocal=$(pwd)

# go to the version folder
if [ -z "$1" ]; then
echo "Provide the relative path to the previewer version you wish to make an all-local instance of, e.g. previewers/v1.4."
exit 1
fi

if [ -z "$2" ]; then
echo "To update the example curl commands, add the base URL for your local previewer installation as the second parameter."
echo "E.g. https://yourinstitution.org/mypreviewerdir to have the Text previewer at https://yourinstitution.org/mypreviewerdir/previewers/v1.4/TextPreview.html"
echo "The version will match the relative path you provide"
echo ""
fi

folder="$1"
cd "${folder}"

echo Downloading local copies of remote JavaScript libraries:
sed -n 's/.*src="\(http[^"]*\)".*/\1/p' *.html | sort -u | sed -n 's/^\(.*\/\)*\(.*\)/sed -i \x27s,\0\,lib\/\2,\x27 *.html/p' > replace_js.sh
sed -n 's/.*src="\(http[^"]*\)".*/\1/p' *.html | sort -u > urls_js.txt
source replace_js.sh
cat urls_js.txt

echo Downloading local copies of remote CSS files:
sed -n 's/.*<link.*href="\(http[^"]*\)".*/\1/p' *.html | sort -u | sed -n 's/^\(.*\/\)*\(.*\)/sed -i \x27s,\0\,lib\/\2,\x27 *.html/p' > replace_css.sh
sed -n 's/.*<link.*href="\(http[^"]*\)".*/\1/p' *.html | sort -u > urls_css.txt
source replace_css.sh
cat urls_css.txt

if [ ! -d ./lib ]; then
mkdir ./lib
fi
cd ./lib
while read url; do
wget --quiet $url
done < "../urls_js.txt"


cd ".."
if [ ! -d ./css ]; then
mkdir ./css
fi
cd ./css
while read url; do
wget --quiet $url
done < "../urls_css.txt"

cd ..


if [ ! -z "$2" ]; then
cd "${dirLocal}"
echo Changing example curl commands to use local URLs
localurl="$2"
sed -i "s,https://gdcc.github.io/dataverse-previewers/previewers/v1.[34],$localurl/$folder,g" *curlcommands.md
echo Done changing example curl commands to use local URLs
cd "${folder}"
fi

echo Cleaning Up...
rm urls_js.txt
rm urls_css.txt
rm replace_js.sh
rm replace_css.sh

echo Done
exit 0

0 comments on commit 5229ffc

Please sign in to comment.