|
|
e7fa50 |
# helpers
|
|
|
e7fa50 |
|
|
|
e7fa50 |
copy() {
|
|
|
e7fa50 |
local SRC=$1
|
|
|
e7fa50 |
local DEST=$2
|
|
|
e7fa50 |
if [ -d "$SRC" ]; then
|
|
|
e7fa50 |
if ! mkdir -p $DEST; then
|
|
|
e7fa50 |
return 1
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
if [ "$(ls -A $1)" ]; then
|
|
|
e7fa50 |
if ! cp --remove-destination -rlP $SRC/* "$DEST/"; then
|
|
|
e7fa50 |
return 1
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
elif [ -f "$SRC" ]; then
|
|
|
e7fa50 |
if ! (mkdir -p `dirname $DEST` && cp --remove-destination -l "$SRC" "$DEST"); then
|
|
|
e7fa50 |
return 1
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
else
|
|
|
e7fa50 |
return 1
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
}
|
|
|
e7fa50 |
|
|
|
e7fa50 |
foreachfile() {
|
|
|
e7fa50 |
local FILE=$1
|
|
|
e7fa50 |
local COMMAND=$2
|
|
|
e7fa50 |
if [ ! -x "$FILE" ]; then
|
|
|
e7fa50 |
return 1
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
if [ -d "$FILE" ]; then
|
|
|
e7fa50 |
ls -1 "$FILE" | while read SUBFILE; do
|
|
|
e7fa50 |
if ! $COMMAND "$FILE/$SUBFILE" ${@:3}; then
|
|
|
e7fa50 |
return 1
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
done
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
}
|
|
|
e7fa50 |
|
|
|
e7fa50 |
readdir() {
|
|
|
e7fa50 |
local FILE=$1
|
|
|
e7fa50 |
if [ -d "$FILE" ]; then
|
|
|
e7fa50 |
echo "directory begin"
|
|
|
e7fa50 |
ls -1 "$1" | while read SUBFILE; do
|
|
|
e7fa50 |
if [ "$SUBFILE" = ".git" ]; then
|
|
|
e7fa50 |
continue
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
if [[ "$SUBFILE" == *.po ]]; then
|
|
|
e7fa50 |
continue
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
local STAT=`stat -c%F:%a:%s "$FILE/$SUBFILE"`
|
|
|
e7fa50 |
echo "$STAT:$SUBFILE"
|
|
|
e7fa50 |
readdir "$FILE/$SUBFILE"
|
|
|
e7fa50 |
done
|
|
|
e7fa50 |
echo "directory end"
|
|
|
e7fa50 |
else
|
|
|
e7fa50 |
local MD5=`md5sum -b "$FILE"`
|
|
|
e7fa50 |
echo "file:${MD5:0:32}"
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
}
|
|
|
e7fa50 |
|
|
|
e7fa50 |
md5() {
|
|
|
e7fa50 |
local FILE=$1
|
|
|
e7fa50 |
local MD5=`readdir "$FILE" | md5sum -b`
|
|
|
e7fa50 |
echo "${MD5:0:32}"
|
|
|
e7fa50 |
}
|
|
|
e7fa50 |
|
|
|
e7fa50 |
remove_recursive() {
|
|
|
e7fa50 |
local CURRENT_PATH="$1"
|
|
|
e7fa50 |
local NEEDLE="$2"
|
|
|
e7fa50 |
rm -f "$CURRENT_PATH/"$NEEDLE
|
|
|
e7fa50 |
for FILE in $CURRENT_PATH; do
|
|
|
e7fa50 |
if [ -d "$CURRENT_PATH/$FILE" ]; then
|
|
|
e7fa50 |
remove_recursive "$CURRENT_PATH/$FILE" "$NEEDLE"
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
done
|
|
|
e7fa50 |
}
|
|
|
e7fa50 |
|
|
|
e7fa50 |
copy_system_lib() {
|
|
|
e7fa50 |
local SRC_NAME=$1
|
|
|
e7fa50 |
local DST_PATH=$2
|
|
|
e7fa50 |
cp --remove-destination /lib/x86_64-linux-gnu/$SRC_NAME* "$DST_PATH" &> /dev/null \
|
|
|
e7fa50 |
|| cp --remove-destination /lib/i386-linux-gnu/$SRC_NAME* "$DST_PATH" &> /dev/null \
|
|
|
e7fa50 |
|| cp --remove-destination /usr/lib/x86_64-linux-gnu/$SRC_NAME* "$DST_PATH" &> /dev/null \
|
|
|
e7fa50 |
|| cp --remove-destination /usr/lib/i386-linux-gnu/$SRC_NAME* "$DST_PATH" &> /dev/null \
|
|
|
e7fa50 |
|| (echo "$SRC_NAME not found in system libraries" && return 1)
|
|
|
e7fa50 |
}
|
|
|
e7fa50 |
|
|
|
e7fa50 |
add_license() {
|
|
|
e7fa50 |
local FILE="$1"
|
|
|
e7fa50 |
local FILE_IN_TITLE="$2"
|
|
|
e7fa50 |
local TARGET="$3"
|
|
|
e7fa50 |
if [ ! -z "$FILE_IN_TITLE" ]; then
|
|
|
e7fa50 |
echo "" >> "$TARGET" || return 1
|
|
|
e7fa50 |
echo "-------------------------------------" >> "$TARGET" || return 1
|
|
|
e7fa50 |
echo " File: $FILE_IN_TITLE" >> "$TARGET" || return 1
|
|
|
e7fa50 |
echo "-------------------------------------" >> "$TARGET" || return 1
|
|
|
e7fa50 |
echo "" >> "$TARGET" || return 1
|
|
|
e7fa50 |
else
|
|
|
e7fa50 |
echo "" >> "$TARGET" || return 1
|
|
|
e7fa50 |
echo "-------------------------------------" >> "$TARGET" || return 1
|
|
|
e7fa50 |
echo "" >> "$TARGET" || return 1
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
cat "$FILE" >> "$TARGET" || return 1
|
|
|
e7fa50 |
}
|
|
|
e7fa50 |
|
|
|
e7fa50 |
copy_system_license() {
|
|
|
e7fa50 |
local SRC_NAMES=$1
|
|
|
e7fa50 |
local DST_PATH=$2
|
|
|
e7fa50 |
local SRC_NAME=
|
|
|
e7fa50 |
for SRC_NAME in $SRC_NAMES; do
|
|
|
e7fa50 |
rm -f "$DST_PATH/license-$SRC_NAME"
|
|
|
e7fa50 |
done
|
|
|
e7fa50 |
for SRC_NAME in $SRC_NAMES; do
|
|
|
e7fa50 |
local TARGET="$DST_PATH/license-$SRC_NAME"
|
|
|
e7fa50 |
local FILE=
|
|
|
e7fa50 |
if [ -f "/usr/share/doc/$SRC_NAME/copyright" ]; then
|
|
|
e7fa50 |
FILE="/usr/share/doc/$SRC_NAME/copyright"
|
|
|
e7fa50 |
elif [ -d "/usr/share/licenses/$SRC_NAME" ]; then
|
|
|
e7fa50 |
FILE="/usr/share/licenses/$SRC_NAME"
|
|
|
e7fa50 |
elif [ -d "/usr/share/doc/$SRC_NAME" ]; then
|
|
|
e7fa50 |
FILE="/usr/share/doc/$SRC_NAME"
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
|
|
|
e7fa50 |
if [ -f "$FILE" ]; then
|
|
|
e7fa50 |
add_license "$FILE" "$FILE" "$TARGET" || (echo "Cannot add license file: $FILE -> $TARGET"; return 1)
|
|
|
e7fa50 |
elif [ -d "$FILE" ]; then
|
|
|
e7fa50 |
ls -1 "$FILE" | while read SUBFILE; do
|
|
|
e7fa50 |
add_license "$FILE/$SUBFILE" "$FILE/$SUBFILE" "$TARGET" || (echo "Cannot add license file: $FILE/$SUBFILE -> $TARGET"; return 1)
|
|
|
e7fa50 |
done
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
|
|
|
e7fa50 |
if [ -f "$TARGET" ]; then
|
|
|
e7fa50 |
return 0
|
|
|
e7fa50 |
fi
|
|
|
e7fa50 |
done
|
|
|
e7fa50 |
|
|
|
e7fa50 |
echo "Cannot found any license for one of system packages: $SRC_NAMES (for $DST_PATH)"
|
|
|
e7fa50 |
return 1
|
|
|
e7fa50 |
}
|
|
|
e7fa50 |
|