Skip to content
Extraits de code Groupes Projets
Valider 53149a63 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

WIP: WIP

parent f9bdcb08
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -775,10 +775,14 @@ __pack() { ...@@ -775,10 +775,14 @@ __pack() {
# Check packs # Check packs
local DEST_FOLDER="$STPKG_BASE/packs/$PACK_NAME" local DEST_FOLDER="$STPKG_BASE/packs/$PACK_NAME"
[ -d "$DEST_FOLDER" ] \ [ -d "$DEST_FOLDER" ] \
&& { { warn "Delete old folder content for pack $PACK_NAME" ; rm "$DEST_FOLDER"/*; } \ && { warn "Old folder for pack $PACK_NAME exists, using checksums to reupload necessary stickers"; } \
|| die "Failed to remove old folder pack content"; } \
|| { { info "Create folder for pack $PACK_NAME" ; mkdir "$DEST_FOLDER"; } \ || { { info "Create folder for pack $PACK_NAME" ; mkdir "$DEST_FOLDER"; } \
|| die "Failed to create destination folder for pack '$PACK_NAME'"; } || die "Failed to create destination folder for pack '$PACK_NAME'"; }
#[ -d "$DEST_FOLDER" ] \
# && { { warn "Delete old folder content for pack $PACK_NAME" ; rm "$DEST_FOLDER"/*; } \
# || die "Failed to remove old folder pack content"; } \
# || { { info "Create folder for pack $PACK_NAME" ; mkdir "$DEST_FOLDER"; } \
# || die "Failed to create destination folder for pack '$PACK_NAME'"; }
local DEST_INDEX="$DEST_FOLDER/$PACK_NAME.json" local DEST_INDEX="$DEST_FOLDER/$PACK_NAME.json"
touch $DEST_INDEX touch $DEST_INDEX
[ ! -f $DEST_INDEX ] && die "Failed to create the index file '$DEST_INDEX'" [ ! -f $DEST_INDEX ] && die "Failed to create the index file '$DEST_INDEX'"
...@@ -792,42 +796,46 @@ __pack() { ...@@ -792,42 +796,46 @@ __pack() {
local FIRST_IN_ARRAY="" local FIRST_IN_ARRAY=""
# Check checksums # Check checksums
local SUM_FILE=".${PACK_NAME}.checksums" local SUM_FILE="$DEST_FOLDER/.$PACK_NAME.checksums"
if [ ! -f "$SUM_FILE" ]; then if [ ! -f "$SUM_FILE" ]; then
touch $SUM_FILE touch $SUM_FILE
fi fi
local -a newFiles local -A hashes unchangedFiles updatedFiles deletedFiles skipFiles
local -A hashes unchangedFiles updatedFiles deletedFiles
local TEMP_CHECK=`mktemp --suffix=.stpkg` local TEMP_CHECK=`mktemp --suffix=.stpkg`
md5sum -c $SUM_FILE &>/dev/null >$TEMP_CHECK md5sum -c $SUM_FILE &>/dev/null >$TEMP_CHECK
while read -r _hash _file; do while read -r _hash _file; do
hashes["$_file"]="$_hash" hashes["$_file"]="$_hash"
done < $SUM_FILE done < $SUM_FILE
newFiles=(*)
for i in "`cat $TEMP_CHECK | grep ": OK$" | sed "s/: OK$//g"`"; do for i in `cat $TEMP_CHECK | grep ': OK$' | sed 's/\(.*\): OK/\1/'`; do
unchangedFiles["$i"]=("${hashes["$i"]}") if [ "x$i" = "x" ]; then continue; fi
unchangedFiles["$i"]="${hashes["$i"]}"
unset hashes["$i"] unset hashes["$i"]
newFiles="${newFiles[@]/$i}" skipFiles[$i]=""
done done
for i in "`cat $TEMP_CHECK | grep ": FAILED$" | sed "s/: FAILED$//g"`"; do for i in `cat $TEMP_CHECK | grep ': FAILED$' | sed 's/\(.*\): FAILED/\1/'`; do
updatedFiles["$i"]=("${hashes["$i"]}") if [ "x$i" = "x" ]; then continue; fi
updatedFiles["$i"]="${hashes["$i"]}"
unset hashes["$i"] unset hashes["$i"]
newFiles="${newFiles[@]/$i}" skipFiles[$i]=""
done done
for i in "`cat $TEMP_CHECK | grep ": FAILED open or read$" | sed "s/: FAILED open or read$//g"`"; do for i in `cat $TEMP_CHECK | grep ': FAILED open or read$' | sed 's/\(.*\): FAILED open or read/\1/'`; do
deletedFiles["$i"]=("${hashes["$i"]}") if [ "x$i" = "x" ]; then continue; fi
deletedFiles["$i"]="${hashes["$i"]}"
unset hashes["$i"] unset hashes["$i"]
newFiles="${newFiles[@]/$i}" skipFiles[$i]=""
done done
for FILE in "${!newFiles[@]}"; do for FILE in *; do
# Add a ',' only if it's not the first in the array # Add a ',' only if it's not the first in the array
echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX
if [[ $(md5sum $FILE) = $(cat $SUM_FILE | grep ) ]]; then if [[ -v skipFiles[$FILE] ]]; then continue; fi
else
md5sum $FILE >> $SUM_FILE echo "Processing new file $FILE"
if [[ "`md5sum $FILE | sed -e 's/\([0-9a-f]\{32\}\) .*$/\1/'`" = "`cat $SUM_FILE | grep "$FILE" | sed -e 's/\([0-9a-f]\{32\}\) .*$/\1/'`" ]]; then
die "New file is replacing existing file, that should not be happening"
fi fi
local ST_JSON="" local ST_JSON=""
...@@ -836,10 +844,10 @@ __pack() { ...@@ -836,10 +844,10 @@ __pack() {
# For the report # For the report
[ "x$FIRST_IN_ARRAY" = "x" ] && echo -e "StickerName MXC Type Width Height" [ "x$FIRST_IN_ARRAY" = "x" ] && echo -e "StickerName MXC Type Width Height"
local FIRST_IN_ARRAY="," FIRST_IN_ARRAY=","
echo -e "$ST_JSON" | jq -r '[.body, .url, .info.mimetype, .info.w, .info.h]|join(" ")' echo -e "$ST_JSON" | jq -r '[.body, .url, .info.mimetype, .info.w, .info.h]|join(" ")'
# TODO: add hashes md5sum $FILE >> $SUM_FILE
progress_reset progress_reset
done | column -t done | column -t
...@@ -847,7 +855,7 @@ __pack() { ...@@ -847,7 +855,7 @@ __pack() {
for FILE in "${!unchangedFiles[@]}"; do for FILE in "${!unchangedFiles[@]}"; do
echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX
[ "x$FIRST_IN_ARRAY" = "x" ] && echo -e "StickerName MXC Type Width Height" [ "x$FIRST_IN_ARRAY" = "x" ] && echo -e "StickerName MXC Type Width Height"
local FIRST_IN_ARRAY="," FIRST_IN_ARRAY=","
#echo -e "$ST_JSON" | jq -r '[.body, .url, .info.mimetype, .info.w, .info.h]|join(" ")' #echo -e "$ST_JSON" | jq -r '[.body, .url, .info.mimetype, .info.w, .info.h]|join(" ")'
echo "$FILE unchanged" echo "$FILE unchanged"
done | column -t done | column -t
...@@ -855,14 +863,14 @@ __pack() { ...@@ -855,14 +863,14 @@ __pack() {
for FILE in "${!updatedFiles[@]}"; do for FILE in "${!updatedFiles[@]}"; do
echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX
[ "x$FIRST_IN_ARRAY" = "x" ] && echo -e "StickerName MXC Type Width Height" [ "x$FIRST_IN_ARRAY" = "x" ] && echo -e "StickerName MXC Type Width Height"
local FIRST_IN_ARRAY="," FIRST_IN_ARRAY=","
echo "$FILE updated" echo "$FILE updated"
done | column -t done | column -t
for FILE in "${!deletedFiles[@]}"; do for FILE in "${!deletedFiles[@]}"; do
echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX
[ "x$FIRST_IN_ARRAY" = "x" ] && echo -e "StickerName MXC Type Width Height" [ "x$FIRST_IN_ARRAY" = "x" ] && echo -e "StickerName MXC Type Width Height"
local FIRST_IN_ARRAY="," FIRST_IN_ARRAY=","
#echo -e "$ST_JSON" | jq -r '[.body, .url, .info.mimetype, .info.w, .info.h]|join(" ")' #echo -e "$ST_JSON" | jq -r '[.body, .url, .info.mimetype, .info.w, .info.h]|join(" ")'
echo "$FILE deleted, but kept in the pack" echo "$FILE deleted, but kept in the pack"
done | column -t done | column -t
...@@ -878,9 +886,10 @@ __pack() { ...@@ -878,9 +886,10 @@ __pack() {
#montage "$DEST_FOLDER/*.{png,gif}" -background none "$DEST_FOLDER/preview.png" #montage "$DEST_FOLDER/*.{png,gif}" -background none "$DEST_FOLDER/preview.png"
#echo -ne "# $PACK_NAME\n![Preview of $PACK_NAME](preview.png)" > "$DEST_FOLDER/README.md" #echo -ne "# $PACK_NAME\n![Preview of $PACK_NAME](preview.png)" > "$DEST_FOLDER/README.md"
echo -ne "# $PACK_NAME\n(no preview)" > "$DEST_FOLDER/README.md" echo -ne "# $PACK_NAME\n(no preview)" > "$DEST_FOLDER/README.md"
find $DEST_FOLDER -type f \( ! -name "preview.png" -and ! -name "$PACK_NAME.json" \) -exec rm {} \; find $DEST_FOLDER -type f \( ! -name "preview.png" -and ! -name "$PACK_NAME.json" -and ! -name '.*.checksums' \) -exec rm {} \;
echo -n "]}" >> $DEST_INDEX echo -n "]}" >> $DEST_INDEX
cat $DEST_INDEX
cat $DEST_INDEX | jq | sponge $DEST_INDEX cat $DEST_INDEX | jq | sponge $DEST_INDEX
info "Pack created, you can now commit it and create a MR to share it with other users" info "Pack created, you can now commit it and create a MR to share it with other users"
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter