Skip to content

Commit 775dacd

Browse files
committed
add extra copy from backup
1 parent 5456e07 commit 775dacd

File tree

1 file changed

+186
-0
lines changed

1 file changed

+186
-0
lines changed

scripts/action-create-twa-2.sh

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#!/bin/bash
2+
3+
##################################################
4+
5+
# some options maybe
6+
7+
##################################################
8+
9+
# Exit immediately if a command exits with a non-zero status,
10+
# treat unset variables as an error, and fail if any command in a pipeline fails
11+
set -euo pipefail
12+
13+
# Colors
14+
#BLACK='\033[0;30m'
15+
RED='\033[0;31m'
16+
GREEN='\033[0;32m'
17+
YELLOW='\033[0;33m'
18+
BLUE='\033[0;34m'
19+
CYAN='\033[0;36m'
20+
BRIGHTWHITE='\033[0;37;1m'
21+
NC='\033[0m'
22+
23+
# Check if cardano-cli is installed
24+
if ! command -v cardano-cli >/dev/null 2>&1; then
25+
echo "Error: cardano-cli is not installed or not in your PATH." >&2
26+
exit 1
27+
fi
28+
29+
# Check if ipfs cli is installed
30+
if ! command -v ipfs >/dev/null 2>&1; then
31+
echo "Error: ipfs cli is not installed or not in your PATH." >&2
32+
exit 1
33+
fi
34+
35+
# Usage message
36+
usage() {
37+
echo "Usage: $0 <directory> --deposit-return-addr <stake address> --withdrawal-addr <stake address> [--no-ipfs-pin]"
38+
echo "Create treasury withdrawal governance actions from a directory of JSONLD metadata files and host the metadata on ipfs."
39+
echo "Options:"
40+
echo " <directory> Path to directory containing .jsonld files"
41+
echo " --deposit-return-addr <stake address> Check that metadata deposit return address matches provided one (Bech32) [REQUIRED]"
42+
echo " --withdrawal-addr <stake address> Check that metadata withdrawal address matches provided one (Bech32) [REQUIRED]"
43+
echo " --no-ipfs-pin Skip IPFS pinning step"
44+
echo " -h, --help Show this help message and exit"
45+
exit 1
46+
}
47+
48+
# Initialize variables with defaults
49+
input_path=""
50+
deposit_return_address_input=""
51+
withdrawal_address_input=""
52+
skip_ipfs_pin="false"
53+
54+
# Parse command line arguments
55+
while [[ $# -gt 0 ]]; do
56+
case $1 in
57+
--deposit-return-addr)
58+
if [ -n "${2:-}" ]; then
59+
deposit_return_address_input="$2"
60+
shift 2
61+
else
62+
echo -e "${RED}Error: --deposit-return-addr requires a value${NC}" >&2
63+
usage
64+
fi
65+
;;
66+
--withdrawal-addr)
67+
if [ -n "${2:-}" ]; then
68+
withdrawal_address_input="$2"
69+
shift 2
70+
else
71+
echo -e "${RED}Error: --withdrawal-addr requires a value${NC}" >&2
72+
usage
73+
fi
74+
;;
75+
--no-ipfs-pin)
76+
skip_ipfs_pin="true"
77+
shift
78+
;;
79+
-h|--help)
80+
usage
81+
;;
82+
*)
83+
if [ -z "$input_path" ]; then
84+
input_path="$1"
85+
fi
86+
shift
87+
;;
88+
esac
89+
done
90+
91+
# If no input path provided, show usage
92+
if [ -z "$input_path" ]; then
93+
echo -e "${RED}Error: No directory specified${NC}" >&2
94+
usage
95+
fi
96+
97+
# Check if required parameters are provided
98+
if [ -z "$deposit_return_address_input" ]; then
99+
echo -e "${RED}Error: --deposit-return-addr is required${NC}" >&2
100+
usage
101+
fi
102+
103+
if [ -z "$withdrawal_address_input" ]; then
104+
echo -e "${RED}Error: --withdrawal-addr is required${NC}" >&2
105+
usage
106+
fi
107+
108+
# Check if input is a directory
109+
if [ ! -d "$input_path" ]; then
110+
echo -e "${RED}Error: Input is not a valid directory: ${YELLOW}$input_path${NC}" >&2
111+
exit 1
112+
fi
113+
114+
echo -e " "
115+
echo -e "${YELLOW}Budget Action Creation Service${NC}"
116+
echo -e "${CYAN}This script processes JSONLD files to create treasury withdrawal governance actions${NC}"
117+
echo -e "${CYAN}It will host files on IPFS and create governance actions for each file${NC}"
118+
119+
# Get all .jsonld files in the directory and subdirectories
120+
jsonld_files=()
121+
while IFS= read -r -d '' file; do
122+
jsonld_files+=("$file")
123+
done < <(find "$input_path" -type f -name "*.jsonld" -print0)
124+
125+
# Check if any .jsonld files were found
126+
if [ ${#jsonld_files[@]} -eq 0 ]; then
127+
echo -e " "
128+
echo -e "${RED}Error: No .jsonld files found in directory (including subdirectories): ${YELLOW}$input_path${NC}" >&2
129+
exit 1
130+
fi
131+
132+
echo -e " "
133+
echo -e "${CYAN}Found ${YELLOW}${#jsonld_files[@]}${NC}${CYAN} .jsonld files to process${NC}"
134+
135+
for file in "${jsonld_files[@]}"; do
136+
# Ask user if they want to continue with the next file
137+
# Skip for the first file
138+
if [ "$file" != "${jsonld_files[0]}" ]; then
139+
echo -e " "
140+
echo -e "${CYAN}The next file is: ${YELLOW}$file${NC}"
141+
read -p "Do you want to continue with the next file? (y/n): " choice
142+
case "$choice" in
143+
y|Y ) echo -e "${GREEN}Continuing with the next file...${NC}";;
144+
n|N ) echo -e "${YELLOW}Exiting...${NC}"; exit 0;;
145+
* ) echo -e "${RED}Invalid choice, exiting...${NC}"; exit 1;;
146+
esac
147+
fi
148+
149+
if [ -f "$file" ]; then
150+
echo -e " "
151+
echo -e "${CYAN}Processing file: ${YELLOW}$file${NC}"
152+
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
153+
154+
if [ "$skip_ipfs_pin" = "false" ]; then
155+
echo -e " "
156+
echo -e "${CYAN}Hosting file on IPFS using ./ipfs-pin.sh${NC}"
157+
./scripts/ipfs-pin.sh "$file"
158+
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
159+
else
160+
echo -e " "
161+
echo -e "${YELLOW}Skipping IPFS pinning step${NC}"
162+
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
163+
fi
164+
165+
echo -e " "
166+
echo -e "${CYAN}Creating treasury governance action using ./action-create-tw.sh${NC}"
167+
168+
./scripts/action-create-tw.sh --deposit-return-addr "$deposit_return_address_input" \
169+
--withdrawal-addr "$withdrawal_address_input" \
170+
"$file"
171+
172+
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
173+
echo -e " "
174+
echo -e "${GREEN}Successfully processed: ${YELLOW}$file${NC}"
175+
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
176+
177+
else
178+
echo -e " "
179+
echo -e "${RED}Error: file is not a valid file: ${YELLOW}$file${NC}" >&2
180+
exit 1
181+
fi
182+
done
183+
184+
echo -e " "
185+
echo -e "${GREEN}All files processed successfully!${NC}"
186+
echo -e "${CYAN}Treasury withdrawal governance actions have been created for all JSONLD files${NC}"

0 commit comments

Comments
 (0)