Skip to content

Commit

Permalink
Refactor UUID generating logic (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
XternA authored Dec 21, 2024
1 parent 0297b1f commit 8105f25
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
18 changes: 7 additions & 11 deletions apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"properties": [
"#EARNAPP_DEVICE_UUID"
],
"uuid_type": 1,
"is_enabled": true,
"proxy_uuid": {
"requires_uuid": true,
"uuid_type": "#",
"name_type": "DEVICE_UUID",
"description": "Register ID with link replacing {uuid} placeholder: https://earnapp.com/r/sdk-node-{uuid}"
}
Expand Down Expand Up @@ -86,12 +85,11 @@
"description": " Log in, then go to 'Profile' to obtain API key. Register device with given UUID in 'Devices' section. Obtain UUID from 'Devices' to re-use device UUID for re-registering.",
"properties": [
"PROXYRACK_API_KEY",
"*PROXYRACK_UUID"
"#PROXYRACK_UUID"
],
"uuid_type": 2,
"is_enabled": true,
"proxy_uuid": {
"requires_uuid": true,
"uuid_type": "*",
"name_type": "UUID",
"description": "Register device ID in app dashboard's 'Devices' section."
}
Expand Down Expand Up @@ -120,12 +118,11 @@
"description": " Log into the dashboard and go to 'Devices' to obtain authentication code.",
"properties": [
"SPEEDSHARE_AUTH_CODE",
"*SPEEDSHARE_UUID"
"#SPEEDSHARE_UUID"
],
"uuid_type": 2,
"is_enabled": true,
"proxy_uuid": {
"requires_uuid": true,
"uuid_type": "*",
"name_type": "UUID",
"description": "Device ID is automatically added. No manual steps required."
}
Expand All @@ -136,12 +133,11 @@
"description": " After installing app, run ' docker logs spide 2>&1 | grep \"Device Key\" ' outside the tool to obtain device key. Log into dashboard to register device.",
"description_ext": "Use machine ID for existing device already registered. See guide: https://github.com/XternA/income-generator/wiki/Keys-and-IDs#machine-id",
"properties": [
"&SPIDE_MACHINE_ID"
"#SPIDE_MACHINE_ID"
],
"is_enabled": true,
"uuid_type": 3,
"proxy_uuid": {
"requires_uuid": true,
"uuid_type": "&",
"name_type": "MACHINE_ID",
"description": "These are machine ID, to regenerate the same device ID. Register device ID from: docker logs spide-{number} 2>&1 | grep \"Device Key\""
}
Expand Down
7 changes: 4 additions & 3 deletions scripts/app-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ process_entries() {
# Check if properties is an array before looping through it
if [ "$(echo "$config_entry" | jq -r '.properties | type')" = "array" ]; then
for entry in $properties; do
entry_name=$(echo "$entry" | sed 's/^"//' | sed 's/"$//' | tr -d "*#&") # Remove surrounding quotes and denoters
denoter=$(echo "${entry%${entry#?}}")
entry_name=$(echo "$entry" | sed 's/^"//' | sed 's/"$//' | tr -d "#") # Remove surrounding quotes and denoter
require_uuid=$(echo "${entry%${entry#?}}")

[ -n "$(grep "^$entry_name=" "$ENV_FILE")" ] && is_update=true

if [ "$denoter" = "#" ] || [ "$denoter" = "*" ] || [ "$denoter" = "&" ]; then
if [ "$require_uuid" = "#" ]; then
denoter=$(echo "$config_entry" | jq -r '.uuid_type' | tr -d '\n')
process_uuid_user_choice
else
input_new_value
Expand Down
7 changes: 2 additions & 5 deletions scripts/proxy/proxy-uuid-generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ export PROXY_FOLDER="${ROOT_DIR}/proxy_uuid"
TOTAL_PROXIES="$(awk 'BEGIN {count=0} NF {count++} END {print count}' "$PROXY_FILE")"

generate_uuid_files() {
app_data="jq -r '.[] | select(.is_enabled == true and .proxy_uuid != null) | \"\(.name) \(.proxy_uuid)\"' \"$JSON_FILE\""
app_data="jq -r '.[] | select(.is_enabled == true and .uuid_type != null) | \"\(.name) \(.uuid_type)\"' \"$JSON_FILE\""

[ -n "$PROXY_FOLDER" ] && mkdir -p "$PROXY_FOLDER"

counter=1
while true; do
echo "$(eval $app_data)" | while read -r name proxy_uuid; do
requires_uuid=$(echo "$proxy_uuid" | jq -r '.requires_uuid')
uuid_type=$(echo "$proxy_uuid" | jq -r '.uuid_type')

echo "$(eval $app_data)" | while read -r name uuid_type; do
proxy_file="${PROXY_FOLDER}/${name}.uuid"
uuid="$(generate_uuid "$uuid_type")"

Expand Down
6 changes: 3 additions & 3 deletions scripts/util/uuid-generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ generate_uuid() {
fi

case "$1" in
"#") echo "sdk-node-$(echo "$uuid" | tr -d '-')" ;;
"*") echo "$uuid" ;;
"&") echo "$uuid" | tr -d '-' ;;
1) echo "sdk-node-$(echo "$uuid" | tr -d '-')" ;;
2) echo "$uuid" ;;
3) echo "$uuid" | tr -d '-' ;;
esac
}

0 comments on commit 8105f25

Please sign in to comment.