Commit Graph
639 Commits
Author SHA1 Message Date
Hsiao-nan Cheung ef343d7f75 autoupdate.ps1: Fixes bug for single line hash extraction (#3015)
Fix a bug introduced in #2996 that single line hash extraction is broken.

When `find_hash_in_textfile()` is called in `get_hash_for_app()`, `$null` is used as `$regex` value for default single line hash extraction and the default value (`'^([a-fA-F0-9]+)$'`) is overriden, which leads a error of "hash not found".
2019-01-21 11:42:49 +01:00
Richard Kuhnt 8dd09661b1 Revert changes from #2931 to fix PS6 conversion problem 2019-01-21 01:40:06 +01:00
Hsiao-nan Cheung 034103fb0e Add JArray::Parse() to json_path in lib/json.ps1 (#3011)
Some JSON file ([example](https://mranapi.azurewebsites.net/api/download)) is surrounded by brackets ("[", "]") and cannot be parsed using `[Newtonsoft.Json.Linq.JObject]::Parse()` in `json_path()`. Instead, they could be parsed by `[Newtonsoft.Json.Linq.JArray]::Parse()` and then be treated as normal, e.g., applies a filter (script) expression.

- Add `[Newtonsoft.Json.Linq.JArray]::Parse()` after `[Newtonsoft.Json.Linq.JObject]::Parse()` failed
- Some JArray are handled by `json_path_legacy()` when `json_path()` throw error before, and the JSONPath is illegal when parsed with `JArray::Parse()`. To keep compatibility, add try-catch in this situation and let `json_path_legacy()` handle them still.
- In the above situation, manifest maintainer should use double dots after `$`, i.e., use `$..NODE` instead of `$.NODE` since it is a JArray contained the JObject.
2019-01-20 12:52:57 +01:00
Chawye Hsu 945a0c64c4 fix(persist): fix the target didn't be created (#3008)
fix(persist): fix the target didn't be created
2019-01-18 05:51:48 +01:00
Richard Kuhnt 3a22526554 Merge pull request #2996 from niheaven/add-version-variables-to-regex-in-hash-extract
Add version variables to autoupdate.hash.regex
2019-01-17 18:40:48 +01:00
Chawye Hsu d23552a5a5 Rewritten data persisting feature (#2897)
**Data matters, please review**

This is a rework of #2891 #2890 and #2882 . This will also fix #2724 and fix #2900 , close #2779 

**Introduction**

I add a function called `unlink_persist_data($dir)`, which recursively unlink all junction/hard link in the given directory. This affects some sub-commands which have interaction with junction/hard link:

- `scoop-install`: the persisting logic has been improved as follow:
  1. if there are data in the `persist` folder, also in app(`source`) folder, rename that one located in app folder (e.g. app's default setting files) with a `original` suffix, then create link from `persist` to  app
  2. if there are data in the `persist` folder, but no in app(`source`) folder, just create link from `persist` to  app
  3. if there is no data in the `persist` folder (e.g. fresh install), but there are data in app(`source`) folder (e.g. app's default setting files), we will just use that default setting files as the first-time persisting. So move that files from app folder to `persist` folder, then create link from `persist` to  app
  4. But what if if there is neither data in the `persist` folder (e.g. fresh install), nor in the app(`source`) folder (e.g. setting files will be created after first startup, like `Everthing.db`). We need to create empty persisting target in the `persist` folder. But by default we can't know if a persisting target is a file or a directory (e.g. `conf.d`). So we create a directory by default, and to avoid this, manifest maintainers should use `pre_install` to manually create the source file before persisting.
- `scoop-reset`: `reset` command uses the logic of `install`, but there is a problem: before re-persisting data, there have been `junction/hard link` in the app(`source`) folder. It will throw an exception of file exists #2724 . To fix this, we should unlink all old link before re-persisting, using `unlink_persist_data`.
- `scoop-uninstall`: `Remove-Item` can not remove `NTFS junction`, we need to unlink all persistting data, before uninstalling/deleting an app, but keeping persisting data.
- `scoop-cleanup`: like `uninstall`, `Remove-Item` can not remove `NTFS junction`, we need to unlink all persistting data, before deleting old versions of an app. Before PR #2882 , it use `fsutil.exe` to unlink junction, which is not friendly to restricted users (#2832 and #2881 ).

Beyond the logic improvement, there is a new feature now: it supports sub-folder data persisting, like:

```json
{
    "homepage": "https://scoop.sh",
    "description": "A dummy manifest for scoop tests.",
    "license": "Freeware",
    "version": "1.1.0",
    "url": "https://get.scoop.sh",
    "pre_install": [
        "if (!(test-path \"$dir\\dummy.txt\")) { new-item -force \"$dir\\dummy.txt\" -itemtype file | out-null }",
        "if (!(test-path \"$dir\\dummydir\")) { new-item \"$dir\\dummydir\" -itemtype directory | out-null }",
        "if (!(test-path \"$dir\\subdir\")) { new-item \"$dir\\subdir\" -itemtype directory | out-null }",
        "if (!(test-path \"$dir\\subdir\\subdummydir\")) { new-item \"$dir\\subdir\\subdummydir\" -itemtype directory | out-null }",
        "if (!(test-path \"$dir\\subdir\\subdummy.txt\")) { new-item -force \"$dir\\subdir\\subdummy.txt\" -itemtype file | out-null }",
    ],
    "persist": [
        "dummy.txt",
        "dummydir",
        "subdir\\subdummydir",
        "subdir\\subdummy.txt"
    ]
}
```
So no need to strip directories of source for target anymore.

To participate in the code review and tests, go visit https://github.com/h404bi/scoop-persist-test for test cases.
2019-01-17 18:00:29 +01:00
Hsiao-nan Cheung dfe846aca0 Add version variables to JSONPath 2019-01-17 16:14:10 +08:00
Hsiao-nan Cheung c3ee407197 Use substitute to replace version variables 2019-01-17 15:11:16 +08:00
Hsiao-nan Cheung c6de3b7c98 Add version variables to autoupdate.hash.regex 2019-01-16 15:20:41 +08:00
Vladimir Chebotarev b925b8ede5 Simplified last_scoop_update(). (#2931) 2019-01-11 16:46:43 +01:00
Retia 3d8d5e84c3 Improvements for the reset command to deal with empty current alias dir correctly (#2896) 2018-12-16 07:45:59 -08:00
Jun Ueoka 79a0d3b768 core/update: Scoop updates itself automatically for the first time after fresh install (#2907)
Fixes #2906
2018-12-16 13:16:48 +01:00
Jakub Čábera 0029f0b29d Fix regression from #2878 (#2899)
Fix regression from #2878
2018-12-14 12:51:17 +01:00
Jakub Čábera 000f1a7473 Support nested bucket folder in external buckets (#2878)
- Closes #2531 

Actual behaviour is kept and nothing is broken.

If external bucket contains `bucket` folder it's used for finding manifests.

How to test:

1. Create folder `TestBucket` in `$env:SCOOP\buckets`
1. Create manifest `CosiTest.json` with hello manifest # Or some other name which definetely cannot exists❗
1. execute `.\bin\scoop.ps1 install CosiTest` within this branch
1. Installing done
1. `.\bin\scoop.ps1 uninstall CosiTest`
1. Create folder `bucket` in `TestBucket` directory and copy CosiTest.json as `bucket\CosiTestBucket.json`
1. `.\bin\scoop.ps1 install CosiTest`
1. Installation will failed with `Couldn't find manifest for 'CosiTest'.`
1. `.\bin\scoop.ps1 install CosiTestBucket`
1. Installation Done
1. `.\bin\scoop.ps1 uninstall CosiTestBucket`
1. Unnstallation Done
2018-12-13 21:10:08 -08:00
Jakub Čábera 614b3279ba [autoupdate] base64 hash extraction fix (#2852) 2018-12-06 20:54:47 +01:00
Jakub Čábera a20b2e99e2 Fix empty bucket name (#2827) 2018-12-01 07:08:19 -08:00
Jakub Čábera 87df537f8c [json] Apparently I cannot use variable (#2768)
json.ps1: Fix a variable Problem introduced with the last changes
2018-11-14 05:41:04 +01:00
Jakub Čábera 3e1649553d formatjson.ps1: Format single value Arrays into String (#2642)
- Automatically convert single value arrays and recursively normalize PSObjects values
- Add tests
- Add .yml .editorconfig settings
2018-11-13 20:49:20 +01:00
Pakorn Vongseela f284dba5d7 install.ps1: Fix persisting bug with already existing folder (#2732)
closes https://github.com/lukesampson/scoop-extras/issues/1300
closes https://github.com/lukesampson/scoop-extras/issues/1370
closes #2724
closes #2671
2018-11-12 10:26:16 +01:00
krokofant 5a51098df5 Fix #2745 Workaround Microsofts syntactic PSModulePath (#2748)
* Workaround Microsofts syntactic PSModulePath

The default user PSModulePath is "$env:USERPROFILE\Documents\WindowsPowerShell\Modules". I the user env variable PSModulePath actually exists the default path is omitted - so we need to explicitly add it.
2018-11-08 19:35:02 +01:00
Ishan Arora 98e0721bb9 core.ps1: Fixed sh shims (path escaping in MSYS2 and Git bash) (#2742)
#2741 broke sh shims in MSYS2 environments (includes Git bash).
2018-11-05 20:27:55 +01:00
Ishan Arora ea1c3e5446 core.ps1: Fixed sh shims (#2741)
Fixes #2740.
Adding .exe suffix to cmd is needed in WSL.
Removing MSYS' slash-escaping from //C is needed in WSL, Cygwin, or anywhere outside MSYS (or Git Bash). Doesn't break MSYS after .exe suffix is added.

See also #1949, #1951
2018-11-05 18:07:10 +01:00
Richard Kuhnt 1eb2609db5 apps_in_bucket(): Use $_.Name on gci result (closes #2707) 2018-10-29 15:33:01 +01:00
Richard Kuhnt 310096e238 autoupdate: improve base64 hash detection 2018-10-01 16:35:47 +02:00
Richard Kuhnt 803525a866 install: fix fosshub downloads with aria2c 2018-09-23 13:19:48 +02:00
Richard Kuhnt 3453487ed6 autoupdate: add 'regex' alias for 'find' 2018-09-18 19:30:18 +02:00
Richard Kuhnt 76fdb6b74c checkver: add 'jsonpath' alias for 'jp' 2018-09-18 19:29:48 +02:00
yukihane 5f0ca5df6a install: ignore url fragment for PowerShell Core 6.1.0 (#2602) 2018-09-17 00:11:55 +02:00
Richard Kuhnt f2d9f0d79f getopt: skip if arg is $null 2018-09-15 12:40:12 +02:00
Richard Kuhnt 5f0c8cfb0a getopt: skip arg if it's decimal (closes #2598) 2018-09-15 12:22:47 +02:00
Richard Kuhnt fb58e92c13 json: catch JsonReaderException 2018-09-14 18:32:31 +02:00
Richard Kuhnt e82587dfc4 buckets: change wording of new_issue_msg() 2018-09-10 13:21:25 +02:00
Richard Kuhnt 98afb99990 autoupdate: Fix base64 hash extraction 2018-09-10 03:18:19 +02:00
Richard Kuhnt c9539b6575 autoupdate: linter fix 2018-09-09 21:19:45 +02:00
Richard Kuhnt 04c9ddeb6d autoupdate: Convert base64 encoded hash values 2018-09-09 16:57:47 +02:00
Leon Yu 9bc7d5f8b3 Fix .ps1 shim parsing logic due to prior PR (#2564)
Due to my prior PR #2562 which changed the content of .ps1 shims, the code that attempts to warn about shims being overwritten no longer detects app name correctly. This is to correct that.
2018-09-07 16:25:37 +02:00
Richard Kuhnt 19373f4b9b Add metalink support for aria2c (#2560)
This should fix #2480 and fix https://github.com/lukesampson/scoop-extras/issues/1126
2018-09-06 11:57:09 +02:00
Leon Yu 0f4a41a4ec core: Make shim support PowerShell 2.0 (#2562)
PowerShell on Windows comes with both 2.0 and 3.0+ installed. This is a feature inherited from .NET -- PowerShell 2.0 is based on .NET 2.0 which is installed side-by-side with .NET 3.0-4.7. It is possible to run PowerShell 2.0 by invoking the command powershell.exe -Version 2.0 -NoProfile.

This is a fairly useful feature for PowerShell scripters, as one can use PowerShell 2.0 to check for the basic compatibility of scripts without having to run a VM. As such, a user can have scoop apps installed via PowerShell 3.0+, and then launch PowerShell 2.0 for casual testing.

Currently the scoop shims are broken in PowerShell 2.0, as they use $PSScriptRoot. In addition, since PowerShell picks up {command}.ps1 before {command}.exe when looking for {command}, this makes using scoop-installed app difficult in PowerShell 2.0.

While Scoop command itself doesn't support PowerShell 2.0, and there is no point in doing so, it is fairly easy to make the shims support PowerShell 2.0, so this is what this patch does.
2018-09-05 12:14:22 +02:00
Richard Kuhnt f374924ab6 install/core: add function for extracting magic bytes 2018-09-04 14:34:29 +02:00
Richard Kuhnt 2ad547477b autoupdate: Fix metalink hash extraction 2018-09-04 14:21:39 +02:00
Richard Kuhnt fc938db7b1 Save install.json as UTF-8 2018-09-02 16:32:47 +02:00
Grigory f46131a798 Fix PowerShell core crash due to '-Encoding byte' being replaced with '-AsByteStream' (#2554) 2018-09-02 12:27:21 +02:00
Chawye Hsu 7697ba4ba8 feature(scoop-info): support url manifest (#2538) 2018-08-27 16:51:18 +02:00
Richard Kuhnt 1a2598bc30 Fix condition for persist_permission() again 2018-08-27 14:15:58 +02:00
Richard Kuhnt eb7b7cbf4f Fix condition for persist_permission() 2018-08-27 11:26:05 +02:00
Retia-Adolf fc1c2a6ac3 Set file write permission to global persist dir (#2524) 2018-08-26 15:37:42 +02:00
Richard Kuhnt ecf627c3b8 Allow simple metalink and meta4 hash extraction 2018-08-14 19:00:58 +02:00
Richard Kuhnt 2224da82f8 Allow extraction of nupkg files with 7zip 2018-08-09 19:23:06 +02:00
x-kej 77a2769ace Catch unzip failures from bad file names (like ../file.exe) (#2472) 2018-08-08 20:36:28 +02:00
Mathias Hermansson cd33a9e31e Change sf regex not to break some manifests. Fixes #2474 (#2476) 2018-08-08 20:34:54 +02:00