Skip to content

Commit

Permalink
added dynamic docker compose file loader
Browse files Browse the repository at this point in the history
  • Loading branch information
MRColorR committed Nov 21, 2022
1 parent 16f16f4 commit bca3006
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
33 changes: 17 additions & 16 deletions runme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ $BITPING_LNK = "BITPING | https://app.bitping.com?r=qm7mIuX3"
### .env File Prototype Link##
$ENV_SRC = 'https://github.com/MRColorR/money4band/raw/main/.env'

### docker-compose.yml Prototype Link##
$DKCOM_SRC = 'https://github.com/MRColorR/money4band/raw/main/docker-compose.yml'
### docker compose.yaml Prototype Link##
$DKCOM_FILENAME = "docker-compose.yaml"
$DKCOM_SRC = "https://github.com/MRColorR/money4band/raw/main/$DKCOM_FILENAME"

### Docker installer script for windows source link ##
$DKINST_WIN_SRC = 'https://github.com/MRColorR/money4band/raw/main/.resources/.scripts/install-docker.ps1'
Expand Down Expand Up @@ -108,9 +109,9 @@ function fn_setupNotifications() {
Write-Output "NOW INSERT BELOW THE LINK FOR NOTIFICATIONS using THE SAME FORMAT WRITTEN ABOVE e.g.: discord://yourToken@yourWebhookid"
$SHOUTRRR_URL = Read-Host
(Get-Content .\.env).replace('# SHOUTRRR_URL=yourApp:yourToken@yourWebHook', "SHOUTRRR_URL=$SHOUTRRR_URL") | Set-Content .\.env
(Get-Content .\docker-compose.yml).replace('# - WATCHTOWER_NOTIFICATIONS=shoutrrr', "- WATCHTOWER_NOTIFICATIONS=shoutrrr") | Set-Content .\docker-compose.yml
(Get-Content .\docker-compose.yml).replace('# - WATCHTOWER_NOTIFICATION_URL', "- WATCHTOWER_NOTIFICATION_URL") | Set-Content .\docker-compose.yml
(Get-Content .\docker-compose.yml).replace('# - WATCHTOWER_NOTIFICATIONS_HOSTNAME', "- WATCHTOWER_NOTIFICATIONS_HOSTNAME") | Set-Content .\docker-compose.yml
(Get-Content .\$DKCOM_FILENAME).replace('# - WATCHTOWER_NOTIFICATIONS=shoutrrr', "- WATCHTOWER_NOTIFICATIONS=shoutrrr") | Set-Content .\$DKCOM_FILENAME
(Get-Content .\$DKCOM_FILENAME).replace('# - WATCHTOWER_NOTIFICATION_URL', "- WATCHTOWER_NOTIFICATION_URL") | Set-Content .\$DKCOM_FILENAME
(Get-Content .\$DKCOM_FILENAME).replace('# - WATCHTOWER_NOTIFICATIONS_HOSTNAME', "- WATCHTOWER_NOTIFICATIONS_HOSTNAME") | Set-Content .\$DKCOM_FILENAME
Read-Host -p "Notifications setup complete. If the link is correct, you will receive a notification for each update made on the app container images. Now press enter to continue"
Clear-Host
}
Expand Down Expand Up @@ -172,9 +173,9 @@ function fn_setupApp() {
(Get-Content .\.env).replace("# ${CURRENT_APP}_HTTPS_PROXY=http://proxyUsername:proxyPassword@proxy_url:proxy_port", "${CURRENT_APP}_HTTPS_PROXY=$APP_HTTPS_PROXY") | Set-Content .\.env
}

