Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions play.d/hansoft-client.sh

This file was deleted.

114 changes: 114 additions & 0 deletions play.d/p4-plan-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/sh

PKGNAME=p4-plan-client
SUPPORTEDARCHES="x86_64"
VERSION="$2"
DESCRIPTION="P4 Plan desktop client from the official site"
URL="https://www.perforce.com/downloads/hansoft-client"

. $(dirname $0)/common.sh

warn_version_is_not_supported

# Public package name in EPM is p4-plan-client, while upstream still mixes
# Helix Plan Client (portal/product title) and HelixPlan (internal app name).
export EPM_REPACK_SCRIPT=p4-plan-client
export EEPM_INTERNAL_PKGNAME='p4planclient p4-plan-client'

# The download page is a Salesforce portal. It does not expose a static .deb URL,
# so we have to reproduce a small part of its Aura workflow.
PORTAL_URL='https://portal.perforce.com/s/downloads?product=Helix%20Plan%20Client'
PORTAL_PAGEURI='/s/downloads?product=Helix%20Plan%20Client'
AURA_APP='siteforce:communityApp'
AURA_APP_LOADED='APPLICATION@markup://siteforce:communityApp'

epm assure curl || fatal 'curl is required'
cd_to_temp_dir

portal_post()
{
local endpoint="$1"
local descriptor="$2"
local caller="$3"
local params="$4"
local output="$5"
local message

message='{"actions":[{"id":"1;a","descriptor":"'$descriptor'","callingDescriptor":"'$caller'","params":'$params',"version":null}]}'

curl -fsSL --max-time 30 "$endpoint" \
--data-urlencode "message=$message" \
--data-urlencode "aura.context=$AURA_CONTEXT" \
--data-urlencode "aura.pageURI=$PORTAL_PAGEURI" \
--data-urlencode 'aura.token=null' \
> "$output"
}

PORTAL_HTML="$PKGDIR/portal.html"
PRODUCT_JSON="$PKGDIR/product.json"
NODES_JSON="$PKGDIR/nodes.json"
DOWNLOAD_JSON="$PKGDIR/download.json"

# Raw HTML contains Aura bootstrap values only inside percent-encoded script URLs.
curl -fsSL --max-time 30 "$PORTAL_URL" > "$PORTAL_HTML" || fatal "Can't open $PORTAL_URL."

FWUID="$(sed -n 's|.*%22fwuid%22%3A%22\([^"%]*\)%22.*|\1|p' "$PORTAL_HTML" | head -n1)"
APP_LOADED="$(
sed -n 's|.*%22APPLICATION%40markup%3A%2F%2Fsiteforce%3AcommunityApp%22%3A%22\([^"%]*\)%22.*|\1|p' "$PORTAL_HTML" \
| head -n1
)"

[ -n "$FWUID" ] || fatal "Can't get Aura fwuid."
[ -n "$APP_LOADED" ] || fatal "Can't get Aura app token."

AURA_CONTEXT='{"mode":"PROD","fwuid":"'$FWUID'","app":"'$AURA_APP'","loaded":{"'$AURA_APP_LOADED'":"'$APP_LOADED'"},"dn":[],"globals":{},"uad":true}'

# Step 1: resolve the current product root folder in the portal file tree.
portal_post \
'https://portal.perforce.com/s/sfsites/aura?r=1&c.dynamicDownload.getDownloadProductAndAllReleaeses=1' \
'apex://productDownloadController/ACTION$getDownloadProductAndAllReleaeses' \
'markup://c:dynamicDownload' \
'{"productName":"Helix Plan Client"}' \
"$PRODUCT_JSON" || fatal "Can't get product data."

ROOT_FOLDER_ID="$(get_json_value "$PRODUCT_JSON" '["actions",0,"returnValue","pDownload","s3Folder__c"]')"
[ -n "$ROOT_FOLDER_ID" ] || fatal "Can't get current download folder."

# Step 2: list files in that folder and find the current Linux .deb node.
NODE_DATA='{"captionField":"","checkable":true,"childObjectType":"","id":"Files/'$ROOT_FOLDER_ID'","key":"'$ROOT_FOLDER_ID'","nodeQuery":"","nodeType":"NodeType_Object","objectType":"Folder__c","objSelectedRecord":{"attributes":{"type":"NEILON__Folder__c"},"Id":"'$ROOT_FOLDER_ID'","Name":"Client"},"orderChildrenBy":"Name","showGroupByCharts":true,"showNewButton":false,"showResultObjectsInTree":true,"tncId":""}'
NODE_DATA_ESCAPED="$(printf '%s' "$NODE_DATA" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')"

