From 3e82b447f2e0ba29f75b4c6256390107c5f79fd1 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Tue, 6 Jul 2021 09:24:42 -0700 Subject: [PATCH] packaging: linux now installs a sh script to invoke cwtch so its command line callable, not just desktop. use bundled tor. windows bat files to trigger file logging for debug --- .drone.yml | 15 +++++---------- LIBCWTCH-GO.version | 2 +- README.md | 20 ++++++++++++++++++-- lib/cwtch/ffi.dart | 14 ++++++++++++-- linux/cwtch | 3 +++ linux/cwtch.home.desktop | 2 +- linux/cwtch.home.sh | 3 +++ linux/cwtch.local-dir.desktop | 10 ---------- linux/cwtch.sys.desktop | 2 +- linux/cwtch.sys.sh | 3 +++ linux/install-home.sh | 5 ++--- linux/install-sys.sh | 2 +- linux/my_application.cc | 14 +++++++++++--- linux/package-release.sh | 11 +++++++++++ windows/cwtch-debug-log.bat | 3 +++ windows/cwtch-info-log.bat | 2 ++ 16 files changed, 77 insertions(+), 34 deletions(-) create mode 100755 linux/cwtch create mode 100755 linux/cwtch.home.sh delete mode 100755 linux/cwtch.local-dir.desktop create mode 100755 linux/cwtch.sys.sh create mode 100755 linux/package-release.sh create mode 100644 windows/cwtch-debug-log.bat create mode 100644 windows/cwtch-info-log.bat diff --git a/.drone.yml b/.drone.yml index 38c902ce..241dff2f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -52,17 +52,10 @@ steps: path: /root/.pub-cache commands: - flutter build linux --dart-define BUILD_VER=`cat VERSION` --dart-define BUILD_DATE=`cat BUILDDATE` - - mkdir deploy/linux - - cp -r build/linux/x64/release/bundle/* deploy/linux - - cp linux/cwtch.*.desktop deploy/linux - - cp linux/install-*.sh deploy/linux - - cp linux/cwtch.png deploy/linux - - cp linux/libCwtch.so deploy/linux/lib/ - # should not be needed, should be in data/flutter_assets and work from there - #- cp /sdks/flutter/bin/cache/artifacts/engine/linux-x64/icudtl.dat deploy/linux - - cp linux/tor deploy/linux + - linux/package-release.sh + - mkdir -p deploy/cwtch + - cp -r build/linux/x64/release/bundle/* deploy/cwtch - cd deploy - - mv linux cwtch - tar -czf cwtch-`cat ../VERSION`.tar.gz cwtch - rm -r cwtch @@ -222,6 +215,8 @@ steps: - copy C:\BuildTools\VC\Redist\MSVC\14.29.30036\x64\Microsoft.VC142.CRT\vcruntime140.dll $Env:releasedir - copy C:\BuildTools\VC\Redist\MSVC\14.29.30036\x64\Microsoft.VC142.CRT\vcruntime140_1.dll $Env:releasedir - copy C:\BuildTools\VC\Redist\MSVC\14.29.30036\x64\Microsoft.VC142.CRT\msvcp140.dll $Env:releasedir + - copy README.md $Env:releasedir\ + - copy windows\*.bat $Env:releasedir\ - powershell -command "Expand-Archive -Path tor.zip -DestinationPath $Env:releasedir\Tor" - name: package-windows diff --git a/LIBCWTCH-GO.version b/LIBCWTCH-GO.version index a3ef35ec..083b5514 100644 --- a/LIBCWTCH-GO.version +++ b/LIBCWTCH-GO.version @@ -1 +1 @@ -v1.0.0-20-gf8eedca-2021-06-30-20-48 \ No newline at end of file +v1.0.0-22-g343c3bc-2021-07-06-15-30 diff --git a/README.md b/README.md index 0be515c7..25c80b52 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,23 @@ A Flutter based [Cwtch](https://cwtch.im) UI. This README covers build instructions, for information on Cwtch itself please go to [https://cwtch.im](https://cwtch.im) -## Getting Started +## Installing + +- Android: Available from the Google Play Store (currently patrons only) or from [https://cwtch.im/download/](https://cwtch.im/download/) as an APK +- Windows: Available from [https://cwtch.im/download/](https://cwtch.im/download/) as an installer or .zip file +- Linux: Available from [https://cwtch.im/download/](https://cwtch.im/download/) as a .tar.gz + - `install.home.sh` installs the app into your home directory + - `install.sys.sh` as root to install system wide + +## Running + +Cwtch logging is controlable with the following environment variables: +- `LOG_FILE=` will reroute all of libcwtch-go's logging to the specified file instead of the console +- `LOG_LEVEL=debug` will set the log level to debug instead of info + +## Building + +### Getting Started First you will need a valid [flutter sdk installation](https://flutter.dev/docs/get-started/install) and run `flutter pub get` to fetch dependencies. @@ -28,7 +44,7 @@ You will probably want to disable Analytics on the Flutter Tool: `flutter config - Follow the steps above to fetch `libCwtch-go` and `tor` (these will fetch Android versions of these binaries also) - run `flutter run` with an Android phone connect via USB (or some other valid debug mode) -#### Known Platform Issues +### Known Platform Issues - **Windows**: Flutter engine has a [known bug](https://github.com/flutter/flutter/issues/75675) around the Right Shift key being sticky. We have implemented a partial workaround, if this happens, tap left shift and it will reset. diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index b56799f9..0f8f1ae3 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -90,7 +90,17 @@ class CwtchFfi implements Cwtch { Map envVars = Platform.environment; if (Platform.isLinux) { home = (envVars['HOME'])!; - bundledTor = "./tor"; + if (await File("linux/tor").exists()) { + bundledTor = "linux/tor"; + } else if (await File("lib/tor").exists()) { + bundledTor = "lib/tor"; + } else if (await File(path.join(home, ".local/lib/cwtch/tor")).exists()) { + bundledTor = path.join(home, ".local/lib/cwtch/tor"); + } else if (await File("/usr/lib/cwtch/tor").exists()) { + bundledTor = "/usr/lib/cwtch/tor"; + } else { + bundledTor = "tor"; + } } else if (Platform.isWindows) { home = (envVars['UserProfile'])!; bundledTor = "Tor\\Tor\\tor.exe"; @@ -99,7 +109,7 @@ class CwtchFfi implements Cwtch { if (EnvironmentConfig.BUILD_VER == dev_version) { cwtchDir = path.join(cwtchDir, "dev"); } - print("cwtchDir $cwtchDir"); + print("StartCwtch( cwtchdir: $cwtchDir, torPath: $bundledTor )"); var startCwtchC = library.lookup>("c_StartCwtch"); // ignore: non_constant_identifier_names diff --git a/linux/cwtch b/linux/cwtch new file mode 100755 index 00000000..89dffb63 --- /dev/null +++ b/linux/cwtch @@ -0,0 +1,3 @@ +#!/bin/sh + +env LD_LIBRARY_PATH=./lib/ ./lib/cwtch \ No newline at end of file diff --git a/linux/cwtch.home.desktop b/linux/cwtch.home.desktop index 82f760cc..16ee3e1d 100755 --- a/linux/cwtch.home.desktop +++ b/linux/cwtch.home.desktop @@ -3,7 +3,7 @@ Version=1.0 Type=Application Name=Cwtch Comment=Metadata Resistant Chat -Exec=env LD_LIBRARY_PATH=~/.local/lib/cwtch/ ~/.local/bin/cwtch +Exec=~/.local/bin/cwtch Icon=cwtch Terminal=false Categories=Network;InstantMessaging; diff --git a/linux/cwtch.home.sh b/linux/cwtch.home.sh new file mode 100755 index 00000000..4e081cbe --- /dev/null +++ b/linux/cwtch.home.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +env LD_LIBRARY_PATH=~/.local/lib/cwtch/ ~/.local/lib/cwtch/cwtch \ No newline at end of file diff --git a/linux/cwtch.local-dir.desktop b/linux/cwtch.local-dir.desktop deleted file mode 100755 index 8928ee07..00000000 --- a/linux/cwtch.local-dir.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Version=1.0 -Type=Application -Name=Cwtch -Comment=Metadata Resistant Chat -Exec=env LD_LIBRARY_PATH=./lib/ ./cwtch -Icon=cwtch -Terminal=false -Categories=Network;InstantMessaging; -Keywords=Internet;IM;Instant Messaging;Messaging;Chat diff --git a/linux/cwtch.sys.desktop b/linux/cwtch.sys.desktop index 32c566a4..b944b91e 100755 --- a/linux/cwtch.sys.desktop +++ b/linux/cwtch.sys.desktop @@ -3,7 +3,7 @@ Version=1.0 Type=Application Name=Cwtch Comment=Metadata Resistant Chat -Exec=env LD_LIBRARY_PATH=/usr/lib/cwtch /usr/bin/cwtch +Exec=/usr/bin/cwtch Icon=cwtch Terminal=false Categories=Network;InstantMessaging; diff --git a/linux/cwtch.sys.sh b/linux/cwtch.sys.sh new file mode 100755 index 00000000..bec6bcc5 --- /dev/null +++ b/linux/cwtch.sys.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +env LD_LIBRARY_PATH=/usr/lib/cwtch /usr/lib/cwtch/cwtch \ No newline at end of file diff --git a/linux/install-home.sh b/linux/install-home.sh index 632befda..663b9fa3 100755 --- a/linux/install-home.sh +++ b/linux/install-home.sh @@ -1,7 +1,7 @@ #!/bin/sh mkdir -p ~/.local/bin -cp cwtch ~/.local/bin/ +sed "s|~|$HOME|g" cwtch.home.sh > ~/.local/bin/cwtch mkdir -p ~/.local/share/icons cp cwtch.png ~/.local/share/icons @@ -13,5 +13,4 @@ mkdir -p ~/.local/lib/cwtch cp -r lib/* ~/.local/lib/cwtch mkdir -p ~/.local/share/applications -sed "s|~|$HOME|g" cwtch.home.desktop > $HOME/.local/share/applications/cwtch.desktop - +sed "s|~|$HOME|g" cwtch.home.desktop > $HOME/.local/share/applications/cwtch.desktop \ No newline at end of file diff --git a/linux/install-sys.sh b/linux/install-sys.sh index 98475063..df39958a 100755 --- a/linux/install-sys.sh +++ b/linux/install-sys.sh @@ -1,6 +1,6 @@ #!/bin/sh -cp cwtch /usr/bin/ +cp cwtch.sys.sh /usr/bin/cwtch cp cwtch.png /usr/share/icons diff --git a/linux/my_application.cc b/linux/my_application.cc index 792826dd..117ef5cd 100644 --- a/linux/my_application.cc +++ b/linux/my_application.cc @@ -76,8 +76,16 @@ static void my_application_activate(GApplication* application) { // Check if assets folder is relative to the executable or if we can use a system copy struct stat info; + // if we're not in freshly compiled structure if (stat(fl_dart_project_get_assets_path(project), &info ) != 0 ) { - if( stat("/usr/share/cwtch/data/flutter_assets", &info ) != 0 ) { + if( stat("lib/cwtch", &info) == 0) { + // use local dir structure + project->assets_path = g_build_filename("data", "flutter_assets", nullptr); + project->aot_library_path = g_build_filename("lib", "libapp.so", nullptr); + project->icu_data_path = g_build_filename("data", "icudtl.dat", nullptr); + gtk_window_set_icon_from_file(window, "./cwtch.png", NULL); + } else if( stat("/usr/share/cwtch/data/flutter_assets", &info ) != 0 ) { + // if we're non in sys installed structure, use home dir structure struct passwd *pw = getpwuid(getuid()); const char *homedir = pw->pw_dir; // /home/$USER/.local/share/cwtch/data/flutter_assets @@ -88,6 +96,7 @@ static void my_application_activate(GApplication* application) { project->icu_data_path = g_build_filename(homedir, ".local", "share", "cwtch", "data", "icudtl.dat", nullptr); gtk_window_set_icon_from_file(window, g_build_filename(homedir, ".local", "share", "icons", "cwtch.png", nullptr), NULL); } else { + // else assume we are in sys installed structure // /usr/share/cwtch/data/flutter_assets project->assets_path = g_build_filename("/", "usr", "share", "cwtch", "data", "flutter_assets", nullptr); // /usr/lib/cwtch @@ -96,9 +105,8 @@ static void my_application_activate(GApplication* application) { project->icu_data_path = g_build_filename("/", "usr", "share", "cwtch", "data", "icudtl.dat", nullptr); gtk_window_set_icon_from_file(window, "/usr/share/icons/cwtch.png", NULL); } - } else { - gtk_window_set_icon_from_file(window, "./cwtch.png", NULL); } + printf("my_application.cc: using aot_library_path or '%s'\n", project->aot_library_path); fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); FlView* view = fl_view_new(project); diff --git a/linux/package-release.sh b/linux/package-release.sh new file mode 100755 index 00000000..33e20157 --- /dev/null +++ b/linux/package-release.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +mv build/linux/x64/release/bundle/cwtch build/linux/x64/release/bundle/lib/cwtch +cp linux/*.desktop build/linux/x64/release/bundle/ +cp linux/cwtch.*.sh build/linux/x64/release/bundle/ +cp linux/install-*.sh build/linux/x64/release/bundle/ +cp linux/cwtch build/linux/x64/release/bundle/ +cp README.md build/linux/x64/release/bundle/ +cp linux/cwtch.png build/linux/x64/release/bundle/ +cp linux/libCwtch.so build/linux/x64/release/bundle/lib/ +cp linux/tor build/linux/x64/release/bundle/lib diff --git a/windows/cwtch-debug-log.bat b/windows/cwtch-debug-log.bat new file mode 100644 index 00000000..6f46931c --- /dev/null +++ b/windows/cwtch-debug-log.bat @@ -0,0 +1,3 @@ +set FILE_LOG=cwtch_debug_log.txt +set LOG_LEVEL=debug +start "cwtch" cwtch diff --git a/windows/cwtch-info-log.bat b/windows/cwtch-info-log.bat new file mode 100644 index 00000000..4f8fafe1 --- /dev/null +++ b/windows/cwtch-info-log.bat @@ -0,0 +1,2 @@ +set FILE_LOG=cwtch_info_log.txt +start "cwtch" cwtch