new config file on stderr + amend README

master
KatolaZ 6 years ago
parent 2ecad5ca4c
commit 29b88760a1
  1. 49
      README.md
  2. 19
      phrollo

@ -5,8 +5,8 @@
configuration file and outputs the relevant selectors to be added to a configuration file and outputs the relevant selectors to be added to a
gophermap. The list of selectors of updated phlogs is sorted in gophermap. The list of selectors of updated phlogs is sorted in
decreasing order of update time (meaning that more recent updates appear decreasing order of update time (meaning that more recent updates appear
at the top of the list). `phrollo` also outputs an updaterd config file, at the top of the list). `phrollo` also prints on stderr an updaterd
to be used for future calls. config file, to be used for future calls.
`phrollo` detects updates by using `shasum -a 256`, i.e. by computing `phrollo` detects updates by using `shasum -a 256`, i.e. by computing
a hash of the resource and comparing it with the hash obtained when the a hash of the resource and comparing it with the hash obtained when the
@ -15,25 +15,23 @@ resource was last seen.
Usage Usage
=========== ===========
1) Either :
``` ```
./phrollo status.txt ./phrollo status.txt
``` ```
or:
In this case, `phrollo` will put a new config file in `status.txt.new`,
and output the sorted list of gopher selectors. The config file received
on input will also be saved in `status.txt.bak`.
2)
``` ```
cat config.txt | ./phrollo cat status.txt | ./phrollo
``` ```
In this case, the new config file will be put in `phrollo.out`, and will print the sorted list of gopher selectors on stdout, and the
output the sorted list of gopher selectors. updated config file on stderr.
IMPORTANT: The next time `phrollo` is run, it must be given the last IMPORTANT: The next time `phrollo` is run, it must be given the last
config file generated. config file generated, so be sure to redirect stderr appropriately. A
fully working example is given below.
Configuration file Configuration file
======================== ========================
@ -71,7 +69,13 @@ them with a "-" dash. Notice that fields are separated by actual TABs:
- KatolaZ /~katolaz/phlog republic.circumlunar.space 70 - - KatolaZ /~katolaz/phlog republic.circumlunar.space 70 -
``` ```
Now we can feed this file to `phrollo` to get: Now we can feed this file to `phrollo`:
```
cat config.txt | ./phrollo 2> config_updated.txt > gophermap
```
and we will get the following output in `gophermap`:
``` ```
1(20190126) Alex Shroeder / alexschroeder.ch 70 1(20190126) Alex Shroeder / alexschroeder.ch 70
@ -83,8 +87,7 @@ Now we can feed this file to `phrollo` to get:
``` ```
which is a list of selectors corresponding to the phlogs specified in which is a list of selectors corresponding to the phlogs specified in
the config file. Moreover, `phrollo` will also create the updated the config file, and the updated config file in config_updated.txt:
config file `phrollo.out`:
``` ```
20190126 Tomasino /phlog gopher.black 70 bd141abfc29522e3e2b5d00f1a656212201ae5def60de90a7ce847cddeb6d0db 20190126 Tomasino /phlog gopher.black 70 bd141abfc29522e3e2b5d00f1a656212201ae5def60de90a7ce847cddeb6d0db
@ -96,4 +99,18 @@ config file `phrollo.out`:
``` ```
Then, we can run `phrollo` again using the latest updated config file Then, we can run `phrollo` again using the latest updated config file
(i.e., `phrollo.out`) to detect updates. to detect updates and generate the new gophermap. It is possible to
automate the update procedure by something like:
```
#!/bin/sh
cp config.txt config.txt."$(date +%Y%m%d)"
cat config.txt | ./phrollo 2> config.txt.new > gophermap.new
[ $? -eq 0 ] && {
mv config.txt.new config.txt
mv gophermap.new gophermap
}
```

@ -3,25 +3,12 @@
# MIT License # MIT License
FILEIN="${1:-/dev/stdin}" FILEIN="${1:-/dev/stdin}"
TODAY="$(date +%Y%m%d)"
if [ "${FILEIN}" != '/dev/stdin' ]; then {
cat "${FILEIN}" | tee "${FILEIN}".bak > "${FILEIN}".new
FILEOUT="${FILEIN}".new
} else {
FILEOUT="$(basename $0).out"
}
fi
IFS=' ' IFS=' '
while read -r D T S H P SH; do while read -r D T S H P SH; do
NSH="$(printf "$S\r\n" | nc $H $P | shasum -a 256 | cut -d " " -f 1)" NSH="$(printf "$S\r\n" | nc $H $P | shasum -a 256 | cut -d " " -f 1)"
[ $? -eq 0 ] && [ $? -eq 0 ] &&
[ "${SH}" != "${NSH}" ] && { [ "${SH}" != "${NSH}" ] && {D="$(date +%Y%m%d)"; SH="${NSH}"}
D="${TODAY}" printf "%s\t%s\t%s\t%s\t%s\t%s\n" "$D" "$T" "$S" "$H" "$P" "$SH" | tee /dev/stderr
SH="${NSH}" done < "${FILEIN}" | sort -rnk1 -k2 | \
}
printf "%s\t%s\t%s\t%s\t%s\t%s\n" "$D" "$T" "$S" "$H" "$P" "$SH"
done < "${FILEIN}" | sort -rnk1 -k2 | tee "${FILEOUT}" | \
sed -r "s/^([0-9][0-9]*) /1(\1) /g;s/ [a-f0-9][a-f0-9]*$//g" |\ sed -r "s/^([0-9][0-9]*) /1(\1) /g;s/ [a-f0-9][a-f0-9]*$//g" |\
sort -rk1 -k2 sort -rk1 -k2

Loading…
Cancel
Save