summaryrefslogtreecommitdiff
path: root/ar/.local/bin/syncdic
blob: c125f42c7bda3e229eea81dce32d3469e56ae63a (plain)
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
#!/bin/sh

dicfile="${XDG_DATA_HOME:-${HOME}/.local/share}/thesiah/dic"
dest="${XDG_DATA_HOME:-${HOME}/.local/share}/dic"

[ -d "$dest" ] || mkdir -p "$dest"

while read -r url; do
  [ -z "$url" ] && continue
  filename=$(basename "$url")
  filepath="${dest}/${filename}"
  tarpath=$(echo "$filepath" | sed 's/.zip//;s/.tar.gz//;s/.tgz//;s/.tar.bz2//;s/.tbz2//;s/.tar.xz//;s/.txz//')

  # Download only if the file does not exist
  if [ ! -d "$tarpath" ]; then
    curl -L "$url" -o "$filepath"
    case "$filename" in
    *.zip)
      unzip -o "$filepath" -d "$dest"
      ;;
    *.tar.gz | *.tgz)
      tar -xzf "$filepath" -C "$dest"
      ;;
    *.tar.bz2 | *.tbz2)
      tar -xjf "$filepath" -C "$dest"
      ;;
    *.tar.xz | *.txz)
      tar -xJf "$filepath" -C "$dest"
      ;;
    esac
    rm -f "$filepath"
  fi
done <"$dicfile"