Set trove parameters within control panel

This commit is contained in:
Bob Mottram 2016-01-27 11:47:33 +00:00
parent 5064ca9413
commit 88abf63a9d
1 changed files with 100 additions and 16 deletions

View File

@ -47,11 +47,9 @@ MINIMUM_PASSWORD_LENGTH=8
VOIP_PORT=64738
VOIP_ONION_PORT=8095
PROJECT_REPO="https://github.com/bashrc/${PROJECT_NAME}"
USB_DRIVE=sdb
# get default USB from config file
CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
CONFIGURATION_FILE=/root/${PROJECT_NAME}.cfg
if [ -f $CONFIGURATION_FILE ]; then
if grep -q "USB_DRIVE=" $CONFIGURATION_FILE; then
USB_DRIVE=$(cat $CONFIGURATION_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
@ -59,12 +57,14 @@ if [ -f $CONFIGURATION_FILE ]; then
USB_DRIVE=$(echo ${USB_DRIVE} | awk -F '/' '{print $3}' | sed 's|1||g' | sed 's|2||g')
fi
fi
# read the location of the main project repo
if grep -q "PROJECT_REPO" $CONFIGURATION_FILE; then
PROJECT_REPO=$(grep "PROJECT_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi
fi
# Trove settings
FRIENDS_TROVE_SERVER=
FRIENDS_TROVE_SSH_PORT=2222
FRIENDS_TROVE_PASSWORD=
MY_TROVE_PASSWORD=
function any_key {
echo ' '
read -n1 -r -p $"Press any key to continue..." key
@ -82,21 +82,104 @@ function check_for_updates {
any_key
}
function read_repo_servers {
if [ -f $CONFIGURATION_FILE ]; then
if grep -q "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE; then
FRIENDS_TROVE_SERVER=$(grep "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi
if grep -q "FRIENDS_TROVE_SSH_PORT" $CONFIGURATION_FILE; then
FRIENDS_TROVE_SSH_PORT=$(grep "FRIENDS_TROVE_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi
if grep -q "MY_TROVE_PASSWORD" $CONFIGURATION_FILE; then
MY_TROVE_PASSWORD=$(grep "MY_TROVE_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi
if grep -q "FRIENDS_TROVE_PASSWORD" $CONFIGURATION_FILE; then
FRIENDS_TROVE_PASSWORD=$(grep "FRIENDS_TROVE_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi
fi
if [ ! $FRIENDS_TROVE_SERVER ]; then
return
fi
if [ ${#FRIENDS_TROVE_SERVER} -lt 2 ]; then
return
fi
MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME}
if [ ! -f $MAIN_COMMAND ]; then
MAIN_COMMAND=/usr/bin/${PROJECT_NAME}
fi
REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g'))
for line in "${REPOS[@]}"
do
repo_name=$(echo "$line" | awk -F '=' '{print $1}')
trove_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}')
friends_repo_url="ssh://trove@${FRIENDS_TROVE_SERVER}:${FRIENDS_TROVE_SSH_PORT}/home/trove/${trove_name}"
${repo_name}="${friends_repo_url}"
done
}
function set_main_repo {
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"Main Repository" \
--inputbox $"Set the main repository:" 8 70 "$PROJECT_REPO" 2>data
--title $"Main Repository (Trove)" \
--form "\n" 8 60 3 \
$"URL:" 1 1 "$FRIENDS_TROVE_SERVER" 1 14 40 15 \
$"SSH Port:" 2 1 "$FRIENDS_TROVE_SSH_PORT" 2 14 40 10000 \
$"Password:" 3 1 "$FRIENDS_TROVE_PASSWORD" 3 14 40 10000 \
2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
repo=$(cat $data)
if [[ $repo == *"."* ]]; then
PROJECT_REPO=$(cat $data)
new_trove_url=$(cat $data | sed -n 1p)
new_trove_ssh_port=$(cat $data | sed -n 2p)
new_trove_password=$(cat $data | sed -n 3p)
if [ ${#new_trove_url} -lt 2 ]; then
return
fi
if [ ${#new_trove_ssh_port} -lt 1 ]; then
return
fi
if [ ${#new_trove_password} -lt 10 ]; then
dialog --title $"Main Repository" \
--msgbox $"Main repository set to $PROJECT_REPO" 6 40
--msgbox $'Trove password was too short. Should be at least 10 characters.' 6 40
return
fi
if [[ $new_trove_url == *"."* ]]; then
FRIENDS_TROVE_SERVER=$new_trove_url
FRIENDS_TROVE_SSH_PORT=$new_trove_ssh_port
FRIENDS_TROVE_PASSWORD=$new_trove_password
if ! grep -q "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE; then
echo "FRIENDS_TROVE_SERVER=$FRIENDS_TROVE_SERVER" >> $CONFIGURATION_FILE
else
sed -i "s|FRIENDS_TROVE_SERVER=.*|FRIENDS_TROVE_SERVER=$FRIENDS_TROVE_SERVER|g" $CONFIGURATION_FILE
fi
if ! grep -q "FRIENDS_TROVE_SSH_PORT" $CONFIGURATION_FILE; then
echo "FRIENDS_TROVE_SSH_PORT=$FRIENDS_TROVE_SSH_PORT" >> $CONFIGURATION_FILE
else
sed -i "s|FRIENDS_TROVE_SSH_PORT=.*|FRIENDS_TROVE_SSH_PORT=$FRIENDS_TROVE_SSH_PORT|g" $CONFIGURATION_FILE
fi
if ! grep -q "FRIENDS_TROVE_PASSWORD" $CONFIGURATION_FILE; then
echo "FRIENDS_TROVE_PASSWORD=$FRIENDS_TROVE_PASSWORD" >> $CONFIGURATION_FILE
else
sed -i "s|FRIENDS_TROVE_PASSWORD=.*|FRIENDS_TROVE_PASSWORD=$FRIENDS_TROVE_PASSWORD|g" $CONFIGURATION_FILE
fi
# re-read the repos
read_repo_servers
dialog --title $"Main Repository" \
--msgbox $"Main repository set to $FRIENDS_TROVE_SERVER" 6 60
fi
}
@ -105,9 +188,9 @@ function add_user {
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"Add new user" \
--form "\n" 8 40 3 \
$"Username:" 1 1 "" 1 11 16 15 \
$"ssh public key (optional):" 2 1 "" 3 1 40 10000 \
--form "\n" 8 60 3 \
$"Username:" 1 1 "" 1 28 16 15 \
$"ssh public key (optional):" 2 1 "" 2 28 40 10000 \
2> $data
sel=$?
case $sel in
@ -1455,6 +1538,7 @@ if [ ! -f $COMPLETION_FILE ]; then
fi
ADMIN_USER=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
read_repo_servers
menu_top_level
clear
cat /etc/motd