Skip to content

Commit

Permalink
2.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
geopsllc committed Aug 7, 2019
1 parent d4bcffe commit d6fc868
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 20 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cd core-control
| `config` | `reset` | Reset Config Files to Defaults |
| `database` | `clear` | Clear the Database |
| `rollback` | | Rollback to Specified Height |
| `plugin` | `list`/`add`/`remove`/`update` | Manage Core Plugins |

## General
This is a Streamlined CLI-Based Core v2 Management Tool.
Expand All @@ -32,6 +33,7 @@ This is a Streamlined CLI-Based Core v2 Management Tool.
- For install/remove you can skip the 'core' argument as it's the default.
- For update you can skip the 'check' argument as it's the default.
- For system you can skip the 'info' argument as it's the default.
- For plugin you can skip the 'list' argument as it's the default.
- When setting a delegate secret just type your secret after the 'set' argument without quotes.
- When doing a rollback just type the desired height after the 'rollback' argument.
- Rollback will stop the running processes, do the rollback and start the processes that were online.
Expand All @@ -45,11 +47,15 @@ using: ccontrol arg1 [arg2]. It also has autocomplete functionality for all poss
If you're running a forger and/or have custom settings, you should add them again.
- Using the 'database clear' arguments will stop the core processes, wipe the database clean, and start the processes that were online before.
The end result is that your node will start syncing from 0.
- For plugin management just type the name of the plugin after 'plugin add/remove/update' as it appears in the list.
- On first run the tool exposes the core-cli with the project name, e.g. ark for project Ark. It will be accessible after logout.
- Do not run as root!

## Changelog

### 2.5.1
- added plugin manager

### 2.5
- updated for core 2.5