(Get-Content .\docker-compose.yml).replace("#- ${CURRENT_APP}_HTTP_PROXY", "- HTTP_PROXY") | Set-Content .\docker-compose.yml
(Get-Content .\docker-compose.yml).replace("#- ${CURRENT_APP}_HTTPS_PROXY", "- HTTPS_PROXY") | Set-Content .\docker-compose.yml
(Get-Content .\docker-compose.yml).replace("#- ${CURRENT_APP}_NO_PROXY", "- NO_PROXY") | Set-Content .\docker-compose.yml
(Get-Content .\$DKCOM_FILENAME).replace("#- ${CURRENT_APP}_HTTP_PROXY", "- HTTP_PROXY") | Set-Content .\$DKCOM_FILENAME
(Get-Content .\$DKCOM_FILENAME).replace("#- ${CURRENT_APP}_HTTPS_PROXY", "- HTTPS_PROXY") | Set-Content .\$DKCOM_FILENAME
(Get-Content .\$DKCOM_FILENAME).replace("#- ${CURRENT_APP}_NO_PROXY", "- NO_PROXY") | Set-Content .\$DKCOM_FILENAME
}
Read-Host -p "${CURRENT_APP} configuration complete, press enter to continue to the next app"
}
Expand Down Expand Up @@ -225,13 +226,13 @@ function fn_setupProxy() {

function fn_setupEnv {
Clear-Host
$yn = Read-Host -p "Do you wish to proceed with the .env file guided setup Y/N? (This will also adapt the docker-compose.yml file accordingly)"
$yn = Read-Host -p "Do you wish to proceed with the .env file guided setup Y/N? (This will also adapt the $DKCOM_FILENAME file accordingly)"
if ($yn -eq 'Y' -or $yn -eq 'y' -or $yn -eq 'Yes' -or $yn -eq 'yes' ) {
Clear-Host
if ( -Not (Select-String -Path .\.env -Pattern "DEVICE_NAME=yourDeviceName" -Quiet) ) {
Write-Output "The current .env file appears to have already been modified. A fresh version will be downloaded and used."
Invoke-WebRequest -OutFile '.env' $ENV_SRC;
Invoke-WebRequest -OutFile 'docker-compose.yml' $DKCOM_SRC;
Invoke-WebRequest -OutFile "$DKCOM_FILENAME" $DKCOM_SRC;
}
Write-Output "Beginnning env file guided setup"
$CURRENT_APP = '';
Expand Down Expand Up @@ -333,7 +334,7 @@ function fn_setupEnv {

function fn_startStack {
Clear-Host
Write-Output "This menu item will launch all the apps using the configured .env file and the docker-compose.yml file (Docker must be already installed and running)"
Write-Output "This menu item will launch all the apps using the configured .env file and the $DKCOM_FILENAME file (Docker must be already installed and running)"
$yn = Read-Host -prompt "Do you wish to proceed Y/N?"
if ($yn -eq 'Y' -or $yn -eq 'y' -or $yn -eq 'Yes' -or $yn -eq 'yes' ) {
docker compose up -d
Expand All @@ -350,7 +351,7 @@ function fn_startStack {

function fn_stopStack() {
Clear-Host
Write-Output "This menu item will stop all the apps and delete the docker stack previously created using the configured .env file and the docker-compose.yml file."
Write-Output "This menu item will stop all the apps and delete the docker stack previously created using the configured .env file and the $DKCOM_FILENAME file."
Write-Output "You don't need to use this command to temporarily pause apps or to update the stack. Use it only in case of uninstallation!"
$yn = Read-Host -prompt "Do you wish to proceed Y/N?"
if ($yn -eq 'Y' -or $yn -eq 'y' -or $yn -eq 'Yes' -or $yn -eq 'yes' ) {
Expand Down Expand Up @@ -383,15 +384,15 @@ function fn_resetEnv {
}

function fn_resetDockerCompose {
Write-Output "Now a fresh docker-compose.yml file will be downloaded"
Write-Output "Now a fresh $DKCOM_FILENAME file will be downloaded"
$yn = Read-Host -prompt "Do you wish to proceed Y/N? "
if ($yn -eq 'Y' -or $yn -eq 'y' -or $yn -eq 'Yes' -or $yn -eq 'yes' ) {
Invoke-WebRequest -OutFile 'docker-compose.yml' $DKCOM_SRC; Write-Output "docker-compose.yml file resetted, remember to reconfigure it if needed";
Invoke-WebRequest -OutFile "$DKCOM_FILENAME" $DKCOM_SRC; Write-Output "$DKCOM_FILENAME file resetted, remember to reconfigure it if needed";
Read-Host -prompt "Press enter to go back to the menu";
mainmenu;
}
else {
Write-Output "docker-compose.yml file reset canceled. The file is left as it is. "
Write-Output "$DKCOM_FILENAME file reset canceled. The file is left as it is. "
Read-Host -prompt "Press enter to go back to the menu";
mainmenu;
}
Expand All @@ -407,7 +408,7 @@ function mainmenu {
Write-Output "4) Start apps stack"
Write-Output "5) Stop apps stack"
Write-Output "6) Reset .env File"
Write-Output "7) Reset docker-compose.yml file"
Write-Output "7) Reset $DKCOM_FILENAME file"
Write-Output "8) Exit"
Do {
$Select = Read-Host
Expand Down
36 changes: 18 additions & 18 deletions runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ readonly BITPING_LNK="BITPING | https://app.bitping.com?r=qm7mIuX3"
### .env File Prototype Link##
readonly ENV_SRC='https://github.com/MRColorR/money4band/raw/main/.env';

### docker-compose.yml Prototype Link##
readonly DKCOM_SRC='https://github.com/MRColorR/money4band/raw/main/docker-compose.yml';
### docker compose.yaml Prototype Link##
readonly DKCOM_FILENAME="docker-compose.yaml"
readonly DKCOM_SRC="https://github.com/MRColorR/money4band/raw/main/$DKCOM_FILENAME";

### Resources, Scripts and Files folders
readonly RESOURCES_DIR="$PWD/.resources"
Expand Down Expand Up @@ -87,16 +88,16 @@ fn_setupNotifications(){
printf "NOW INSERT BELOW THE LINK FOR NOTIFICATIONS using THE SAME FORMAT WRITTEN ABOVE e.g.: discord://yourToken@yourWebhookid"$'\n'
read -r SHOUTRRR_URL
sed -i "s^# SHOUTRRR_URL=yourApp:yourToken@yourWebHook^SHOUTRRR_URL=$SHOUTRRR_URL^" .env
sed -i "s/# - WATCHTOWER_NOTIFICATIONS=shoutrrr/- WATCHTOWER_NOTIFICATIONS=shoutrrr/" docker-compose.yml
sed -i "s/# - WATCHTOWER_NOTIFICATION_URL/- WATCHTOWER_NOTIFICATION_URL/" docker-compose.yml
sed -i "s/# - WATCHTOWER_NOTIFICATIONS_HOSTNAME/- WATCHTOWER_NOTIFICATIONS_HOSTNAME/" docker-compose.yml
sed -i "s/# - WATCHTOWER_NOTIFICATIONS=shoutrrr/- WATCHTOWER_NOTIFICATIONS=shoutrrr/" $DKCOM_FILENAME
sed -i "s/# - WATCHTOWER_NOTIFICATION_URL/- WATCHTOWER_NOTIFICATION_URL/" $DKCOM_FILENAME
sed -i "s/# - WATCHTOWER_NOTIFICATIONS_HOSTNAME/- WATCHTOWER_NOTIFICATIONS_HOSTNAME/" $DKCOM_FILENAME
read -r -p "Notifications setup complete. If the link is correct, you will receive a notification for each update made on the app container images. Now press enter to continue"
clear;
}

fn_setupApp(){
if [ "$2" == "email" ] ; then
printf "Note: If you are using login with google, remember to set also a password for your app account!"
printf "Note: If you are using login with google, remember to set also a password for your app account!"$'\n'
printf "Enter your %s Email"$'\n' "$1"
read -r APP_EMAIL
sed -i "s/your$1Mail/$APP_EMAIL/" .env
Expand Down Expand Up @@ -142,9 +143,9 @@ fn_setupApp(){
sed -i "s^# $1_HTTPS_PROXY=http://proxyUsername:proxyPassword@proxy_url:proxy_port^$1_HTTPS_PROXY=$APP_HTTPS_PROXY^" .env ;

fi
sed -i "s^#- $1_HTTP_PROXY^- HTTP_PROXY^" docker-compose.yml ;
sed -i "s^#- $1_HTTPS_PROXY^- HTTPS_PROXY^" docker-compose.yml ;
sed -i "s^#- $1_NO_PROXY^- NO_PROXY^" docker-compose.yml ;
sed -i "s^#- $1_HTTP_PROXY^- HTTP_PROXY^" $DKCOM_FILENAME ;
sed -i "s^#- $1_HTTPS_PROXY^- HTTPS_PROXY^" $DKCOM_FILENAME ;
sed -i "s^#- $1_NO_PROXY^- NO_PROXY^" $DKCOM_FILENAME ;
fi
read -r -p "$1 configuration complete, press enter to continue to the next app"
}
Expand Down Expand Up @@ -186,7 +187,7 @@ fn_setupProxy(){


fn_setupEnv(){
read -r -p "Do you wish to proceed with the .env file guided setup Y/N? (This will also adapt the docker-compose.yml file accordingly)" yn
read -r -p "Do you wish to proceed with the .env file guided setup Y/N? (This will also adapt the $DKCOM_FILENAME file accordingly)" yn
case $yn in
[Yy]* ) clear;;
[Nn]* ) blueprint ".env file setup canceled. Make sure you have a valid .env file before proceeding with the stack startup."; read -r -p "Press Enter to go back to mainmenu"; mainmenu;;
Expand All @@ -195,7 +196,7 @@ fn_setupEnv(){
if ! grep -q "DEVICE_NAME=yourDeviceName" .env ; then
echo "The current .env file appears to have already been modified. A fresh version will be downloaded and used.";
curl -fsSL $ENV_SRC -o ".env"
curl -fsSL $DKCOM_SRC -o "docker-compose.yml"
curl -fsSL $DKCOM_SRC -o "$DKCOM_FILENAME"
fi
printf "beginnning env file guided setup"$'\n'
CURRENT_APP='';
Expand Down Expand Up @@ -281,7 +282,7 @@ fn_setupEnv(){
}

fn_startStack(){
yellowprint "This menu item will launch all the apps using the configured .env file and the docker-compose.yml file (Docker must be already installed and running)"
yellowprint "This menu item will launch all the apps using the configured .env file and the $DKCOM_FILENAME file (Docker must be already installed and running)"
read -r -p "Do you wish to proceed Y/N? " yn
case $yn in
[Yy]* ) sudo docker compose up -d; greenprint "All Apps started you can visit the web dashboard on http://localhost:8081/ . If not already done use the previously generated earnapp node URL to add your device in your earnapp dashboard. Check the README file for more details."; read -r -p "Now press enter to go back to the menu"; mainmenu;;
Expand All @@ -291,7 +292,7 @@ fn_startStack(){
}

fn_stopStack(){
yellowprint "This menu item will stop all the apps and delete the docker stack previously created using the configured .env file and the docker-compose.yml file."
yellowprint "This menu item will stop all the apps and delete the docker stack previously created using the configured .env file and the $DKCOM_FILENAME file."
yellowprint "You don't need to use this command to temporarily pause apps or to update the stack. Use it only in case of uninstallation!"
read -r -p "Do you wish to proceed Y/N? " yn
case $yn in
Expand All @@ -312,11 +313,11 @@ fn_resetEnv(){
}

fn_resetDockerCompose(){
redprint "Now a fresh docker-compose.yml file will be downloaded"
redprint "Now a fresh $DKCOM_FILENAME file will be downloaded"
read -r -p "Do you wish to proceed Y/N? " yn
case $yn in
[Yy]* ) curl -fsSL $DKCOM_SRC -o "docker-compose.yml"; greenprint "docker-compose.yml file resetted, remember to reconfigure it if needed";;
[Nn]* ) blueprint "docker-compose.yml file reset canceled. The file is left as it is"; mainmenu;;
[Yy]* ) curl -fsSL $DKCOM_SRC -o "$DKCOM_FILENAME"; greenprint "$DKCOM_FILENAME file resetted, remember to reconfigure it if needed";;
[Nn]* ) blueprint "$DKCOM_FILENAME file reset canceled. The file is left as it is"; mainmenu;;
* ) printf "Please answer yes or no.";;
esac
}
Expand All @@ -325,8 +326,7 @@ fn_resetDockerCompose(){
mainmenu() {
clear;
PS3="Select an option and press Enter "

items=("Show apps' links to register or go to dashboard" "Install Docker" "Setup .env file" "Start apps stack" "Stop apps stack" "Reset .env File" "Reset docker-compose.yml file")
items=("Show apps' links to register or go to dashboard" "Install Docker" "Setup .env file" "Start apps stack" "Stop apps stack" "Reset .env File" "Reset $DKCOM_FILENAME file")

select item in "${items[@]}" Quit
do
Expand Down

0 comments on commit bca3006

Please sign in to comment.