Skip to content

Commit

Permalink
v0.3 - Added install script
Browse files Browse the repository at this point in the history
Added a script to install the application, including prerequisites.
Refactored code to remove unnecessary outside tools.
Update README.md with new instructions, including install.sh script.
  • Loading branch information
steppsr authored Dec 13, 2022
1 parent 7193f18 commit 9003bc8
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 44 deletions.
29 changes: 19 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
# xd-nft-wizard
xd nft wizard is a interactive Bash script to help with Chia NFTs.

## Requiements
You may need to install the following tools if you don't already have them. Run `which toolname` from the
command line, where toolname is one of the tools below to see if there is one installed on your machine. If
the command returns a path, then you have the tool. If it does not, then you may need to install the tool.
## Download
You can download the following files individually, or grab the latest release. Put the files into
a folder you create for the application. I like to do this in my home directory.

**Required tools:**
To create a folder for the application in your home directory:
```
cd
mkdir xdnft
```

## Install
There are a couple of require utilities that will be installed if not already on your system.
1. curl
2. jq

## Running the command
Use the `bash` command to run the script. You can also use redirect to send the output to a file.
To run the install:
`bash install.sh`

Example:
```
bash xdnft.sh
Follow any on screen prompts. It will ask you to reload your user profile after it completes:
`source ~/.bashrc`

## Running the command
```
xdnft
```

## Actions available
Expand All @@ -40,6 +48,7 @@ bash xdnft.sh
C. Random Name Picker

## Screenshots

![xd nft wizard](https://xchdev.com/images/xd-nft-wizard_1.png)

![xd nft wizard](https://xchdev.com/images/xd-nft-wizard_2.png)
Expand Down
59 changes: 59 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

##################
# INSTALL SCRIPT #
##################

appdir=`pwd`

# define some colors
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
bldgrn='\e[1;32m' # Bold Green
bldpur='\e[1;35m' # Bold Purple
txtrst='\e[0m' # Text Reset

echo -e "${bldgrn}"

# Prequisite: jq - check if installed already and if not run the installer
if ! command -v jq &> /dev/null
then
echo -e "Installing jq..."
sudo apt install jq
fi

if ! command -v curl &> /dev/null
then
echo -e "Installing curl..."
sudo apt install curl
fi

# Create the working folders for the application
echo -e "Installing into $appdir directory..."

[ ! -d "$appdir/files" ] && mkdir "$appdir/files" && echo "${txtrst}files${bldgrn} sub-directory created..."

# Set the script as executable
echo -e "Making the script executable..."
chmod +x ./xdnft.sh

# Add an alias to the .bashrc profile
echo -e "Adding alias for script to user profile ${txtrst}~/.bashrc${bldgrn}..."
echo "" >> ~/.bashrc
echo "alias xdnft=\"bash $appdir/xdnft.sh\"" >> ~/.bashrc
source ~/.bashrc

echo -e "${bldpur}### Install complete! ###${txtrst}"
echo ""
echo ""
echo -e "One final task, please run the following command to reload your user profile:"
echo -e "${bldgrn}source ~/.bashrc${txtrst}"
echo ""
echo ""
echo -e "How to using the script: "
echo -e ""
user=`whoami`
server=`hostname`
echo -e " $user@$server:$appdir$ ${bldgrn}xdnft${txtrst}"
echo ""
echo -e "${txtrst}"
74 changes: 40 additions & 34 deletions xdnft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bldpur='\e[1;35m' # Bold Purple
txtrst='\e[0m' # Text Reset

display_banner() {
version="0.2"
version="0.3"
echo -e "${bldgrn}"
echo -e " _ __ _ _ _ "
echo -e " | | / _| | (_) | |"
Expand Down Expand Up @@ -62,9 +62,9 @@ get_wallet_id () {
for id in $nft_id_list; do
if [ "$id" == "$nft_id" ]; then
nft_json=`curl -s https://api.mintgarden.io/nfts/$id`
nft_coin_id=`echo "$nft_json" | jq '.id' | cut -c 2- | rev | cut -c 2- | rev`
nft_collection=`echo "$nft_json" | jq '.data.metadata_json.collection.name' | cut -c 2- | rev | cut -c 2- | rev`
nft_name=`echo "$nft_json" | jq '.data.metadata_json.name' | cut -c 2- | rev | cut -c 2- | rev`
nft_coin_id=`echo "$nft_json" | jq '.id' | cut --fields 2 --delimiter=\"`
nft_collection=`echo "$nft_json" | jq '.data.metadata_json.collection.name' | cut --fields 2 --delimiter=\"`
nft_name=`echo "$nft_json" | jq '.data.metadata_json.name' | cut --fields 2 --delimiter=\"`
echo -e "NFT ID: ${txtrst}$id${txtgrn}"
echo -e "NFT Collection: ${txtrst}$nft_collection${txtgrn}"
echo -e "NFT Name: ${txtrst}$nft_name${txtgrn}"
Expand Down Expand Up @@ -98,7 +98,7 @@ echo " 4. Get list of NFT IDs from Collection"
echo " 5. Get list of Owner Wallets from NFT IDs"
echo " 6. Get list of NFT Names from NFT IDs"
echo " 7. Name generators"
echo " X. Exit"
echo " x. Exit"
echo ""
read -p "Selection: " menu_selection

