From a13c82f8e7a0132b0c0ece4b4289433226801e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lio?= Date: Tue, 16 May 2023 21:26:28 -0300 Subject: [PATCH] change Y variable to X; no more auto sudo for methods of install and remove --- CHANGELOG.md | 2 + Makefile | 11 +++-- README.md | 56 +++++++++++----------- lib/database/models/package.g.dart | 2 +- lib/global.dart | 41 +++++++++------- lib/os/prepare.dart | 77 +++++++++++++++++------------- lib/os/repositories.dart | 2 +- lib/pubspec.dart | 2 +- pubspec.yaml | 2 +- 9 files changed, 107 insertions(+), 88 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e36ae21..100e806 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## v0.32.0 +- change Y variable to X; no more auto sudo for methods of install and remove ## v0.31.0 - fix apt bug hasDefault ## v0.28.0 diff --git a/Makefile b/Makefile index bedefa8..d9b1eb4 100644 --- a/Makefile +++ b/Makefile @@ -11,13 +11,14 @@ PKG ?= micro # auto, any, apt, brew, dnf, pacman, zypper MET ?= auto -CACHE ?= 1 +# NO CACHE +NC ?= false # Get latest release tag XTAG ?=$(shell curl -sL https://api.github.com/repos/verseles/xpm/releases/latest | jq -r '.tag_name') -compile: +build: mkdir -p build dart compile exe bin/xpm.dart -o build/xpm @@ -29,8 +30,8 @@ test: validate: echo "Validating package $(PKG) with $(MET) method on $(IMG) image... XPM" - docker build --build-arg XTAG=$(XTAG) -t xpm:$(IMG) -f docker/$(IMG)/Dockerfile . --no-cache=$(CACHE == 0) - docker run -it xpm:$(IMG) xpm install $(PKG) -m $(MET) + docker build --build-arg XTAG=$(XTAG) -t xpm:$(IMG) -f docker/$(IMG)/Dockerfile . $(if $(NC == true),--no-cache) + docker run -it xpm:$(IMG) /bin/sh -c "xpm ref && xpm install $(PKG) -m $(MET)" validate-all: $(MAKE) validate IMG=ubuntu MET=auto @@ -53,4 +54,4 @@ validate-all: $(MAKE) validate IMG=clearlinux MET=swupd -.PHONY: compile try test validate validate-all +.PHONY: build try test validate validate-all diff --git a/README.md b/README.md index 659fbe1..4868aa0 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ readonly xDESC="A modern and intuitive terminal-based text editor" # The url of the package (OPTIONAL) readonly xURL="https://micro-editor.github.io" # The architecture supported by the package -readonly xARCH=('linux64' 'linux32' 'linux-arm' 'linux-arm64' 'macos-arm64' 'macos' 'win32' 'win64' 'freebsd64' 'freebsd32' 'openbsd64' 'openbsd32' 'netbsd64' 'netbsd32') +readonly xARCHS=('linux64' 'linux32' 'linux-arm' 'linux-arm64' 'macos-arm64' 'macos' 'win32' 'win64' 'freebsd64' 'freebsd32' 'openbsd64' 'openbsd32' 'netbsd64' 'netbsd32') # The license of the package, can be an url or a initialisms like MIT, BSD, etc. readonly xLICENSE="https://raw.githubusercontent.com/zyedidia/micro/v$xVERSION/LICENSE" # The name(s) of the binary file(s) generated (OPTIONAL) @@ -107,34 +107,34 @@ install_apt() { `$XPM` Returns the path to the xpm binary. -`$yCHANNEL` +`$xCHANNEL` Returns the channel of the package, if it's a stable version, or a beta version, or a nightly version. Default is empty which means latest stable. -`$yARCH` +`$xARCH` Returns the current architecture of the system. For example: `x86_64`, `arm64`, `arm`, etc. -`$yOS` +`$xOS` Returns the current operating system. For example: `linux`, `macos`, `windows`, `android`, etc. -`$yBIN` +`$xBIN` Returns the binary folder of the system. For example: `/usr/bin`, `/usr/local/bin`, `/data/data/com.termux/files/usr/bin`, etc. -`$yHOME` +`$xHOME` Returns the home folder of the system. For example: `/home/user`, `/data/data/com.termux/files/home`, `/Users/user`, `/root`, etc. -`$yTMP` +`$xTMP` Returns the temporary folder of the system. For example: `/tmp`, `/data/data/com.termux/files/usr/tmp`, `/var/tmp`, etc. -`$ySUDO` +`$xSUDO` Returns the sudo command if available, otherwise returns empty. -`$isSnap` +`$hasSnap` Returns `true` if the system has snap installed, otherwise returns `false`. -`$isFlatpak` +`$hasFlatpak` Returns `true` if the system has flatpak installed, otherwise returns `false`. -`$isAppImage` +`$hasAppImage` Returns `true` if the system has appimage installed, otherwise returns `false`. ### Functions available @@ -170,8 +170,8 @@ These functions are called if the system has `snap` or `flatpak` or `appimage` i if [[ $isFlatpack == true ]]; then $1 uninstall $xNAME # with --assumeyes exit 1 -elif [[ $isAppimage == true ]]; then - rm -f $yHOME/.local/share/appimagekit/$xNAME +elif [[ $hasAppImage == true ]]; then + rm -f $xHOME/.local/share/appimagekit/$xNAME exit 1 else $1 remove $xNAME # snap with --yes @@ -273,7 +273,7 @@ readonly xVERSION="113.0.1" readonly xTITLE="Mozilla Firefox" readonly xDESC="A free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation" readonly xURL="https://www.mozilla.org/firefox" -readonly xARCH=('linux64' 'linux32' 'linux-arm' 'linux-arm64' 'macos-arm64' 'macos' 'win32' 'win64' 'freebsd64' 'freebsd32' 'openbsd64' 'openbsd32' 'netbsd64' 'netbsd32') +readonly xARCHS=('linux64' 'linux32' 'linux-arm' 'linux-arm64' 'macos-arm64' 'macos' 'win32' 'win64' 'freebsd64' 'freebsd32' 'openbsd64' 'openbsd32' 'netbsd64' 'netbsd32') readonly xLICENSE="MPL GPL LGPL" readonly xPROVIDES=("firefox") @@ -286,15 +286,15 @@ validate() { install_any() { local file file="$($XPM get "http://archive.mozilla.org/pub/firefox/releases/$xVERSION/linux-x86_64/en-US/firefox-$xVERSION.tar.bz2" --no-progress --no-user-agent --name="$xNAME-$xVERSION.tar.bz2")" - $ySUDO mkdir -p "/opt/$xNAME" - $ySUDO tar xvf "$file" -C "/opt" - $ySUDO ln -sf "/opt/$xNAME/$xNAME" "$yBIN/$xNAME" + $xSUDO mkdir -p "/opt/$xNAME" + $xSUDO tar xvf "$file" -C "/opt" + $xSUDO ln -sf "/opt/$xNAME/$xNAME" "$xBIN/$xNAME" $XPM shortcut --name="$xNAME" --path="$xNAME" --icon="/opt/$xNAME/browser/chrome/icons/default/default128.png" --description="$xDESC" --category="Network" } remove_any() { - $ySUDO rm -rf "/opt/$xNAME" - $ySUDO rm -f "$yBIN/$xNAME" + $xSUDO rm -rf "/opt/$xNAME" + $xSUDO rm -f "$xBIN/$xNAME" $XPM shortcut --remove --name="$xNAME" } @@ -316,7 +316,7 @@ readonly xVERSION="2.0.11" readonly xTITLE="Micro Text Editor" readonly xDESC="A modern and intuitive terminal-based text editor" readonly xURL="https://micro-editor.github.io" -readonly xARCH=('linux64' 'linux32' 'linux-arm' 'linux-arm64' 'macos-arm64' 'macos' 'win32' 'win64' 'freebsd64' 'freebsd32' 'openbsd64' 'openbsd32' 'netbsd64' 'netbsd32') +readonly xARCHS=('linux64' 'linux32' 'linux-arm' 'linux-arm64' 'macos-arm64' 'macos' 'win32' 'win64' 'freebsd64' 'freebsd32' 'openbsd64' 'openbsd32' 'netbsd64' 'netbsd32') readonly xLICENSE="https://raw.githubusercontent.com//v$xVERSION/LICENSE" readonly xPROVIDES=("micro") @@ -326,14 +326,14 @@ readonly xPROVIDES=("micro") readonly xDEFAULT=('apt' 'pacman' 'dnf' 'choco' 'brew' 'termux') # variables which is dinamically set and available for use -# $yCHANNEL +# $xCHANNEL # the default channel is empty, which means the latest stable version # user can change using -c or --channel flag -# $isSnap, $isFlatpack, $isAppimage +# $hasSnap, $isFlatpack, $hasAppImage # these boolean variables are set to true if the package manager is available and selected # $XPM is the path to xpm executable -# $ySUDO is the sudo command, if available. Most commands already add sudo if available -# $yBIN is the path to first bin folder on PATH. +# $xSUDO is the sudo command, if available. Most commands already add sudo if available +# $xBIN is the path to first bin folder on PATH. # the only required function is validate. install_any and remove_any are very important, but not required. validate() { # $1 is the path to executable from $xPROVIDES (if defined) or $xNAME @@ -379,12 +379,12 @@ remove_dnf() { # $1 means dnf compatible with -y, with sudo if available # update commands will be called before install_pack and remove_pack install_pack() { # $1 means an executable compatible with snap, flatpack or appimage - # $isSnap, $isFlatpack, $isAppimage are available as boolean + # $hasSnap, $isFlatpack, $hasAppImage are available as boolean # shellcheck disable=SC2154 if [[ $isFlatpack == true ]]; then # actually micro is not available on flatpack # $1 install $xNAME # with --assumeyes return 1 - elif [[ $isAppimage == true ]]; then # actually micro is not available on appimage + elif [[ $hasAppImage == true ]]; then # actually micro is not available on appimage # $1 install $xNAME return 1 else # snap @@ -393,12 +393,12 @@ install_pack() { # $1 means an executable compatible with snap, flatpack or appi } remove_pack() { - # $isSnap, $isFlatpack, $isAppimage are available as boolean + # $hasSnap, $isFlatpack, $hasAppImage are available as boolean # shellcheck disable=SC2154 if [[ $isFlatpack == true ]]; then # actually micro is not available on flatpack # $1 uninstall $xNAME # with --assumeyes exit 1 - elif [[ $isAppimage == true ]]; then # actually micro is not available on appimage + elif [[ $hasAppImage == true ]]; then # actually micro is not available on appimage # rm -f ~/.local/share/appimagekit/$xNAME exit 1 else diff --git a/lib/database/models/package.g.dart b/lib/database/models/package.g.dart index 1908562..d7c3956 100644 --- a/lib/database/models/package.g.dart +++ b/lib/database/models/package.g.dart @@ -2749,7 +2749,7 @@ extension PackageQuerySortThenBy on QueryBuilder } extension PackageQueryWhereDistinct on QueryBuilder { - QueryBuilder distinctByArch() { + QueryBuilder distinctBxARCH() { return QueryBuilder.apply(this, (query) { return query.addDistinctBy(r'arch'); }); diff --git a/lib/global.dart b/lib/global.dart index ce7a7f5..04023ca 100644 --- a/lib/global.dart +++ b/lib/global.dart @@ -1,48 +1,53 @@ /// A boolean value indicating whether the current environment is a Snap environment. -bool _isSnap = false; +bool _hasSnap = false; /// A boolean value indicating whether the current environment is a Flatpak environment. -bool _isFlatpak = false; +bool _hasFlatpak = false; /// A boolean value indicating whether the current environment is an AppImage environment. -bool _isAppImage = false; +bool _hasAppImage = false; /// The path to the sudo command. String _sudoPath = ''; +String _updateCommand = ''; + /// A class that provides global variables and methods. class Global { /// Gets or sets a value indicating whether the current environment is a Snap environment. - static bool get isSnap => _isSnap; - static set isSnap(bool value) { - _isSnap = value; + static bool get hasSnap => _hasSnap; + static set hasSnap(bool value) { + _hasSnap = value; if (value) { - _isFlatpak = false; - _isAppImage = false; + _hasFlatpak = false; + _hasAppImage = false; } } /// Gets or sets a value indicating whether the current environment is a Flatpak environment. - static bool get isFlatpak => _isFlatpak; - static set isFlatpak(bool value) { - _isFlatpak = value; + static bool get hasFlatpak => _hasFlatpak; + static set hasFlatpak(bool value) { + _hasFlatpak = value; if (value) { - _isSnap = false; - _isAppImage = false; + _hasSnap = false; + _hasAppImage = false; } } /// Gets or sets a value indicating whether the current environment is an AppImage environment. - static bool get isAppImage => _isAppImage; - static set isAppImage(bool value) { - _isAppImage = value; + static bool get hasAppImage => _hasAppImage; + static set hasAppImage(bool value) { + _hasAppImage = value; if (value) { - _isSnap = false; - _isFlatpak = false; + _hasSnap = false; + _hasFlatpak = false; } } /// Gets or sets the path to the sudo command. static String get sudoPath => _sudoPath; static set sudoPath(String value) => _sudoPath = value; + + static String get updateCommand => _updateCommand; + static set updateCommand(String value) => _updateCommand = value; } diff --git a/lib/os/prepare.dart b/lib/os/prepare.dart index 03fb441..24b2351 100644 --- a/lib/os/prepare.dart +++ b/lib/os/prepare.dart @@ -159,7 +159,7 @@ class Prepare { /// /// The [to] parameter is the installation target. Future bestForPack({String to = 'install'}) async { - // @TODO: Add support for hasDefault + // @TODO: Add support for hasDefault and xSUDO and global update. final String? snap = await Executable('snap').find(); final String? flatpak = await Executable('flatpak').find(); @@ -169,13 +169,13 @@ class Prepare { if (snap != null) { bestPack = snap; - Global.isSnap = true; + Global.hasSnap = true; } else if (flatpak != null) { bestPack = '$flatpak --assumeyes'; - Global.isFlatpak = true; + Global.hasFlatpak = true; } else if (appimage != null) { bestPack = appimage; - Global.isAppImage = true; + Global.hasAppImage = true; } return bestPack != null ? '${to}_pack "$bestPack"' : await bestForAny(to: to); @@ -198,11 +198,12 @@ class Prepare { if (bestSwupd != null) { final String update = '${Global.sudoPath} $bestSwupd update'; - if (hasMethod) { + Global.updateCommand = update; + if (hasDefault) { final operation = to == 'install' ? 'bundle-add' : 'bundle-remove'; - return '$update \n ${Global.sudoPath} $bestSwupd $operation -y ${package.name}'; + return '${Global.sudoPath} $bestSwupd $operation -y ${package.name}'; } - return '$update \n ${to}_swupd "${Global.sudoPath} $bestSwupd"'; + return '${to}_swupd "$bestSwupd"'; } } @@ -227,11 +228,12 @@ class Prepare { if (bestApt != null) { final String update = '${Global.sudoPath} $bestApt update'; + Global.updateCommand = update; if (hasDefault) { final operation = to == 'install' ? 'install' : 'remove'; - return '$update \n ${Global.sudoPath} $bestApt $operation -y ${package.name}'; + return '${Global.sudoPath} $bestApt $operation -y ${package.name}'; } - return '$update \n ${to}_apt "${Global.sudoPath} $bestApt -y"'; + return '${to}_apt "$bestApt -y"'; } } @@ -256,11 +258,12 @@ class Prepare { if (bestArchLinux != null) { final String update = '${Global.sudoPath} $bestArchLinux -Sy'; + Global.updateCommand = update; if (hasDefault) { final operation = to == 'install' ? '-S' : '-R'; - return '$update \n ${Global.sudoPath} $bestArchLinux --noconfirm $operation ${package.name}'; + return '${Global.sudoPath} $bestArchLinux --noconfirm $operation ${package.name}'; } - return '$update \n ${to}_pacman "${Global.sudoPath} $bestArchLinux --noconfirm"'; + return '${to}_pacman "$bestArchLinux --noconfirm"'; } } @@ -284,11 +287,12 @@ class Prepare { if (bestFedora != null) { final String update = '${Global.sudoPath} $bestFedora check-update'; + Global.updateCommand = update; if (hasDefault) { final operation = to == 'install' ? 'install' : 'remove'; - return '$update \n ${Global.sudoPath} $bestFedora -y $operation ${package.name}'; + return '${Global.sudoPath} $bestFedora -y $operation ${package.name}'; } - return '$update \n ${to}_dnf "${Global.sudoPath} $bestFedora -y"'; + return '${to}_dnf "$bestFedora -y"'; } } @@ -310,11 +314,12 @@ class Prepare { if (brew != null) { final String update = '$brew update'; + Global.updateCommand = update; if (hasDefault) { final operation = to == 'install' ? 'install' : 'uninstall'; - return '$update \n $brew $operation ${package.name}'; + return '$brew $operation ${package.name}'; } - return '$update \n ${to}_macos "$brew"'; + return '${to}_macos "$brew"'; } } @@ -336,11 +341,12 @@ class Prepare { if (zypper != null) { final String update = '${Global.sudoPath} $zypper refresh'; + Global.updateCommand = update; if (hasDefault) { final operation = to == 'install' ? 'install' : 'remove'; - return '$update \n ${Global.sudoPath} $zypper --non-interactive $operation ${package.name}'; + return '${Global.sudoPath} $zypper --non-interactive $operation ${package.name}'; } - return '$update \n ${to}_zypper "${Global.sudoPath} $zypper --non-interactive"'; + return '${to}_zypper "$zypper --non-interactive"'; } } @@ -362,11 +368,12 @@ class Prepare { if (pkg != null) { final String update = '${Global.sudoPath} $pkg update'; + Global.updateCommand = update; if (hasDefault) { final operation = to == 'install' ? 'install' : 'uninstall'; - return '$update \n ${Global.sudoPath} $pkg $operation -y ${package.name}'; + return '${Global.sudoPath} $pkg $operation -y ${package.name}'; } - return '$update \n ${to}_android "${Global.sudoPath} $pkg -y"'; + return '${to}_android "$pkg -y"'; } } @@ -377,6 +384,8 @@ class Prepare { /// /// The [to] parameter is the installation target. Future bestForWindows({String to = 'install'}) async { + // @TODO add support for global update (if possible) + final methods = package.methods ?? []; final hasMethod = methods.contains('choco'); @@ -423,6 +432,8 @@ ${await baseScriptContents()} ${await packageScript.contents()} +${Global.updateCommand}; + ${await best(to: 'install')} '''; @@ -519,24 +530,24 @@ validate "$bestValidateExecutable" executable += ' ${Platform.script.path}'; } - String yOS = Platform.operatingSystem; - String yARCH = getArchitecture(); - String yCHANNEL = args!['channel'] ?? ''; + String xOS = Platform.operatingSystem; + String xARCH = getArchitecture(); + String xCHANNEL = args!['channel'] ?? ''; - String yTMP = (await XPM.temp(packageName)).path; + String xTMP = (await XPM.temp(packageName)).path; return ''' readonly XPM="$executable"; -readonly yOS="$yOS"; -readonly yARCH="$yARCH"; -readonly yCHANNEL="$yCHANNEL"; -readonly yBIN="${binDirectory().path}"; -readonly yHOME="${XPM.userHome.path}"; -readonly yTMP="$yTMP"; -readonly ySUDO="${Global.sudoPath}"; -readonly isSnap="${Global.isSnap}"; -readonly isFlatpak="${Global.isFlatpak}"; -readonly isAppImage="${Global.isAppImage}"; +readonly xOS="$xOS"; +readonly xARCH="$xARCH"; +readonly xCHANNEL="$xCHANNEL"; +readonly xBIN="${binDirectory().path}"; +readonly xHOME="${XPM.userHome.path}"; +readonly xTMP="$xTMP"; +readonly xSUDO="${Global.sudoPath}"; +readonly hasSnap="${Global.hasSnap}"; +readonly hasFlatpak="${Global.hasFlatpak}"; +readonly hasAppImage="${Global.hasAppImage}"; '''; } diff --git a/lib/os/repositories.dart b/lib/os/repositories.dart index feb4cbb..ec1161e 100644 --- a/lib/os/repositories.dart +++ b/lib/os/repositories.dart @@ -141,7 +141,7 @@ class Repositories { final version = bashScript.get('xVERSION'); final title = bashScript.get('xTITLE'); final url = bashScript.get('xURL'); - final archs = bashScript.getArray('xARCH'); + final archs = bashScript.getArray('xARCHS'); final defaults = bashScript.getArray('xDEFAULT'); final installMethodFutures = XPM.installMethods.keys diff --git a/lib/pubspec.dart b/lib/pubspec.dart index ad09d19..b2e8ca4 100644 --- a/lib/pubspec.dart +++ b/lib/pubspec.dart @@ -2,7 +2,7 @@ const name = 'xpm'; const description = 'Universal package manager for any unix-like distro including macOS. Also experimental Windows support.'; -const version = '0.31.0'; +const version = '0.32.0'; const homepage = 'https://xpm.link'; const repository = 'https://github.com/verseles/xpm'; const executables = '{xpm: null}'; diff --git a/pubspec.yaml b/pubspec.yaml index a261984..099975d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: xpm description: Universal package manager for any unix-like distro including macOS. Also experimental Windows support. -version: 0.31.0 +version: 0.32.0 homepage: https://xpm.link repository: https://github.com/verseles/xpm executables: