@@ -23,79 +23,81 @@ jobs:
23
23
- name : Update rsync section
24
24
run : |
25
25
FILE="documentation/docs/Mirrors.md"
26
- # Save static content up to the rsync section marker
27
- sed '/^### 2\. Set up synchronization via rsync/,$d' $FILE > tmp.md
28
- # Append updated rsync section header and table
29
- echo "" >> tmp.md
30
- echo "### 2. Set up synchronization via rsync" >> tmp.md
31
- echo "" >> tmp.md
32
- echo " - Sync files from one of the official repositories using the following commands:" >> tmp.md
33
- echo "" >> tmp.md
34
- echo " | Content | Command | Required Space |" >> tmp.md
35
- echo " |-----------------|---------------------------------------------|---------------:|" >> tmp.md
26
+ sed '/^### 2\. Set up synchronization via rsync/,$d' "$FILE" > tmp.md
27
+ cat <<EOF >> tmp.md
28
+ ### 2. Set up synchronization via rsync
29
+
30
+ - Sync files from one of the official repositories using the following commands:
31
+
32
+ | Content | Command | Required Space |
33
+ |-----------------|---------------------------------------------|---------------:|
34
+ EOF
36
35
for storage in dl apt archive oldarchive; do
37
- size=$(curl -s https://k-space.ee.armbian.com/$storage/size.txt)
38
- case "$storage" in
39
- "dl")
40
- TEXT="Current images" ;;
41
- "apt")
42
- TEXT="Packages" ;;
43
- "archive")
44
- TEXT="Archived images" ;;
45
- *)
46
- TEXT="Very old images" ;;
47
- esac
48
- echo " | $TEXT | \`rsync -av rsync://rsync.armbian.com/$storage\` | $size |" >> tmp.md
36
+ size=$(curl -s https://k-space.ee.armbian.com/$storage/size.txt)
37
+ case "$storage" in
38
+ "dl")
39
+ TEXT="Current images"
40
+ ;;
41
+ "apt")
42
+ TEXT="Packages"
43
+ ;;
44
+ "archive")
45
+ TEXT="Archived images"
46
+ ;;
47
+ *)
48
+ TEXT="Very old images"
49
+ ;;
50
+ esac
51
+ echo " | $TEXT | \`rsync -av rsync://rsync.armbian.com/$storage\` | $size |" >> tmp.md
49
52
done
50
- # Append the remainder of the file starting from the " ## Current Mirrors" marker
51
- sed -n '/^## Current Mirrors/,$p' $FILE >> tmp.md
52
- mv tmp.md $FILE
53
+ sed -n '/^ ## Current Mirrors/,$p' "$FILE" >> tmp.md
54
+ sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' tmp.md
55
+ mv tmp.md " $FILE"
53
56
54
57
- name : Update Current Mirrors section
55
58
run : |
56
59
FILE="documentation/docs/Mirrors.md"
57
- # Save static content up to the "## Current Mirrors" marker
58
- sed '/^## Current Mirrors/,$d' $FILE > tmp.md
59
- # Append new "## Current Mirrors" section header and table header
60
- echo "" >> tmp.md
61
- echo "## Current Mirrors" >> tmp.md
62
- echo "" >> tmp.md
63
- echo "| Site | Time Zone | Flag | Speed | Packages | Images | Archive | Rsync |" >> tmp.md
64
- echo "|:-----|:----------|------|-------:|:--------:|:------:|:-------:|:-----:|" >> tmp.md
65
- # Dynamically generate the table rows from the API data
60
+ sed '/^## Current Mirrors/,$d' "$FILE" > tmp.md
61
+ cat <<EOF >> tmp.md
62
+ ## Current Mirrors
63
+
64
+ | Site | Time Zone | Flag | Speed | Packages | Images | Archive | Rsync |
65
+ |:-----|:----------|------|-------:|:--------:|:------:|:-------:|:-----:|
66
+ EOF
66
67
JQ=$(curl -s -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" \
67
68
-H "Accept: application/json; indent=4" \
68
69
"${{ secrets.NETBOX_API }}/virtualization/virtual-machines/?limit=500&name__empty=false&role=mirror")
69
70
for i in $(echo $JQ | jq '.results[] | .id'); do
70
- NAME=$(echo $JQ | jq ".results[] | select(.id == $i) | .name" | sed "s/\"//g")
71
- SITE_ID=$(echo $JQ | jq ".results[] | select(.id == $i) | .site.id")
72
- SITE_STATUS=$(echo $JQ | jq -r ".results[] | select(.id == $i) | .status.value")
73
- SITE_TAGS=$(echo $JQ | jq -r ".results[] | select(.id == $i) | .tags[].slug" | xargs )
74
- SITEQ=$(curl -s -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" \
75
- -H "Accept: application/json; indent=4" \
76
- "${{ secrets.NETBOX_API }}/dcim/sites/?limit=500&name__empty=false&id=$SITE_ID")
77
- SITE_NAME=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .name" | sed 's/ /\ /g')
78
- SITE_REGION=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .region.display")
79
- SITE_TZ=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .time_zone")
80
- SITE_LATITUDE=$(echo $SITEQ | jq ".results[] | select(.id == $SITE_ID) | .latitude")
81
- SITE_LONGITUDE=$(echo $SITEQ | jq ".results[] | select(.id == $SITE_ID) | .longitude")
82
- SITE_SPEED=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .custom_fields.download_speed")
83
- IP=$(dig +short ${NAME} | tail -1)
84
- SITE_FLAG=$(curl --max-time 5 -s http://ipwhois.app/json/${IP} | jq -r '.country_code')
85
- [[ $SITE_STATUS == "decommissioning" ]] && continue
86
- if [[ $SITE_STATUS != "active" ]]; then
87
- LABEL=":x:"
88
- else
89
- LABEL=":white_check_mark:"
90
- fi
91
- if [[ "${SITE_TAGS}" == *"debs"* ]]; then FIELD1="$LABEL"; else FIELD1=""; fi
92
- if [[ "${SITE_TAGS}" == *"images"* ]]; then FIELD2="$LABEL"; else FIELD2=""; fi
93
- if [[ "${SITE_TAGS}" == *"archive"* ]]; then FIELD3="$LABEL"; else FIELD3=""; fi
94
- if [[ "${SITE_TAGS}" == *"rsync"* ]]; then FIELD4="$LABEL"; else FIELD4=""; fi
95
- echo "| [$SITE_NAME](https://$NAME) | $SITE_TZ | [](https://www.openstreetmap.org/search?lat=$SITE_LATITUDE&lon=$SITE_LONGITUDE) | $SITE_SPEED Mbps | $FIELD1 | $FIELD2 | $FIELD3 | $FIELD4 |" >> tmp.md
96
- sleep 1
71
+ NAME=$(echo $JQ | jq ".results[] | select(.id == $i) | .name" | sed "s/\"//g")
72
+ SITE_ID=$(echo $JQ | jq ".results[] | select(.id == $i) | .site.id")
73
+ SITE_STATUS=$(echo $JQ | jq -r ".results[] | select(.id == $i) | .status.value")
74
+ SITE_TAGS=$(echo $JQ | jq -r ".results[] | select(.id == $i) | .tags[].slug" | xargs )
75
+ SITEQ=$(curl -s -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" \
76
+ -H "Accept: application/json; indent=4" \
77
+ "${{ secrets.NETBOX_API }}/dcim/sites/?limit=500&name__empty=false&id=$SITE_ID")
78
+ SITE_NAME=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .name" | sed 's/ /\ /g')
79
+ SITE_REGION=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .region.display")
80
+ SITE_TZ=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .time_zone")
81
+ SITE_LATITUDE=$(echo $SITEQ | jq ".results[] | select(.id == $SITE_ID) | .latitude")
82
+ SITE_LONGITUDE=$(echo $SITEQ | jq ".results[] | select(.id == $SITE_ID) | .longitude")
83
+ SITE_SPEED=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .custom_fields.download_speed")
84
+ IP=$(dig +short " ${NAME}" | tail -1)
85
+ SITE_FLAG=$(curl --max-time 5 -s http://ipwhois.app/json/" ${IP}" | jq -r '.country_code')
86
+ [[ $SITE_STATUS == "decommissioning" ]] && continue
87
+ if [[ $SITE_STATUS != "active" ]]; then
88
+ LABEL=":x:"
89
+ else
90
+ LABEL=":white_check_mark:"
91
+ fi
92
+ if [[ "${SITE_TAGS}" == *"debs"* ]]; then FIELD1="$LABEL"; else FIELD1=""; fi
93
+ if [[ "${SITE_TAGS}" == *"images"* ]]; then FIELD2="$LABEL"; else FIELD2=""; fi
94
+ if [[ "${SITE_TAGS}" == *"archive"* ]]; then FIELD3="$LABEL"; else FIELD3=""; fi
95
+ if [[ "${SITE_TAGS}" == *"rsync"* ]]; then FIELD4="$LABEL"; else FIELD4=""; fi
96
+ echo "| [$SITE_NAME](https://$NAME) | $SITE_TZ | [](https://www.openstreetmap.org/search?lat=$SITE_LATITUDE&lon=$SITE_LONGITUDE) | $SITE_SPEED Mbps | $FIELD1 | $FIELD2 | $FIELD3 | $FIELD4 |" >> tmp.md
97
+ sleep 1
97
98
done
98
- mv tmp.md $FILE
99
+ sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' tmp.md
100
+ mv tmp.md "$FILE"
99
101
100
102
- name : Create Pull Request to documentation
101
103
uses : peter-evans/create-pull-request@v7
0 commit comments