Expand Down Expand Up @@ -180,34 +180,38 @@ if [ "$menu_selection" == "3" ]; then
wallet_list=`chia wallet show -w nft | grep "Wallet ID" | cut -c 28- | tr '\n' ' '`
echo -e "NFT Wallets: ${txtrst}$wallet_list${bldgrn}"
echo ""
read -p "Wallet ID, or [Enter] for all? " answer_wallet
if [ "$answer_wallet" != "" ]; then
wallet_list="$answer_wallet"
fi
read -p "Wallet ID, or [Enter] for all, or [x] to cancel? " answer_wallet

all=0
for val in $wallet_list; do
if [ "$answer_wallet" != "X" ] && [ "$answer_wallet" != "x" ]; then

echo ""
echo "==== Wallet ID: $val ===="
if [ "$answer_wallet" != "" ]; then
wallet_list="$answer_wallet"
fi

c=`chia wallet nft list -i $val | grep "NFT identifier" | wc -l`
nft_ids=`chia wallet nft list -i $val | grep "NFT identifier" | cut -c 28-`
all=0
for val in $wallet_list; do

for id in $nft_ids; do
nft_json=`curl -s https://api.mintgarden.io/nfts/$id`
nft_collection=`echo "$nft_json" | jq '.data.metadata_json.collection.name' | cut -c 2- | rev | cut -c 2- | rev`
nft_name=`echo "$nft_json" | jq '.data.metadata_json.name' | cut -c 2- | rev | cut -c 2- | rev`
echo -e "${txtrst}$id [$nft_collection] $nft_name${bldgrn}"
done
echo ""
echo "==== Wallet ID: $val ===="

echo -e "Wallet Total: ${txtrst}$c${bldgrn}"
all=$(($all+$c))
c=`chia wallet nft list -i $val | grep "NFT identifier" | wc -l`
nft_ids=`chia wallet nft list -i $val | grep "NFT identifier" | cut -c 28-`

done
for id in $nft_ids; do
nft_json=`curl -s https://api.mintgarden.io/nfts/$id`
nft_collection=`echo "$nft_json" | jq '.data.metadata_json.collection.name' | cut --fields 2 --delimiter=\"`
nft_name=`echo "$nft_json" | jq '.data.metadata_json.name' | cut --fields 2 --delimiter=\"`
echo -e "${txtrst}$id [$nft_collection] $nft_name${bldgrn}"
done

echo ""
echo -e "Total number of NFTs: ${txtrst}$all${bldgrn}"
echo -e "Wallet Total: ${txtrst}$c${bldgrn}"
all=$(($all+$c))

done

echo ""
echo -e "Total number of NFTs: ${txtrst}$all${bldgrn}"
fi
fi

###########################################################
Expand All @@ -224,10 +228,12 @@ if [ "$menu_selection" == "4" ]; then
echo -e "For example: ${txtrst}col1kmrzafjx6ej8w79tz5vnjt4w8xuq2p6nmnheelgwwu3rsgsar0fsxc4wud${bldgrn}"
echo -e ""
read -p "Collection ID? " collection_id
nfts=`curl -s https://api.mintgarden.io/collections/$collection_id/nfts/ids`
echo "${txtrst}"
echo "$nfts" | jq '.[].encoded_id' | cut -c 2- | rev | cut -c 2- | rev
echo -e "${txtgrn}"
if [ "$collection_id" != "X" ] && [ "$collection_id" != "x" ]; then
nfts=`curl -s https://api.mintgarden.io/collections/$collection_id/nfts/ids`
echo -e "${txtrst}"
echo "$nfts" | jq '.[].encoded_id' | cut --fields 2 --delimiter=\"
echo -e "${txtgrn}"
fi
fi

###########################################################
Expand Down Expand Up @@ -259,8 +265,8 @@ if [ "$menu_selection" == "5" ]; then
n=1
for id in $nft_ids; do
nft_json=`curl -s https://api.mintgarden.io/nfts/$id`
nft_id=`echo "$nft_json" | jq '.encoded_id' | cut -c 2- | rev | cut -c 2- | rev`
nft_owner_wallet=`echo "$nft_json" | jq '.owner_address.encoded_id' | cut -c 2- | rev | cut -c 2- | rev`
nft_id=`echo "$nft_json" | jq '.encoded_id' | cut --fields 2 delimiter=\"`
nft_owner_wallet=`echo "$nft_json" | jq '.owner_address.encoded_id' | cut --fields 2 --delimiter=\"`
#outputting to the console screen slows the script down
if [ "$output_type" == "S" ] || [ "$output_type" == "s" ]; then
echo -e "${txtrst}$n. $id $nft_owner_wallet${bldgrn}"
Expand Down Expand Up @@ -301,8 +307,8 @@ if [ "$menu_selection" == "6" ]; then
n=1
for id in $nft_ids; do
nft_json=`curl -s https://api.mintgarden.io/nfts/$id`
nft_id=`echo "$nft_json" | jq '.encoded_id' | cut -c 2- | rev | cut -c 2- | rev`
nft_name=`echo "$nft_json" | jq '.data.metadata_json.name' | cut -c 2- | rev | cut -c 2- | rev`
nft_id=`echo "$nft_json" | jq '.encoded_id' | cut --fields 2 --delimiter=\"`
nft_name=`echo "$nft_json" | jq '.data.metadata_json.name' | cut --fields 2 --delimiter=\"`
if [ "$output_type" == "S" ] || [ "$output_type" == "s" ]; then
echo -e "${txtrst}$nft_id,$nft_name${bldgrn}"
fi
Expand Down

0 comments on commit 9003bc8

Please sign in to comment.