portal_post \
'https://portal.perforce.com/s/sfsites/aura?r=2&NEILON.apLightningTreeNode.getChildNodes=1' \
'apex://NEILON.apLightningTreeNodeController/ACTION$getChildNodes' \
'markup://NEILON:apLightningTreeNode' \
'{"treeType":"Files","nodeData":"'"$NODE_DATA_ESCAPED"'","withoutSharing":true,"showItemsCount":false,"defaultWhereClauses":"{}"}' \
"$NODES_JSON" || fatal "Can't get current Linux downloads."

DEB_INDEX="$(
epm tool json -b < "$NODES_JSON" \
| sed -n 's|^\["actions",0,"returnValue",\([0-9][0-9]*\),"title"\][[:space:]]*".*\.deb"$|\1|p' \
| head -n1
)"
[ -n "$DEB_INDEX" ] || fatal "Can't find Linux .deb package."

RECORD_ID="$(get_json_value "$NODES_JSON" '["actions",0,"returnValue",'$DEB_INDEX',"userData","objSelectedRecord","Id"]')"
[ -n "$RECORD_ID" ] || fatal "Can't get Linux package record id."

VERSION="$(
get_json_value "$NODES_JSON" '["actions",0,"returnValue",'$DEB_INDEX',"title"]' \
| sed -n 's|^.*_\([0-9][0-9][0-9][0-9]\)_\([0-9][0-9][0-9][0-9]\)_x64\.deb$|\1.\2|p'
)"

# Step 3: ask the portal for a fresh signed S3 URL for that file.
portal_post \
'https://portal.perforce.com/s/sfsites/aura?r=3&NEILON.edFileDetail.getFileDownloadInformation=1' \
'apex://NEILON.edFileDetailController/ACTION$getFileDownloadInformation' \
'markup://NEILON:edLightningFileDownload' \
'{"recordId":"'$RECORD_ID'"}' \
"$DOWNLOAD_JSON" || fatal "Can't get package download URL."

PKGURL="$(get_json_value "$DOWNLOAD_JSON" '["actions",0,"returnValue","fileDownloadURL"]')"
[ -n "$PKGURL" ] || fatal "Can't get package URL."

install_pkgurl
19 changes: 11 additions & 8 deletions repack.d/hansoft.sh → repack.d/p4-plan-client.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
BUILDROOT="$1"
SPEC="$2"

PRODUCT=hansoft
PRODUCTCUR=Hansoft
PRODUCT=p4-plan-client
PRODUCTCUR=HelixPlan
PRODUCTDIR=/opt/HelixPlan

. $(dirname $0)/common.sh

subst "s|^Name:.*|Name: p4-plan-client|" "$SPEC"

add_bin_link_command $PRODUCT $PRODUCTDIR/$PRODUCTCUR
add_bin_link_command $PRODUCTCUR $PRODUCT

cat <<EOF |create_file /usr/share/applications/$PRODUCT.desktop
[Desktop Entry]
Expand All @@ -18,7 +20,8 @@ Categories=Development;Office;
Exec=$PRODUCT -Url %u
Icon=$PRODUCT
MimeType=x-scheme-handler/hansoft;
Name=Hansoft Client
Name=P4 Plan Client
Comment=P4 Plan client
Terminal=false
Type=Application
Version=1.0
Expand All @@ -34,7 +37,7 @@ Name=Log out & exit all
X-Hansoft-TaskType=Command
EOF

# copied from ~.local/share/icons/se.hansoft.Exe-PMClient_7B6AC2CBB8795205B8E6DC09CB75B5E6.png
i=256
install_file ipfs://QmbYM3wS2qXtWbUg9mASMPoJmgfL6smny1m3J4PfuiDtJR /usr/share/icons/hicolor/${i}x${i}/apps/$PRODUCT.png

# Upstream .deb does not ship a standalone icon file, so use the current
# official product favicon published in Perforce docs.
i=512
install_file https://help.perforce.com/hansoft/current/Skins/Favicons/favicon-p4-plan.png /usr/share/icons/hicolor/${i}x${i}/apps/$PRODUCT.png