Skip to content

Commit

Permalink
feat: input data for data.json & keys.env while installing
Browse files Browse the repository at this point in the history
  • Loading branch information
StafLoker committed Dec 21, 2024
1 parent 2550c1e commit 661aa19
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,44 +92,65 @@ tar -xzvf "${install_dir}/${VERSION}.tar.gz" -C "$install_dir"
rm -f "${install_dir}/${VERSION}.tar.gz"

# Move the extracted files to the correct location
if [ -f "${install_dir}/ddns-porkbun-script-${VERSION#v}/ddns-porkbun-script.sh" ] && \
[ -f "${install_dir}/ddns-porkbun-script-${VERSION#v}/LICENSE" ] && \
[ -f "${install_dir}/ddns-porkbun-script-${VERSION#v}/README.md" ]; then
if [ -f "${install_dir}/ddns-porkbun-script-${VERSION#v}/ddns-porkbun-script.sh" ] &&
[ -f "${install_dir}/ddns-porkbun-script-${VERSION#v}/LICENSE" ] &&
[ -f "${install_dir}/ddns-porkbun-script-${VERSION#v}/README.md" ]; then
mv "${install_dir}/ddns-porkbun-script-${VERSION#v}/ddns-porkbun-script.sh" \
"${install_dir}/ddns-porkbun-script-${VERSION#v}/LICENSE" \
"${install_dir}/ddns-porkbun-script-${VERSION#v}/README.md" \
"$install_dir/"
"${install_dir}/ddns-porkbun-script-${VERSION#v}/LICENSE" \
"${install_dir}/ddns-porkbun-script-${VERSION#v}/README.md" \
"$install_dir/"
else
log_error "One or more files are missing in the source directory."
exit 1
fi
rm -rf "${install_dir}/ddns-porkbun-script-${VERSION#v}"

log_info "Checking for keys.env file..."
# Create the keys.env file if it doesn't exist in the install directory
if [ ! -f "${install_dir}/keys.env" ]; then
log_info "- Creating keys.env file..."
echo 'PORKBUN_API_KEY="pk"' > "${install_dir}/keys.env"
echo 'PORKBUN_SECRET_API_KEY="sk"' >> "${install_dir}/keys.env"
read -p "Enter your Porkbun API key: " api_key
read -p "Enter your Porkbun secret API key: " secret_api_key
echo "PORKBUN_API_KEY=\"${api_key}\"" >"${install_dir}/keys.env"
echo "PORKBUN_SECRET_API_KEY=\"${secret_api_key}\"" >>"${install_dir}/keys.env"
chmod 600 "${install_dir}/keys.env"
else
log_success "keys.env file already exists."
fi

log_info "Checking for data.json file..."
# Create the data.json file if it doesn't exist in the install directory
if [ ! -f "${install_dir}/data.json" ]; then
log_info "- Creating data.json file..."
cat <<EOF > "${install_dir}/data.json"
read -p "Enter your domain (e.g., example.com): " domain
read -p "Do you want to enable concurrency? (yes/no): " concurrency
if [ "$concurrency" = "yes" ]; then
concurrency_value="true"
else
concurrency_value="false"
fi
log_info "Enter your subdomains one by one. Type '0' when you are finished."

subdomains_list=()
while true; do
read -p "Enter a subdomain (or type '0' to finish): " subdomain
if [[ "$subdomain" == "0" ]]; then
break
fi
if [[ -n "$subdomain" ]]; then
subdomains_list+=("$subdomain")
fi
done

subdomains_json=$(printf '"%s",' "${subdomains_list[@]}")
subdomains_json="[${subdomains_json%,}]"

cat <<EOF >"${install_dir}/data.json"
{
"domain": "example.com",
"concurrency": true,
"subdomains": [
"sub1",
"sub2"
]
"domain": "${domain}",
"concurrency": ${concurrency_value},
"subdomains": ${subdomains_json}
}
EOF

else
log_success "data.json file already exists."
fi
Expand All @@ -150,5 +171,3 @@ log_info "Making the main script executable..."
chmod +x "${install_dir}/ddns-porkbun-script.sh"

log_success "Installation or update of ddns-porkbun-script version $VERSION completed successfully!"

log_warning "Please configure the keys.env and data.json files before use."

0 comments on commit 661aa19

Please sign in to comment.