Skip to content

Commit 7b1e834

Browse files
committed
CLI script fixes
1 parent a39792d commit 7b1e834

File tree

7 files changed

+33
-49
lines changed

7 files changed

+33
-49
lines changed

bin/admin/clear-ontology.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
set -eo pipefail
23

34
print_usage()
45
{

bin/admin/packages/install-package.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
set -eo pipefail
23

34
print_usage()
45
{
@@ -95,7 +96,7 @@ else
9596
fi
9697

9798
# POST to packages/install endpoint
98-
curl -k -s -w "%{http_code}\n" -E "$cert_pem_file":"$cert_password" \
99+
curl -k -f -s -w "%{http_code}\n" -E "$cert_pem_file":"$cert_password" \
99100
-X POST \
100101
-H "Accept: text/turtle" \
101102
-H "Content-Type: application/x-www-form-urlencoded" \

bin/admin/packages/uninstall-package.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
set -eo pipefail
23

34
print_usage()
45
{
@@ -95,7 +96,7 @@ else
9596
fi
9697

9798
# POST to packages/uninstall endpoint
98-
curl -k -s -w "%{http_code}\n" -E "$cert_pem_file":"$cert_password" \
99+
curl -k -f -s -w "%{http_code}\n" -E "$cert_pem_file":"$cert_password" \
99100
-X POST \
100101
-H "Accept: text/turtle" \
101102
-H "Content-Type: application/x-www-form-urlencoded" \

http-tests/admin/packages/install-package-ontology.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ package_uri="https://packages.linkeddatahub.com/skos/#this"
1212
package_ontology_uri="https://raw.githubusercontent.com/AtomGraph/LinkedDataHub-Apps/refs/heads/develop/packages/skos/ns.ttl#"
1313
namespace_ontology_uri="${END_USER_BASE_URL}ns#"
1414

15-
# install package via POST to packages/install endpoint
16-
curl -k -w "%{http_code}\n" -o /dev/null -f -s \
17-
-E "$OWNER_CERT_FILE":"$OWNER_CERT_PWD" \
18-
-X POST \
19-
-H "Content-Type: application/x-www-form-urlencoded" \
20-
--data-urlencode "package-uri=$package_uri" \
21-
"${ADMIN_BASE_URL}packages/install" \
15+
# install package
16+
install-package.sh \
17+
-b "$END_USER_BASE_URL" \
18+
-f "$OWNER_CERT_FILE" \
19+
-p "$OWNER_CERT_PWD" \
20+
--package "$package_uri" \
2221
| grep -q "$STATUS_SEE_OTHER"
2322

2423
# verify owl:imports triple was added to namespace graph

http-tests/admin/packages/uninstall-package-ontology.sh

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,24 @@ package_uri="https://packages.linkeddatahub.com/skos/#this"
1212
package_ontology_uri="https://raw.githubusercontent.com/AtomGraph/LinkedDataHub-Apps/refs/heads/develop/packages/skos/ns.ttl#"
1313
namespace_ontology_uri="${END_USER_BASE_URL}ns#"
1414

15-
# first install the package
16-
curl -k -w "%{http_code}\n" -o /dev/null -f -s \
17-
-E "$OWNER_CERT_FILE":"$OWNER_CERT_PWD" \
18-
-X POST \
19-
-H "Content-Type: application/x-www-form-urlencoded" \
20-
--data-urlencode "package-uri=$package_uri" \
21-
"${ADMIN_BASE_URL}packages/install" \
15+
# install package
16+
install-package.sh \
17+
-b "$END_USER_BASE_URL" \
18+
-f "$OWNER_CERT_FILE" \
19+
-p "$OWNER_CERT_PWD" \
20+
--package "$package_uri" \
2221
| grep -q "$STATUS_SEE_OTHER"
2322

2423
# verify owl:imports triple exists before uninstall
2524
ns_before=$(curl -k -s -H "Accept: application/n-triples" "${END_USER_BASE_URL}ns")
2625
echo "$ns_before" | grep -q "<${namespace_ontology_uri}> <http://www.w3.org/2002/07/owl#imports> <${package_ontology_uri}>"
2726

28-
# uninstall package via POST to packages/uninstall endpoint
29-
curl -k -w "%{http_code}\n" -o /dev/null -f -s \
30-
-E "$OWNER_CERT_FILE":"$OWNER_CERT_PWD" \
31-
-X POST \
32-
-H "Content-Type: application/x-www-form-urlencoded" \
33-
--data-urlencode "package-uri=$package_uri" \
34-
"${ADMIN_BASE_URL}packages/uninstall" \
27+
# uninstall package
28+
uninstall-package.sh \
29+
-b "$END_USER_BASE_URL" \
30+
-f "$OWNER_CERT_FILE" \
31+
-p "$OWNER_CERT_PWD" \
32+
--package "$package_uri" \
3533
| grep -q "$STATUS_SEE_OTHER"
3634

3735
# verify owl:imports triple was removed from namespace graph

src/main/java/com/atomgraph/linkeddatahub/resource/admin/pkg/InstallPackage.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public Response post(@FormParam("package-uri") String packageURI, @HeaderParam("
160160
if (log.isDebugEnabled()) log.debug("Downloading package stylesheet from: {}", stylesheetURI);
161161
String stylesheetContent = downloadStylesheet(stylesheetURI);
162162

163-
installStylesheet(Paths.get(getServletContext().getRealPath("/static")).resolve(packagePath).resolve("layout.xsl"), packagePath, stylesheetContent, endUserApp);
163+
installStylesheet(Paths.get(getServletContext().getRealPath("/static")).resolve(packagePath).resolve("layout.xsl"), stylesheetContent, endUserApp);
164164

165165
// 4. Regenerate master stylesheet
166166
regenerateMasterStylesheet(endUserApp, pkg);
@@ -344,20 +344,12 @@ private void installOntology(EndUserApplication app, Model ontologyModel, String
344344
/**
345345
* Installs stylesheet to <samp>/static/<package-path>/layout.xsl</samp>
346346
*/
347-
private void installStylesheet(Path stylesheetFile, String packagePath, String stylesheetContent, EndUserApplication endUserApp) throws IOException
347+
private void installStylesheet(Path stylesheetFile, String stylesheetContent, EndUserApplication endUserApp) throws IOException
348348
{
349349
Files.createDirectories(stylesheetFile.getParent());
350350
Files.writeString(stylesheetFile, stylesheetContent);
351351

352352
if (log.isDebugEnabled()) log.debug("Installed package stylesheet at: {}", stylesheetFile);
353-
354-
// Purge stylesheet from frontend proxy cache to clear any cached 404 responses
355-
// String stylesheetURL = "/static/" + packagePath + "/layout.xsl";
356-
// if (endUserApp.getFrontendProxy() != null)
357-
// {
358-
// if (log.isDebugEnabled()) log.debug("Purging stylesheet from frontend proxy cache: {}", stylesheetURL);
359-
// getSystem().ban(endUserApp.getFrontendProxy(), stylesheetURL, false);
360-
// }
361353
}
362354

363355
/**
@@ -387,13 +379,6 @@ private void regenerateMasterStylesheet(EndUserApplication app, com.atomgraph.li
387379
// Regenerate master stylesheet (XSLTMasterUpdater works with paths)
388380
XSLTMasterUpdater updater = new XSLTMasterUpdater(getServletContext());
389381
updater.regenerateMasterStylesheet(packagePaths);
390-
391-
// Purge master stylesheet from cache
392-
// if (app.getFrontendProxy() != null)
393-
// {
394-
// if (log.isDebugEnabled()) log.debug("Purging master stylesheet from frontend proxy cache: {}", com.atomgraph.linkeddatahub.Application.MASTER_STYLESHEET_PATH);
395-
// getSystem().ban(app.getFrontendProxy(), com.atomgraph.linkeddatahub.Application.MASTER_STYLESHEET_PATH, false);
396-
// }
397382
}
398383

399384
/**

src/main/java/com/atomgraph/linkeddatahub/resource/admin/pkg/UninstallPackage.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ public Response post(@FormParam("package-uri") String packageURI, @HeaderParam("
148148
if (stylesheet != null)
149149
{
150150
String packagePath = pkg.getStylesheetPath();
151-
uninstallStylesheet(Paths.get(getServletContext().getRealPath("/static")), packagePath, endUserApp);
151+
Path packageDir = Paths.get(getServletContext().getRealPath("/static")).resolve(packagePath);
152+
Path stylesheetFile = packageDir.resolve("layout.xsl");
153+
154+
uninstallStylesheet(stylesheetFile, packagePath, endUserApp);
152155
regenerateMasterStylesheet(endUserApp, pkg);
153156
}
154157

@@ -245,12 +248,8 @@ private void uninstallOntology(EndUserApplication app, String packageOntologyURI
245248
/**
246249
* Deletes stylesheet from <samp>/static/<package-path>/</samp>
247250
*/
248-
private void uninstallStylesheet(Path staticDir, String packagePath, EndUserApplication endUserApp) throws IOException
251+
private void uninstallStylesheet(Path stylesheetFile, String packagePath, EndUserApplication endUserApp) throws IOException
249252
{
250-
Path packageDir = staticDir.resolve(packagePath);
251-
252-
// Delete layout.xsl
253-
Path stylesheetFile = packageDir.resolve("layout.xsl");
254253
Files.delete(stylesheetFile);
255254
if (log.isDebugEnabled()) log.debug("Deleted package stylesheet: {}", stylesheetFile);
256255

@@ -263,10 +262,10 @@ private void uninstallStylesheet(Path staticDir, String packagePath, EndUserAppl
263262
}
264263

265264
// Delete directory if empty
266-
if (Files.list(packageDir).count() == 0)
265+
if (Files.list(stylesheetFile.getParent()).count() == 0)
267266
{
268-
Files.delete(packageDir);
269-
if (log.isDebugEnabled()) log.debug("Deleted package directory: {}", packageDir);
267+
Files.delete(stylesheetFile.getParent());
268+
if (log.isDebugEnabled()) log.debug("Deleted package directory: {}", stylesheetFile.getParent());
270269
}
271270
}
272271

0 commit comments

Comments
 (0)