-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdeletePermTrashOrg.sh
More file actions
59 lines (46 loc) · 1.55 KB
/
deletePermTrashOrg.sh
File metadata and controls
59 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
## REQUIREMENTS ##
# before running the script:
# download jq JSON tool
# Log in to Bitwarden CLI first
# Get the directory of the current script
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Check if 'bw' exists in the same directory as the script
if [[ -f "$script_dir/bw" ]]; then
bw_path="$script_dir/bw"
else
# If not found, check in the directories listed in $PATH
bw_path=$(which bw)
if [[ -z $bw_path ]]; then
echo "'bw' not found in the script directory or in \$PATH"
exit 1
fi
fi
# Check if 'jq' exists in the same directory as the script
if [[ -f "$script_dir/jq" ]]; then
jq_path="$script_dir/jq"
else
# If not found, check in the directories listed in $PATH
jq_path=$(which jq)
if [[ -z $jq_path ]]; then
echo "'jq' not found in the script directory or in \$PATH"
exit 1
fi
fi
#ask for org id
read -p 'Organization ID: ' org_id
#ask for master password to unlock the CLI
read -sp 'Enter Master Password for the account (Hidden): ' acc_master_pass
echo ""
session_key=$($bw_path unlock $acc_master_pass --raw)
$bw_path sync --session $session_key
trash_items="$($bw_path list items --organizationid $org_id --trash --session $session_key | $jq_path -r '.[].id' | tr -d '"')"
cc=0
echo "deleting trash items.."
for item_id in ${trash_items[@]} ; do
((cc++))
echo "deleting item no. $cc"
$bw_path delete item $item_id --permanent --session $session_key
done
echo "$cc items deleted from trash"
$bw_path sync --session $session_key