From 7c148db02816e2ae7eeda0c29d1d6b0dc937ce26 Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 1 May 2021 13:54:04 +0200 Subject: [PATCH 1/4] fix(Dev scripts): Add gitignore to prevent password leak Signed-off-by: h4570 --- dev-scripts/.gitignore | 7 +++++ .../deploy-dbg-example.ps1 | 28 ++++++++++++------- .../deploy-prd-example.ps1 | 22 ++++++++++----- 3 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 dev-scripts/.gitignore rename deploy-dbg.ps1 => dev-scripts/deploy-dbg-example.ps1 (66%) rename deploy-prd.ps1 => dev-scripts/deploy-prd-example.ps1 (66%) diff --git a/dev-scripts/.gitignore b/dev-scripts/.gitignore new file mode 100644 index 0000000..3e1cbbe --- /dev/null +++ b/dev-scripts/.gitignore @@ -0,0 +1,7 @@ +# Ignore everything +* + +# Except these +!.gitignore +!deploy-dbg-example.ps1 +!deploy-prd-example.ps1 \ No newline at end of file diff --git a/deploy-dbg.ps1 b/dev-scripts/deploy-dbg-example.ps1 similarity index 66% rename from deploy-dbg.ps1 rename to dev-scripts/deploy-dbg-example.ps1 index c348d7b..c8e68e8 100644 --- a/deploy-dbg.ps1 +++ b/dev-scripts/deploy-dbg-example.ps1 @@ -5,21 +5,24 @@ param ( [switch]$skip_backend = $false, [switch]$skip_frontend = $false - ) +) -$TARGET = "root@192.168.0.155" +$TARGET = "armnas@192.168.0.155" + +# --- README! +# Please duplicate this file, change the name of it, and put your password here. +# For your safety, the new file will NOT be tracked by git. -# --- -# You can remove passwords from these commands, via installing your ssh key on target machine. -# -> cat id_rsa.pub | ssh root@$TARGET_IP 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys' $SSH = 'plink.exe' -$SSH_DEFAULT_ARGS = '-batch', '-pw', 'raspberry' +$SSH_DEFAULT_ARGS = '-batch', '-pw', 'PUT_ARMNAS_PASSWORD_HERE' $SCP = 'pscp.exe' -$SCP_DEFAULT_ARGS = '-r', '-P', '22', '-pw', 'raspberry' -# ---- +$SCP_DEFAULT_ARGS = '-r', '-P', '22', '-pw', 'PUT_ARMNAS_PASSWORD_HERE' +# --- + +Set-Location .. # ===--- Deploy frontend ---=== -if(!$skip_frontend) { +if (!$skip_frontend) { Write-Host "Building Angular (frontend)" -ForegroundColor DarkGreen Set-Location frontend/web-app ng build --configuration=debug --output-hashing=all --output-path=./dist > $null @@ -32,7 +35,7 @@ if(!$skip_frontend) { } # ===--- Deploy backend ---=== -if(!$skip_backend) { +if (!$skip_backend) { Write-Host "Building Web API (backend)" -ForegroundColor DarkGreen Set-Location backend/WebApi $GIT_TAG = git describe --tags @@ -43,9 +46,13 @@ if(!$skip_backend) { Write-Host "Deploying Web API (backend)" -ForegroundColor Magenta & $SSH $SSH_DEFAULT_ARGS $TARGET '. /var/www/armnas/backend/WebApi/stop.sh' > $null # stop backend + & $SSH $SSH_DEFAULT_ARGS $TARGET 'mv /var/www/armnas/backend/WebApi/armnas.db /var/www/armnas/' > $null # backup armnas.db + & $SSH $SSH_DEFAULT_ARGS $TARGET 'mv /var/www/armnas/backend/WebApi/appsettings.json /var/www/armnas/' > $null # backup appsettings.json & $SSH $SSH_DEFAULT_ARGS $TARGET 'rm -rf /var/www/armnas/backend/WebApi/*' > $null & $SCP $SCP_DEFAULT_ARGS './backend/WebApi/publish/\*' $TARGET':/var/www/armnas/backend/WebApi' > $null Remove-Item -LiteralPath "./backend/WebApi/publish" -Force -Recurse + & $SSH $SSH_DEFAULT_ARGS $TARGET 'mv /var/www/armnas/armnas.db /var/www/armnas/backend/WebApi/' > $null # restore armnas.db + & $SSH $SSH_DEFAULT_ARGS $TARGET 'mv /var/www/armnas/appsettings.json /var/www/armnas/backend/WebApi/' > $null # restore appsettings.json & $SSH $SSH_DEFAULT_ARGS $TARGET 'chmod +x /var/www/armnas/backend/WebApi/start.sh' > $null & $SSH $SSH_DEFAULT_ARGS $TARGET 'chmod +x /var/www/armnas/backend/WebApi/stop.sh' > $null @@ -55,3 +62,4 @@ if(!$skip_backend) { # ===--- Finish ---=== Write-Host "Done!" -ForegroundColor DarkGreen +Set-Location dev-scripts diff --git a/deploy-prd.ps1 b/dev-scripts/deploy-prd-example.ps1 similarity index 66% rename from deploy-prd.ps1 rename to dev-scripts/deploy-prd-example.ps1 index 82d2790..dfe4193 100644 --- a/deploy-prd.ps1 +++ b/dev-scripts/deploy-prd-example.ps1 @@ -2,16 +2,19 @@ # ===--- Variables ---=== -$TARGET = "root@192.168.0.155" +$TARGET = "armnas@192.168.0.155" + +# --- README! +# Please duplicate this file, change the name of it, and put your password here. +# For your safety, the new file will NOT be tracked by git. -# --- -# You can remove passwords from these commands, via installing your ssh key on target machine. -# -> cat id_rsa.pub | ssh root@$TARGET_IP 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys' $SSH = 'plink.exe' -$SSH_DEFAULT_ARGS = '-batch', '-pw', 'raspberry' +$SSH_DEFAULT_ARGS = '-batch', '-pw', 'Sandrox1' $SCP = 'pscp.exe' -$SCP_DEFAULT_ARGS = '-r', '-P', '22', '-pw', 'raspberry' -# ---- +$SCP_DEFAULT_ARGS = '-r', '-P', '22', '-pw', 'Sandrox1' +# --- + +Set-Location .. # ===--- Deploy frontend ---=== @@ -37,9 +40,13 @@ Set-Location .. Write-Host "Deploying Web API (backend)" -ForegroundColor Magenta & $SSH $SSH_DEFAULT_ARGS $TARGET '. /var/www/armnas/backend/WebApi/stop.sh' > $null # stop backend +& $SSH $SSH_DEFAULT_ARGS $TARGET 'mv /var/www/armnas/backend/WebApi/armnas.db /var/www/armnas/' > $null # backup armnas.db +& $SSH $SSH_DEFAULT_ARGS $TARGET 'mv /var/www/armnas/backend/WebApi/appsettings.json /var/www/armnas/' > $null # backup appsettings.json & $SSH $SSH_DEFAULT_ARGS $TARGET 'rm -rf /var/www/armnas/backend/WebApi/*' > $null & $SCP $SCP_DEFAULT_ARGS './backend/WebApi/publish/\*' $TARGET':/var/www/armnas/backend/WebApi' > $null Remove-Item -LiteralPath "./backend/WebApi/publish" -Force -Recurse +& $SSH $SSH_DEFAULT_ARGS $TARGET 'mv /var/www/armnas/armnas.db /var/www/armnas/backend/WebApi/' > $null # restore armnas.db +& $SSH $SSH_DEFAULT_ARGS $TARGET 'mv /var/www/armnas/appsettings.json /var/www/armnas/backend/WebApi/' > $null # restore appsettings.json & $SSH $SSH_DEFAULT_ARGS $TARGET 'chmod +x /var/www/armnas/backend/WebApi/start.sh' > $null & $SSH $SSH_DEFAULT_ARGS $TARGET 'chmod +x /var/www/armnas/backend/WebApi/stop.sh' > $null @@ -48,3 +55,4 @@ Remove-Item -LiteralPath "./backend/WebApi/publish" -Force -Recurse # ===--- Finish ---=== Write-Host "Done!" -ForegroundColor DarkGreen +Set-Location dev-scripts From 91406bc8de7f7c7905d593ae5db7dc5310a8227c Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 1 May 2021 13:54:52 +0200 Subject: [PATCH 2/4] fix(Install script): minor bugfixing Signed-off-by: h4570 --- install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index eaf80bf..e4f8c6e 100644 --- a/install.sh +++ b/install.sh @@ -75,7 +75,7 @@ step_2() { } step_3() { - apt-get install debian-keyring unzip jq curl debian-archive-keyring ntfs-3g ufw apt-transport-https -y + apt-get install debian-keyring acl unzip jq curl debian-archive-keyring ntfs-3g ufw apt-transport-https -y # Check if caddy repo was already added. Add if not if [ ! -f /etc/apt/sources.list.d/caddy-stable.list ]; then curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo apt-key add - @@ -241,7 +241,7 @@ http://$web_api_ip_domain { step_7() { # Give a chance to caddy and .NET to wake up - sleep 5s + sleep 10s # Add main user to armnas curl --header "Content-Type: application/json" \ @@ -289,7 +289,7 @@ step_10() { # Check if script is running with root privileges if [ `id -u` -ne 0 ] ; then echo "Please run as root" ; exit 1 ; fi -myip="$(hostname -I | xargs)" +myip="$(hostname -I | xargs | awk '{gsub(/ /,", ")}1')" color_green echo "==========================" @@ -370,7 +370,7 @@ while true; do done while true; do - read -p "Install .NET SDK/Runtime which is needed for armnas development? (y/N): " yn + read -p "Install .NET SDK/Runtime? Not needed by Armnas. (y/N): " yn case $yn in [Yy]* ) install_sdk_runtime=true; break;; [Nn]* ) install_sdk_runtime=false; break;; From 87a1009b3d3405ea25993e313723610d1ca213cf Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 1 May 2021 13:55:46 +0200 Subject: [PATCH 3/4] fix(Partitions): dont allow to umount not armnas partitions Signed-off-by: h4570 --- .../pages/home/partitions/partitions.component.ts | 8 ++++++-- frontend/web-app/src/assets/i18n/en-US.json | 2 +- frontend/web-app/src/assets/i18n/pl-PL.json | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/web-app/src/app/components/pages/home/partitions/partitions.component.ts b/frontend/web-app/src/app/components/pages/home/partitions/partitions.component.ts index 4a19d0e..4f68e68 100644 --- a/frontend/web-app/src/app/components/pages/home/partitions/partitions.component.ts +++ b/frontend/web-app/src/app/components/pages/home/partitions/partitions.component.ts @@ -77,7 +77,11 @@ export class PartitionsComponent implements OnInit, OnDestroy { // remove mount/auto mount with old name! const weShouldDisableAutoMount = partition.isAutoMountEnabled; const weShouldUnmount = partition.mountingPoint; // is mounted - + if ((weShouldDisableAutoMount || weShouldUnmount) && !this.isPartitionSavedInDb(partition)) { + this.snackbar.open(this.translate.instant('home.armnasCanUnmountItsOwn'), '😶', { duration: 3000 }); + partition.isFreezed = false; + return; + } if (weShouldDisableAutoMount) await this.partitionService.disableAutoMount(partition.uuid); if (weShouldUnmount) @@ -176,7 +180,7 @@ export class PartitionsComponent implements OnInit, OnDestroy { } private isPartitionSavedInDb(partition: LsblkPartitionInfoView): boolean { - if (!partition.displayName) return false; + if (!partition.cachedDisplayName) return false; return true; } diff --git a/frontend/web-app/src/assets/i18n/en-US.json b/frontend/web-app/src/assets/i18n/en-US.json index fcd0ff5..aab4c0a 100644 --- a/frontend/web-app/src/assets/i18n/en-US.json +++ b/frontend/web-app/src/assets/i18n/en-US.json @@ -34,7 +34,7 @@ "mount": "Mount", "unmount": "Unmount", "loading": "Loading...", - "armnasCanUnmountItsOwn": "Armnas can umount its own mounts only!", + "armnasCanUnmountItsOwn": "Armnas can umount its own mounts only! Umount manually and restart the webpage.", "setDisplayName": "Please set display name first!", "goodbye": "Goodbye!", "seeYou": "See you in few minutes!", diff --git a/frontend/web-app/src/assets/i18n/pl-PL.json b/frontend/web-app/src/assets/i18n/pl-PL.json index 75036cc..772828b 100644 --- a/frontend/web-app/src/assets/i18n/pl-PL.json +++ b/frontend/web-app/src/assets/i18n/pl-PL.json @@ -34,7 +34,7 @@ "mount": "Zamontuj", "unmount": "Odmontuj", "loading": "Ładowanie...", - "armnasCanUnmountItsOwn": "Armnas może odmontować tylko własne partycje.", + "armnasCanUnmountItsOwn": "Armnas może odmontować tylko własne partycje. Odmontuj manualnie i zrestartuj stronę.", "setDisplayName": "Najpierw ustaw nazwę własną!", "goodbye": "Do zobaczenia!", "seeYou": "Widzimy się za kilka minut!", From 92fc091296f0e2e5a2499de57aaef3d4bf8ddfb7 Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 1 May 2021 14:31:07 +0200 Subject: [PATCH 4/4] docs draft Signed-off-by: h4570 --- README.MD | 19 +++++-------------- docs/development.md | 1 + docs/installation.md | 18 ++++++++++++++++++ docs/logs.md | 1 + docs/messages.md | 1 + docs/q&a.md | 2 ++ 6 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 docs/development.md create mode 100644 docs/installation.md create mode 100644 docs/logs.md create mode 100644 docs/messages.md create mode 100644 docs/q&a.md diff --git a/README.MD b/README.MD index 19a2b15..5ea8eb0 100644 --- a/README.MD +++ b/README.MD @@ -1,17 +1,8 @@ [![Full CI](https://github.com/h4570/armnas/actions/workflows/ci.yml/badge.svg)](https://github.com/h4570/armnas/actions/workflows/ci.yml) # Work in progress! - -### Roadmap -- Installation - - Test Armbian - - Test Raspbian -- Documentation - - How to add message (with example) - - How to check logs - - How to develop - - Add info: Devices must have partitions, partitions must have UUID (create partition with parted and format `mkfs.ntfs -f /dev/sdb1`) - - How to install Armbian - - If running on Armbian -`add-apt-repository ppa:transmissionbt/ppa -y` -- Create cool readme with test/lint/quality badges +- Test Raspbian +- Test/lint/quality badges +- Docs +- Video +- Readme diff --git a/docs/development.md b/docs/development.md new file mode 100644 index 0000000..8864710 --- /dev/null +++ b/docs/development.md @@ -0,0 +1 @@ +# TODO: SSH connection + dev scripts \ No newline at end of file diff --git a/docs/installation.md b/docs/installation.md new file mode 100644 index 0000000..cff9e4e --- /dev/null +++ b/docs/installation.md @@ -0,0 +1,18 @@ +# TODO: Install, uninstall, update + +## Install +**For Armbian users**, please add transmission repo (only once): +`add-apt-repository ppa:transmissionbt/ppa -y` + +1. Download install script +`sudo wget https://raw.githubusercontent.com/h4570/armnas/main/install.sh` +2. Run script +`sudo chmod +x install.sh && sudo ./install.sh` + +## Update + +## Uninstall +1. Download uninstall script +`sudo wget https://raw.githubusercontent.com/h4570/armnas/main/uninstall.sh` +2. Run script +`sudo chmod +x uninstall.sh && sudo ./uninstall.sh` diff --git a/docs/logs.md b/docs/logs.md new file mode 100644 index 0000000..df2ec8b --- /dev/null +++ b/docs/logs.md @@ -0,0 +1 @@ +# TODO: How to check logs \ No newline at end of file diff --git a/docs/messages.md b/docs/messages.md new file mode 100644 index 0000000..e402624 --- /dev/null +++ b/docs/messages.md @@ -0,0 +1 @@ +# TODO: How to add message (with example) \ No newline at end of file diff --git a/docs/q&a.md b/docs/q&a.md new file mode 100644 index 0000000..9f7e78e --- /dev/null +++ b/docs/q&a.md @@ -0,0 +1,2 @@ +- .NET Crashing on Hardkernel's Ubuntu +- Add info: Devices must have partitions, partitions must have UUID (create partition with parted and format `mkfs.ntfs -f /dev/sdb1`) \ No newline at end of file