Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
shorten folder names
Browse files Browse the repository at this point in the history
  • Loading branch information
broizter committed May 15, 2022
1 parent eb06cf5 commit a501598
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions bitwardenbackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,20 @@ fi
# Variables used later in script. Not meant to be changed.
SESSION=$("$BW_BINARY" unlock --raw "$PASSWORD")
PARENTS=$("$BW_BINARY" list items --session "$SESSION" | jq -r '.[] | select(.attachments) | .id')
ATTACHFOLDER="$OUTPUTFOLDER"/attachments/
JSONFILE="$OUTPUTFOLDER"/vault.json
EXIT=0

# Detect changes to your Bitwarden vault and export passwords to json file
"$BW_BINARY" sync --session "$SESSION" || EXIT=$?
"$BW_BINARY" export "$PASSWORD" --format json --session "$SESSION" --output "$JSONFILE" || EXIT=$?

# Create folder where attachments end up
if ! [ -d "$ATTACHFOLDER" ]; then
mkdir "$ATTACHFOLDER" || EXIT=$?
fi

# Goes through any item that contains attachments and downloads them
for P in $PARENTS; do
if ! [ -d "$ATTACHFOLDER"/"$P" ]; then
mkdir "$ATTACHFOLDER"/"$P" || EXIT=$?
fi
ATTACH=$("$BW_BINARY" get item "$P" --session "$SESSION" | jq -r .attachments[].id)
PARENTFOLDER=$(echo $P | cut -d - -f 1)
for A in $ATTACH; do
if ! [ -d "$ATTACHFOLDER"/"$P"/"$A" ]; then
mkdir "$ATTACHFOLDER"/"$P"/"$A" || EXIT=$?
fi
"$BW_BINARY" get attachment "$A" --itemid "$P" --session "$SESSION" --output "$ATTACHFOLDER"/"$P"/"$A"/ || EXIT=$?
ATTACHFOLDER=$(echo $A | cut -c1-8)
"$BW_BINARY" get attachment "$A" --itemid "$P" --session "$SESSION" --output "$OUTPUTFOLDER"/attachments/"$PARENTFOLDER"/"$ATTACHFOLDER"/ || EXIT=$?
done
done

Expand Down

0 comments on commit a501598

Please sign in to comment.