-
Notifications
You must be signed in to change notification settings - Fork 8
/
update-service.sh
executable file
·39 lines (29 loc) · 1.2 KB
/
update-service.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
AIRLINENAMESDIR=/home/planefence/airlinenames
WORKDIR=/home/planefence/git/planefence-airlinecodes
GITREPO=kx1t/planefence-airlinecodes
[[ ! -d $WORKDIR ]] && git clone https://github.com/$GITREPO $WORKDIR
pushd $WORKDIR
git pull --all
cp -fu airlinecodes.txt $AIRLINENAMESDIR
tmpfile=$(mktemp)
tmpfile2=$(mktemp)
sed 's/^\([A-Z0-9]\{3\}\).*/\1/g' $AIRLINENAMESDIR/airline-missed.txt 2>/dev/null | sort -k1,1 -u | awk NF >$tmpfile
while read -r missed
do
tac $AIRLINENAMESDIR/airline-missed.txt | grep "^$missed," $AIRLINENAMESDIR/airlinecodes.txt 2>&1 >/dev/null || echo "Airline code \"$missed\", examples:$(tac $AIRLINENAMESDIR/airline-missed.txt| grep "^$missed" | xargs)" >> $tmpfile2
done < $tmpfile
# remove dupes:
cat $tmpfile2 airlinecodes-unresolved.txt | awk -F',' '!seen[$1]++' > $tmpfile
mv -f $tmpfile airlinecodes-unresolved.txt
touch airlinecodes-unresolved.txt
rm $tmpfile2
rm -f $AIRLINENAMESDIR/airline-missed.txt
# back up the server dir:
pushd $AIRLINENAMESDIR && tar -czvf backup.tgz ./* && popd && mv $AIRLINENAMESDIR/backup.tgz .
# now write it back to the repo:
# git remote set-url origin git@github.com:$GITREPO
git add -A *
git commit -m "auto-upload $(date)"
git push
popd