#!/bin/sh
# loffice-freetype.sh: skip downloading external freetype (for use with alien's
# libreoffice.SlackBuild).
FILE=libreoffice.SlackBuild
BACKUP=$FILE.orig
FREETYPE_INDEX=$(sed -n 's/^SOURCE\[\([0-9]\{1,\}\)\]=.*freetype.*/\1/p' $FILE)
LAST_INDEX=$(sed -n 's/^SOURCE\[\([0-9]\{1,\}\)\].*/\1/p' $FILE | tail -1)
# Create a backup of the SlackBuild:
printf "Backup: "
cp -v $FILE $BACKUP || exit 1
# Remove freetype from SOURCE and SRCURL arrays:
sed -i "/^SOURCE\[$FREETYPE_INDEX\]=/,/^SRCURL\[$FREETYPE_INDEX\]=/d" $FILE
# Adjust the rest of the index numbers to fill the gap:
for ((i=$FREETYPE_INDEX; i<=$LAST_INDEX; i++)); do
sed -i "/^SOURCE\[$i\]=/s/$i/$((i-1))/" $FILE
sed -i "/^SRCURL\[$i\]=/s/$i/$((i-1))/" $FILE
done