Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: update shlink_link to add OS and Hardware information to click… #2648

Merged
merged 2 commits into from
Sep 17, 2024
Merged
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
42 changes: 19 additions & 23 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -1379,44 +1379,40 @@ app_prefix_category() { #lists all apps in a category with format "category/app"
fi
}

# bitly_link() { #Runs whenever an app is installed/uninstalled to tally the number of users for each app
# #This cannot possibly be used to identify you, or any information about you.
# #It simply "clicks" a bitly link - a shortened URL - so that the total number of clicks can be tallied to determine how popular a certain app is.
# app="$1"
# trigger="$2"
#
# [ -z "$app" ] && error "bitly_link(): requires an app argument"
# [ -z "$trigger" ] && error "bitly_link(): requires a trigger argument"
#
# #if the 'Enable Analytics' setting is enabled
# if [ "$(cat "${DIRECTORY}/data/settings/Enable analytics")" == 'Yes' ];then
# #determine the name of the link to "click"
# bitlylink="https://bit.ly/pi-apps-$trigger-$(echo "$app" | tr -d ' ' | sed 's/[^a-zA-Z0-9]//g')"
# #click it
# curl -L --user-agent "Pi-Apps Raspberry Pi app store" "$bitlylink" &>/dev/null &
# fi
# }

bitly_link() { #compatibility function pointing to shlink_link (incase old manage script is running with new api)
shlink_link "$@"
}

shlink_link() { #Runs whenever an app is installed/uninstalled to tally the number of users for each app
{
#This cannot possibly be used to identify you, or any information about you.
#It simply "clicks" a shlink link - a shortened URL - so that the total number of clicks can be tallied to determine how popular a certain app is.
app="$1"
trigger="$2"
local app="$1"
local trigger="$2"

[ -z "$app" ] && error "shlink_link(): requires an app argument"
[ -z "$trigger" ] && error "shlink_link(): requires a trigger argument"

#if the 'Enable Analytics' setting is enabled
if [ "$(cat "${DIRECTORY}/data/settings/Enable analytics")" == 'Yes' ];then
if [ "$(cat "${DIRECTORY}/data/settings/Enable analytics" 2>/dev/null)" != 'No' ]; then
#obtain model and SOC_ID
get_model &>/dev/null
local model="$(echo $model | tr -d '"'\; | head -1)"
# obtain (hashed) machine_id (only if file exists and has contents)
[ -s /etc/machine-id ] && machine_id="$(cat /etc/machine-id | sha1sum | awk '{print $1}' | head -1)"
# obtain (hashed) serial_number (only if file exists and has contents)
[ -s /sys/firmware/devicetree/base/serial-number ] && serial_number="$(cat /sys/firmware/devicetree/base/serial-number | sha1sum | awk '{print $1}' | head -1)"
#obtain operating system name
#not using PRETTY_NAME to only get the ID and OS major version (eg: Ubuntu 24.04 instead of Ubuntu 24.04.1 LTS)
local os_name="$(cat /etc/os-release | grep ^ID= | tr -d '"'\; | awk -F= '{print $2}' | head -1) $(cat /etc/os-release | grep ^VERSION_ID= | tr -d '"'\; | awk -F= '{print $2}' | head -1)"

#determine the name of the link to "click"
shlinklink="https://analytics.pi-apps.io/pi-apps-$trigger-$(echo "$app" | tr -d ' ' | sed 's/[^a-zA-Z0-9]//g')/track"
local shlinklink="https://analytics.pi-apps.io/pi-apps-$trigger-$(echo "$app" | tr -d ' ' | sed 's/[^a-zA-Z0-9]//g')/track"
#click it
curl -s -X 'GET' "$shlinklink" -H 'accept: image/gif' -A "Pi-Apps Raspberry Pi app store" >/dev/null &
#NOTE: any future changes to the user agent should only APPEND
curl -s -X 'GET' "$shlinklink" -H 'accept: image/gif' -A "Pi-Apps Raspberry Pi app store; $model; $SOC_ID; $machine_id; $serial_number; ${os_name^}" >/dev/null
fi
} &
}

usercount() { #Return number of users for specified app. $1 is app name. If empty, all are shown.
Expand Down
7 changes: 2 additions & 5 deletions gui
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ mkdir -p "${DIRECTORY}/data/status" "${DIRECTORY}/data/update-status" \
"${DIRECTORY}/updater" set-status &
trap "kill $! &>/dev/null" EXIT #kill the above subprocess on exit

#Click pi-apps usage link every time the GUI is run only if the 'Enable Analytics' setting is enabled
if [ "$(cat "${DIRECTORY}/data/settings/Enable analytics")" == 'Yes' ];then
#click it
curl -s -X 'GET' "https://analytics.pi-apps.io/pi-apps-active-usage/track" -H 'accept: image/gif' -A "Pi-Apps Raspberry Pi app store" >/dev/null &
fi
#Click pi-apps usage link every time the GUI is run
shlink_link usage active
}

#Determine the app list mode. Allowed values: 'yad-*', 'xlunch-*'
Expand Down
2 changes: 1 addition & 1 deletion install
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ elif [ ! -d "$DIRECTORY" ];then
error "Pi-Apps download failed!\ngit clone output was: $output"
fi
#click new installation analytics link
curl -s -X 'GET' "https://analytics.pi-apps.io/pi-apps-install-script/track" -H 'accept: image/gif' -A "Pi-Apps Raspberry Pi app store" >/dev/null &
"${DIRECTORY}/api" shlink_link script install
fi

#Past this point, DIRECTORY variable populated with valid pi-apps directory
Expand Down
4 changes: 1 addition & 3 deletions uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ function error {
DIRECTORY="$(readlink -f "$(dirname "$0")")"

#click new uninstallation analytics link
if [ "$(cat "${DIRECTORY}/data/settings/Enable analytics")" == 'Yes' ];then
curl -s -X 'GET' "https://analytics.pi-apps.io/pi-apps-uninstall-script/track" -H 'accept: image/gif' -A "Pi-Apps Raspberry Pi app store" >/dev/null &
fi
"${DIRECTORY}/api" shlink_link script uninstall

if [ -z "$(dpkg-query -W --showformat='${Status}\n' yad 2>/dev/null | grep "install ok installed")" ];then
zenity --title='Pi-Apps' --window-icon="${DIRECTORY}/icons/logo.png" \
Expand Down