Skip to content

Commit

Permalink
Merge pull request #4 from nikosch86/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
nikosch86 authored Jun 14, 2021
2 parents e18c4ae + 3db44a1 commit 216c13d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
6 changes: 1 addition & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
script to create droplet / instance on digitalocean or google cloud or setup a manually deployed machine

with sporestack it is possible to prepay a digitalocean instance using cryptocurrency,
the refund address can be used to get some of the payment back in case of an error on sporestacks side,
seemingly there are no refunds upon early termination of a prepaid instance.
sporestack supports the standard digitalocean regions, but currently there is no nice way to specify the instance size or image via the API,
so these values are fixed to the sporestack defaults for now (1GB, 1 Core, ubuntu 16.04)

Expand Down Expand Up @@ -33,7 +31,7 @@ supports installing wallets, for now only monero is supported.
## help
```
usage: stand-up.py [-h] [--target {digitalocean,gcloud,sporestack,manual}] [--digitalocean-api-key DIGITALOCEAN_API_KEY] [--gcloud-api-key-file GCLOUD_API_KEY_FILE]
[--gcloud-project-id GCLOUD_PROJECT_ID] [--sporestack-days SPORESTACK_DAYS] [--sporestack-refund-address SPORESTACK_REFUND_ADDRESS] [--sporestack-currency {btc,bch,bsv}]
[--gcloud-project-id GCLOUD_PROJECT_ID] [--sporestack-days SPORESTACK_DAYS] [--sporestack-currency {btc,bch,bsv}]
[--instance-ip INSTANCE_IP] [--name NAME] [--region REGION] [--size SIZE] [--image IMAGE] [--user USER] [--ssh-port SSH_PORT] [--ssh-connection-tries SSH_CONNECTION_TRIES]
[--ssh-wait-for-auth] [--tool TOOL] [--repo REPO] [--service {ipsec,proxy,shadowsocks,wireguard,ssh-pivot}] [--wallet {monero}] [--force] [--destroy] [--bare] [--no-kali]
[--compose-version COMPOSE_VERSION] [--verbose] [--quiet] [--ssh-private-key SSH_PRIVATE_KEY] [--create-private-key]
Expand All @@ -50,8 +48,6 @@ optional arguments:
Project ID for GCloud (default: first available project id)
--sporestack-days SPORESTACK_DAYS
How many days to prepay sporestack instance
--sporestack-refund-address SPORESTACK_REFUND_ADDRESS
Refund Address for sporestack instances that have been terminated early
--sporestack-currency {btc,bch,bsv}
Which currency to use for payment
--instance-ip INSTANCE_IP
Expand Down
38 changes: 18 additions & 20 deletions stand-up.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
argparser.add_argument("--gcloud-api-key-file", help="API key file for GCloud")
argparser.add_argument("--gcloud-project-id", help="Project ID for GCloud (default: first available project id)")
argparser.add_argument("--sporestack-days", help="How many days to prepay sporestack instance", default=1, type=int)
argparser.add_argument("--sporestack-refund-address", help="Refund Address for sporestack instances that have been terminated early", default=None)
argparser.add_argument("--sporestack-currency", help="Which currency to use for payment", default='btc', choices=['btc', 'bch', 'bsv', 'xmr'])
argparser.add_argument("--instance-ip", help="Instance IP if manual mode is used")
argparser.add_argument("--name", "-n", help="slug name (default: %(default)s)", default='investig')
argparser.add_argument("--region", "-r", help="region or zone (default: selects random region/zone)", default='random')
argparser.add_argument("--size", "-s", help="slug size or machine type (default: %(default)s)", default='2gb')
argparser.add_argument("--image", help="slug image (default: %(default)s)", default='ubuntu-16-04-x64')
argparser.add_argument("--image", help="slug image (default: %(default)s)", default='ubuntu-20-04-x64')
argparser.add_argument("--user", "-u", help="username to use for ssh connection (default: %(default)s)", default='root')
argparser.add_argument("--ssh-port", help="port to use for ssh connection (default: %(default)s)", default=22, type=int)
argparser.add_argument("--ssh-connection-tries", help="how many times to try to establish ssh connection (default: %(default)s)", default=30, type=int)
Expand Down Expand Up @@ -78,9 +77,9 @@ def cleanup_and_die(msg):
elif args.target == 'sporestack':
try:
instance_dict
machine_info = sporestackv2.client.get_machine_info(config['name'])
machine_info = sporestack.client.get_machine_info(config['name'])
logger.critical("calling delete() on instance id {}".format(machine_info['machine_id']))
sporestackv2.client.delete(config['name'], sporestackv2.client.API_ENDPOINT)
sporestack.client.delete(config['name'], sporestack.client.API_ENDPOINT)
except NameError:
logger.debug('no instance has been created yet')
try:
Expand All @@ -104,9 +103,9 @@ def cleanup_and_die(msg):
cleanup_and_die("please install the digitalocean module: 'pip install -U python-digitalocean'")

try:
import sporestackv2
import sporestack
except ImportError:
cleanup_and_die("please install the sporestackv2 module: 'pip install -U sporestack'")
cleanup_and_die("please install the sporestack module: 'pip install -U sporestack'")

try:
from google.oauth2 import service_account
Expand All @@ -115,7 +114,7 @@ def cleanup_and_die(msg):
cleanup_and_die("please install the gcloud module: 'pip install -U google-api-python-client'")

def write_config(configdict, configfile):
for nosave in ["bare", "no_kali", "create_private_key", "destroy", "force", "instance_ip", "name", "quiet", "verbose", "digitalocean_api_key", "gcloud_api_key_file", "gcloud_api_key_file", "ssh_wait_for_auth", "sporestack_refund_address"]:
for nosave in ["bare", "no_kali", "create_private_key", "destroy", "force", "instance_ip", "name", "quiet", "verbose", "digitalocean_api_key", "gcloud_api_key_file", "gcloud_api_key_file", "ssh_wait_for_auth"]:
if nosave in configdict: del configdict[nosave]
if not os.path.exists(os.path.dirname(configfile)):
os.mkdir(os.path.dirname(configfile))
Expand Down Expand Up @@ -537,33 +536,32 @@ def validate_digitalocean():
logger.info("setting up existing instance on IP {}".format(instance_ip))
elif args.target == 'sporestack':
if vars(args).get('destroy'):
if sporestackv2.client.machine_exists(config['name']):
machine_info = sporestackv2.client.get_machine_info(config['name'])
sporestackv2.client.delete(config['name'], sporestackv2.client.API_ENDPOINT)
if sporestack.client.machine_exists(config['name']):
machine_info = sporestack.client.get_machine_info(config['name'])
sporestack.client.delete(config['name'], sporestack.client.API_ENDPOINT)
cleanup_and_die("destroyed instance id {}, aborting".format(machine_info['machine_id']))
else:
cleanup_and_die("no instance with name {} found, aborting".format(config['name']))

if sporestackv2.client.machine_exists(config['name']):
machine_info = sporestackv2.client.get_machine_info(config['name'])
if sporestack.client.machine_exists(config['name']):
machine_info = sporestack.client.get_machine_info(config['name'])
logger.warning('the requested name "{}" is already taken'.format(config['name']))
if vars(args).get('force'):
sporestackv2.client.delete(config['name'], sporestackv2.client.API_ENDPOINT)
sporestack.client.delete(config['name'], sporestack.client.API_ENDPOINT)
logger.warning('force option is set, calling destroy() on existing instance id {}'.format(machine_info['machine_id']))
else:
exit(1)

try:
instance_dict = sporestackv2.client.launch(config['name'],
instance_dict = sporestack.client.launch(config['name'],
config['sporestack_days'], # days,
5, # disk,
1, # memory,
'/32', # ipv4,
'/128', # ipv6,
1, # bandwidth,
'digitalocean.sporestack.com', # host=None,
sporestackv2.client.API_ENDPOINT, # api_endpoint=API_ENDPOINT,
config['sporestack_refund_address'], # refund_address=None,
sporestack.client.API_ENDPOINT, # api_endpoint=API_ENDPOINT,
1, # cores=1,
config['sporestack_currency'], # currency='bch',
config['region'], # region=None,
Expand Down Expand Up @@ -651,7 +649,7 @@ def validate_digitalocean():
echo \"deb http://http.kali.org/kali kali-rolling main non-free contrib\" > /etc/apt/sources.list.d/kali.list && \
echo \"deb-src http://http.kali.org/kali kali-rolling main non-free contrib\" >> /etc/apt/sources.list.d/kali.list && \
export DEBIAN_FRONTEND=noninteractive; apt-get -q update && \
apt-get -o Dpkg::Options::=\"--force-overwrite\" -yq install console-setup-linux")
apt-get -o Dpkg::Options::=\"--force-overwrite\" -yq install console-setup-linux software-properties-common")
logger.debug("".join(stdout.readlines()))
if stdout.channel.recv_exit_status() > 0: logger.critical("STDERR of setup command: {}".format(stderr.read()))
printProgressBar(12)
Expand All @@ -666,7 +664,7 @@ def validate_digitalocean():
printProgressBar(13)

logger.info('installing tools "{}"'.format(standard_tools))
stdin, stdout, stderr = ssh.exec_command("export DEBIAN_FRONTEND=noninteractive; apt-get -yq install {}".format("zlib1g-dev ruby-dev python-pip"))
stdin, stdout, stderr = ssh.exec_command("export DEBIAN_FRONTEND=noninteractive; apt-get -yq install {}".format("zlib1g-dev ruby-dev python3-pip"))
logger.debug("".join(stdout.readlines()))
if stdout.channel.recv_exit_status() > 0: logger.critical("STDERR of setup command: {}".format(stderr.read()))

Expand Down Expand Up @@ -714,7 +712,7 @@ def validate_digitalocean():
logger.info('installing wallet {}'.format(item))

if item == 'monero':
stdin, stdout, stderr = ssh.exec_command("curl -L -o linux64.tar.bz2 https://downloads.getmonero.org/cli/linux64 && tar xf linux64.tar.bz2")
stdin, stdout, stderr = ssh.exec_command("curl -L -o linux64.tar.bz2 https://downloads.getmonero.org/cli/linux64 && tar xf linux64.tar.bz2 && rm linux64.tar.bz2")
logger.debug("".join(stdout.readlines()))
if stdout.channel.recv_exit_status() > 0: logger.critical("STDERR of setup command: {}".format(stderr.read()))
printProgressBar(18)
Expand Down Expand Up @@ -770,7 +768,7 @@ def validate_digitalocean():
print("\nsocks5 {} {} user {}".format(instance_ip, 1080, proxy_password))

if service == 'wireguard':
stdin, stdout, stderr = ssh.exec_command("export DEBIAN_FRONTEND=noninteractive; add-apt-repository -yu ppa:wireguard/wireguard && apt-get -yq install wireguard")
stdin, stdout, stderr = ssh.exec_command("export DEBIAN_FRONTEND=noninteractive; apt-get -yq install wireguard")
logger.debug("".join(stdout.readlines()))
if stdout.channel.recv_exit_status() > 0: logger.critical("STDERR of setup command: {}".format(stderr.read()))
sftp = ssh.open_sftp()
Expand Down

0 comments on commit 216c13d

Please sign in to comment.