#!/bin/bash
EXT=desktop
DESKTOP1=/home/${USER}/Desktop
DESKTOP2=/home/${USER}/デスクトップ
cd "${DESKTOP1}" 2>/dev/null||cd "${DESKTOP2}"||exit
ls ./*.${EXT} 2>/dev/null|while read -r i;do grep -q "^Type=Link$" "${i}" && echo "${i}" \
|while read -r i
do
URLLINE=$(grep "^URL=" "${i}")
modifytime=$(stat -c %y "${i}"|cut -b1-4,6-7,9-10,12-13,15-19|sed 's/:/./')
fname=${i#*/}
fname=${fname%*$EXT}URL
fname=$(echo "${fname}"|sed -e 's/〜/～/'g)
fname=$(echo "${fname}"|sed -e 's/»/-/'g)
fname=$(echo "${fname}"|sed -e 's/"/”/'g)
fname=$(echo "${fname}"|sed -e 's/\\/／/'g)
fname=$(echo "${fname}"|sed -e 's/?/？/'g)
fname=$(echo "${fname}"|sed -e 's/</＜/'g)
fname=$(echo "${fname}"|sed -e 's/>/＞/'g)
fname=$(echo "${fname}"|sed -e 's/:/：/'g)
fname=$(echo "${fname}"|sed -e 's/;/；/'g)
fname=$(echo "${fname}"|sed -e 's/|/｜/'g)
fname=$(echo "${fname}"|sed -e 's/,/，/'g)
fname=$(echo "${fname}"|sed -e 's/*/-/'g)
fname=$(echo "${fname}"|sed -e 's/\^/-/'g)
fname=$(echo "${fname}"|sed -e 's/ / /'g)
fname=$(echo "${fname}"|sed -e 's/—/―/'g)
fname=$(echo "${fname}"|sed -e 's/−/－/'g)
fname=$(echo "${fname}"|sed -e 's/ê/e/'g)
fname=$(echo "${fname}"|sed -e 's/ó/o/'g)
fname=$(echo "${fname}"|sed -e 's/@/＠/'g)
while [ "$(echo "${fname}"|cut -b1)" == "-" ]
do
fname=$(echo "${fname}"|sed -e 's/^-//')
done
grep "^${URLLINE}.$" "${fname}" 2>/dev/null
if [ $? -ne 0 ]; then
echo -e "[Default]\r">"${fname}"
echo -e "BASE${URLLINE}\r">>"${fname}"
echo -e "[InternetShortcut]\r">>"${fname}"
echo -e "${URLLINE}\r">>"${fname}"
touch -t ${modifytime} "${fname}"
fi
rm "${i}"
done;done
