Skip to content

Commit

Permalink
File struct scripts fix (hyperledger#430)
Browse files Browse the repository at this point in the history
* Fix read_ledger, gen_indy_pool; add create_dirs

Signed-off-by: Dmitry Surnin <[email protected]>

* Remove dirs create form setup.py

Signed-off-by: Dmitry Surnin <[email protected]>

* Fix dir name in home folder

Signed-off-by: Dmitry Surnin <[email protected]>
  • Loading branch information
dsurnin authored and ashcherbakov committed Nov 3, 2017
1 parent 6c92abb commit a863af8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 56 deletions.
33 changes: 14 additions & 19 deletions build-scripts/ubuntu-1604/postinst_node
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,21 @@
if [ -f /home/indy/.indy ]; then
rm /home/indy/.indy
fi
mkdir -p /home/indy/.indy
chown -R indy:indy /home/indy/.indy

mkdir -p /var/lib/indy/
chown -R indy:indy /var/lib/indy/

# create indy config folder if does not exist
mkdir -p /etc/indy
mkdir -p /var/lib/indy/
mkdir -p /var/log/indy

# create indy config if does not exist
if [ ! -f /etc/indy/indy_config.py ]; then
touch /etc/indy/indy_config.py
fi
chown -R indy:indy /etc/indy/

# create indy log folder if does not exist
mkdir -p /var/log/indy
chown -R indy:indy /var/log/indy

# change permissions for plenum folders
#chown -R indy:indy /var/plenum/
#chown -R indy:indy /var/log/plenum
#chown -R indy:indy /etc/plenum

# create indy cli folder if does not exist
mkdir -p /home/indy/indy-cli
mkdir -p /home/indy/indy-cli/networks
chown -R indy:indy /home/indy/indy-cli
mkdir -p /home/indy/.indy-cli
mkdir -p /home/indy/.indy-cli/networks
chown -R indy:indy /home/indy/.indy-cli
chmod -R ug+rwx /home/indy/.indy-cli

# init_indy_node script
cat <<EOF > /usr/local/bin/init_indy_node
Expand Down Expand Up @@ -143,6 +130,14 @@ echo "CLI_NETWORK_DIR = '~/.indy-cli/networks'" >> /etc/indy/indy_config.py
echo "NODE_BASE_DATA_DIR = baseDir" >> /etc/indy/indy_config.py


chown -R indy:indy /etc/indy
chown -R indy:indy /var/lib/indy
chown -R indy:indy /var/log/indy
chmod -R ug+rwx /etc/indy
chmod -R ug+rwx /var/lib/indy
chmod -R ug+rwx /var/log/indy


# Automatically added from template:
if which py3compile >/dev/null 2>&1; then
py3compile -O -p indy-node /usr/local/lib/python3.5/dist-packages/
Expand Down
33 changes: 33 additions & 0 deletions scripts/create_dirs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

if [ "${SUDO_USER}" == "" ]; then
echo "It should be run with sudo"
exit
fi

# dirs to be created
node_dirs="/etc/indy /var/lib/indy /var/log/indy /home/${SUDO_USER}/.indy-cli"

# create dirs
for dr in $node_dirs
do
mkdir -p $dr
done

# generate base config if not exists
if [ ! -f /etc/indy/indy_config.py ]; then
echo "NETWORK_NAME = 'sandbox'" > /etc/indy/indy_config.py

echo "baseDir = '/var/lib/indy'" >> /etc/indy/indy_config.py
echo "NODE_BASE_DATA_DIR = baseDir" >> /etc/indy/indy_config.py
echo "CLI_BASE_DIR = '~/.indy-cli/'" >> /etc/indy/indy_config.py
echo "CLI_NETWORK_DIR = '~/.indy-cli/networks'" >> /etc/indy/indy_config.py
echo "LOG_DIR = '/var/log/indy'" >> /etc/indy/indy_config.py
fi

# grant permissions
for dr in $node_dirs
do
chown -R ${SUDO_USER}:${SUDO_USER} $dr
chmod -R ug+rwx $dr
done
29 changes: 6 additions & 23 deletions scripts/read_ledger
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,21 @@ def get_ledger_dir(node_name, client_name):
exit()

config = getConfig()
base_dir = config.baseDir if node_name else config.CLI_BASE_DIR
base_dir = config.CLI_BASE_DIR if client_name else config.baseDir
data_dir = config.clientDataDir if client_name else config.nodeDataDir
ledger_data_dir = os.path.join(base_dir, config.NETWORK_NAME, data_dir)
if not os.path.exists(ledger_data_dir):
# TODO: find a better way
ledger_data_dir = os.path.join('/home/indy/.indy', data_dir)
if not os.path.exists(ledger_data_dir):
logger.error(
"Can not find the directory with the ledger: {}".format(ledger_data_dir))
logger.error("Can not find the directory with the ledger: {}".format(ledger_data_dir))
exit()

target_dir = node_name
if client_name:
target_dir = client_name
elif node_name:
target_dir = node_name
else:
target_dir = None

if target_dir:
ledger_data_dir = os.path.join(ledger_data_dir, target_dir)
if not os.path.isdir(ledger_data_dir):
print("Specified Node or Client folder not found: {}".format(
ledger_data_dir))
print("Specified Node or Client folder not found: {}".format(ledger_data_dir))
exit()
return ledger_data_dir

Expand All @@ -88,28 +80,19 @@ def get_ledger_dir(node_name, client_name):
def get_ledger(type_, ledger_data_dir):
config = getConfig()

hash_store_name = None
ledger_name = None
if type_ == 'pool':
hash_store_name = 'pool'
ledger_name = config.poolTransactionsFile
elif type_ == 'domain':
hash_store_name = 'domain'
ledger_name = config.domainTransactionsFile
elif type_ == 'config':
hash_store_name = 'config'
ledger_name = config.configTransactionsFile
else:
print("Unknown ledger type: {}".format(type_))
exit()

hash_store = LevelDbHashStore(
dataDir=read_copy_ledger_data_dir,
fileNamePrefix=hash_store_name)
return Ledger(
CompactMerkleTree(hashStore=hash_store),
dataDir=ledger_data_dir,
fileName=ledger_name)
hash_store = LevelDbHashStore(dataDir=ledger_data_dir, fileNamePrefix=type_)
return Ledger(CompactMerkleTree(hashStore=hash_store), dataDir=ledger_data_dir, fileName=ledger_name)


def print_txns(ledger, args):
Expand Down
14 changes: 0 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@
LOG_DIR = os.path.join(BASE_DIR, "log")
CONFIG_FILE = os.path.join(BASE_DIR, "indy_config.py")

for path in [BASE_DIR, LOG_DIR]:
if not os.path.exists(path):
os.makedirs(path)

if not os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, 'w') as f:
msg = "# Here you can create config entries according to your " \
"needs.\n " \
"# For help, refer config.py in the indy package.\n " \
"# Any entry you add here would override that from config " \
"example\n"
f.write(msg)


setup(
name='indy-node-dev',
version=__version__,
Expand Down

0 comments on commit a863af8

Please sign in to comment.