Expand Down
5 changes: 4 additions & 1 deletion cccomp.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ccontrol_completions () {
prev=${COMP_WORDS[COMP_CWORD-1]}

if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen -W "install update remove secret start restart stop status logs snapshot system config database rollback" -- $cur) )
COMPREPLY=( $(compgen -W "install update remove secret start restart stop status logs snapshot system config database rollback plugin" -- $cur) )
elif [ $COMP_CWORD -eq 2 ]; then
case "$prev" in
"install")
Expand Down Expand Up @@ -39,6 +39,9 @@ ccontrol_completions () {
"database")
COMPREPLY=( $(compgen -W "clear" -- $cur) )
;;
"plugin")
COMPREPLY=( $(compgen -W "list add remove update" -- $cur) )
;;
*)
;;
esac
Expand Down
19 changes: 19 additions & 0 deletions ccontrol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,25 @@ main () {

echo -e "\n${green}All Done!${nc}\n"

elif [[ ( "$1" = "plugin" ) && ( ( ( "$2" = "add" || "$2" = "remove" || "$2" = "update" ) && ! -z "$3" && -z "$4" ) || ( ( "$2" = "list" || -z "$2" ) && -z "$3" ) ) ]]; then

if [[ ! -d $data || ! -d $core ]]; then
echo -e "\n${red}Core not installed. Please install first.${nc}\n"
exit 1
elif [[ ! -d plugins || -z "$(ls plugins)" ]]; then
echo -e "\n${red}No plugins found.${nc}\n"
exit 1
fi

if [ -z "$2" ]; then
set -- "$2" "list"
fi

if [ "$2" = "list" ]; then
plugin_list
else
plugin_manage $2 $3
fi

else

Expand Down
137 changes: 119 additions & 18 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
wrong_arguments () {

echo -e "\nMissing: arg1 [arg2]\n"
echo -e " ----------------------------------------------------------------------"
echo -e "| arg1 | arg2 | Description |"
echo -e " ----------------------------------------------------------------------"
echo -e "| install | core | Install Core |"
echo -e "| update | core / self / check | Update Core / Core-Control / Check |"
echo -e "| remove | core / self | Remove Core / Core-Control |"
echo -e "| secret | set / clear | Delegate Secret Set / Clear |"
echo -e "| start | relay / forger / all | Start Core Services |"
echo -e "| restart | relay / forger / all | Restart Core Services |"
echo -e "| stop | relay / forger / all | Stop Core Services |"
echo -e "| status | relay / forger / all | Show Core Services Status |"
echo -e "| logs | relay / forger / all | Show Core Logs |"
echo -e "| snapshot | create / restore | Snapshot Create / Restore |"
echo -e "| system | info / update | System Info / Update |"
echo -e "| config | reset | Reset Config Files to Defaults |"
echo -e "| database | clear | Clear the Database |"
echo -e "| rollback | | Rollback to Specified Height |"
echo -e " ----------------------------------------------------------------------\n"
echo -e " ------------------------------------------------------------------------------"
echo -e "| arg1 | arg2 | Description |"
echo -e " ------------------------------------------------------------------------------"
echo -e "| install | core | Install Core |"
echo -e "| update | core / self / check | Update Core / Core-Control / Check |"
echo -e "| remove | core / self | Remove Core / Core-Control |"
echo -e "| secret | set / clear | Delegate Secret Set / Clear |"
echo -e "| start | relay / forger / all | Start Core Services |"
echo -e "| restart | relay / forger / all | Restart Core Services |"
echo -e "| stop | relay / forger / all | Stop Core Services |"
echo -e "| status | relay / forger / all | Show Core Services Status |"
echo -e "| logs | relay / forger / all | Show Core Logs |"
echo -e "| snapshot | create / restore | Snapshot Create / Restore |"
echo -e "| system | info / update | System Info / Update |"
echo -e "| config | reset | Reset Config Files to Defaults |"
echo -e "| database | clear | Clear the Database |"
echo -e "| rollback | | Rollback to Specified Height |"
echo -e "| plugin | list / add / remove / update | Manage Core Plugins |"
echo -e " ------------------------------------------------------------------------------\n"
exit 1

}
Expand Down Expand Up @@ -508,3 +509,103 @@ db_clear () {
fi

}

plugin_list () {

echo -e "\nAvailable plugins:\n"

for plugin in $(ls plugins); do

. "plugins/$plugin"

if [ -z "$(cat $config/plugins.js | grep $plugin)" ]; then
echo -e "${cyan}$plugin${nc} - ${red}inactive${nc} [$desc]"
else
echo -e "${cyan}$plugin${nc} - ${green}active${nc} [$desc]"
fi

done

echo

}

plugin_manage () {

if [ ! -f plugins/$2 ]; then
echo -e "\n${red}Plugin not found.${nc}\n"
exit 1
else
. "plugins/$2"
fi

added="$(cat $config/plugins.js | grep $2)"
lastline='};'
blockend='},'
stab=' '


if [[ "$1" = "add" && -z "$added" ]]; then

alen=${#options[@]}
insert="$stab\"$npmrepo\/$2\": {\n"

for i in ${!options[@]}; do
insert="$insert\t${options[$i]}"
comp=$((i+1))
if [ "$comp" -lt "$alen" ]; then
insert="$insert,\n"
else
insert="$insert\n"
fi
done

insert="$insert$stab$blockend\n"
sed -i "s/$lastline/$insert$lastline/" $config/plugins.js

mkdir $core/node_modules/$npmrepo > /dev/null 2>&1
git clone $gitrepo/$2 $core/node_modules/$npmrepo/$2 > /dev/null 2>&1

echo -e "\n${green}Plugin $2 installed with default settings.${nc}\n"
echo -e "${red}Restart Core for the changes to take effect.${nc}\n"
echo -e "${cyan}For more information and custom configuration${nc}"
echo -e "${cyan}visit $gitrepo/$2${nc}\n"

elif [[ "$1" = "add" && ! -z "$added" ]]; then

echo -e "\n${red}Plugin already installed.${nc}\n"


elif [[ "$1" = "remove" && ! -z "$added" ]]; then

sed -i "/$2/,/$blockend/d" $config/plugins.js
rm -rf $core/node_modules/$npmrepo/$2 > /dev/null 2>&1

echo -e "\n${green}Plugin $2 removed successfully.${nc}\n"
echo -e "${red}Restart Core for the changes to take effect.${nc}\n"

elif [[ "$1" = "remove" && -z "$added" ]]; then

echo -e "\n${red}Plugin not installed.${nc}\n"

elif [[ "$1" = "update" && ! -z "$added" ]]; then

cd $core/node_modules/$npmrepo/$2 > /dev/null 2>&1
git_check

if [ "$up2date" = "yes" ]; then
echo -e "Already up-to-date."
exit 1
fi

git pull

echo -e "\n${red}Restart Core for the changes to take effect.${nc}\n"

else

echo -e "\n${red}Plugin not installed.${nc}\n"

fi

}
1 change: 1 addition & 0 deletions misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

i=1
sp="/-\|"

red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
Expand Down
4 changes: 4 additions & 0 deletions plugins/block-propagator
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
desc='Block Propagator for Ark-powered blockchains'
npmrepo='@alessiodf'
gitrepo='https://github.com/alessiodf'
options[0]='enabled: true'
5 changes: 5 additions & 0 deletions plugins/round-monitor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
desc='Round Monitor for Ark-powered blockchains'
npmrepo='@alessiodf'
gitrepo='https://github.com/alessiodf'
options[0]='enabled: true'
options[1]='delegate: \"del_name\"'
2 changes: 1 addition & 1 deletion project.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ rpc_port="8080"
core="$HOME/${name}-core"
data="$HOME/.config/${name}-core"
config="$data/$network"
version="2.5"
version="2.5.1"

0 comments on commit d6fc868

Please sign in to comment.