From 368cec636f8f553517dc72f557b081a53820015d Mon Sep 17 00:00:00 2001 From: Alejandro Barrachina Date: Sat, 26 Feb 2022 20:29:24 +0100 Subject: [PATCH] category and program system reworked to use JSON --- .vscode/settings.json | 10 ++++++++ Games/games.ps1 | 13 ---------- Games/games.txt | 3 --- Programming/programming.ps1 | 13 ---------- Programming/programming.txt | 9 ------- README.md | 36 ++++++++++++++++++-------- Template/template.ps1 | 13 ---------- Template/template.txt | 1 - Utils/Utils.ps1 | 13 ---------- Utils/Utils.txt | 9 ------- json/games.json | 32 ++++++++++++++++++++++++ json/programming.json | 50 +++++++++++++++++++++++++++++++++++++ json/utils.json | 50 +++++++++++++++++++++++++++++++++++++ main.ps1 | 29 ++++++++++++--------- 14 files changed, 184 insertions(+), 97 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 Games/games.ps1 delete mode 100644 Games/games.txt delete mode 100644 Programming/programming.ps1 delete mode 100644 Programming/programming.txt delete mode 100644 Template/template.ps1 delete mode 100644 Template/template.txt delete mode 100644 Utils/Utils.ps1 delete mode 100644 Utils/Utils.txt create mode 100644 json/games.json create mode 100644 json/programming.json create mode 100644 json/utils.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6d6eaec --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "spellright.language": [ + "en", + "es" + ], + "spellright.documentTypes": [ + "markdown", + "latex" + ] +} diff --git a/Games/games.ps1 b/Games/games.ps1 deleted file mode 100644 index f152874..0000000 --- a/Games/games.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -$games = "0" - -while ($games -ne "y" -and $games -ne "n") { - $games = Read-Host "Install gaming stuff? (y/n) " - if ($games -eq "y") { - foreach ($line in Get-Content $PSSCriptRoot\games.txt) { - if ($line.contains("#")) { - continue - } - winget install --id $line -e - } - } -} diff --git a/Games/games.txt b/Games/games.txt deleted file mode 100644 index e0ec224..0000000 --- a/Games/games.txt +++ /dev/null @@ -1,3 +0,0 @@ -Valve.Steam -GOG.Galaxy -Ubisoft.Uplay \ No newline at end of file diff --git a/Programming/programming.ps1 b/Programming/programming.ps1 deleted file mode 100644 index 48426fe..0000000 --- a/Programming/programming.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -$programming = "0" - -while ($programming -ne "y" -and $programming -ne "n") { - $programming = Read-Host "Install programming stuff? (y/n) " - if ($programming -eq "y") { - foreach ($line in Get-Content $PSSCriptRoot\programming.txt) { - if ($line.contains("#")) { - continue - } - winget install --id $line -e - } - } -} diff --git a/Programming/programming.txt b/Programming/programming.txt deleted file mode 100644 index 90c98a1..0000000 --- a/Programming/programming.txt +++ /dev/null @@ -1,9 +0,0 @@ -Microsoft.WindowsTerminal -Microsoft.VisualStudioCode -Microsoft.VisualStudio.Community -Microsoft.Powertoys -Python.Python -RubyInstallerTeam.RubyWithDevKit -AnsgarBecker.HeidiSQL -Git.Git -Axosoft.GitKraken diff --git a/README.md b/README.md index e09b6cd..ae33b79 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,36 @@ Script using winget for easy windows setup -## How to create new categories +## Add new programs to existing categories + +To add a new program you have to add a new entry to the array inside its JSON file. -In main.ps1 put this line of code at the end of the script +Said object must follow this model -```powershell - .\NewFolder\NewScript.ps1 +```json +{ + "mode": "ID or NAME", + "identifier": "Name or ID of the program", + "source": "winget or msstore", + "scope": "user or machine" +} ``` -In the new folder create a .txt file with the app id's and a .ps1 with the file.txt name in the line +Depending on whether it comes from winget or the Microsoft Store, you should put "winget" or "msstore" on the source field. -```powershell - foreach ($line in Get-Content $PSSCriptRoot\newFile.txt) -``` +Some programs as Netflix can only be installed for the current user, others like Steam can only be installed machine-wide. -And change the name of the category in +## How to create new categories -```powershell - $confirmation = Read-Host "Install EXAMPLE stuff? (y/n) " +To create a new category you only have to add a new JSON file to [./json](./json). This files will be an array of programs, so you have to use an array syntax inside the file. Open the file with a square bracket, open and close a new program with curly brackets, and use a coma to separate programs: + +```json +[ + { + ONE Program + }, + { + OTHER PROGRAM + } +] ``` diff --git a/Template/template.ps1 b/Template/template.ps1 deleted file mode 100644 index 9c1256b..0000000 --- a/Template/template.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -$confirmation = "0" - -while ($confirmation -ne "y" -and $confirmation -ne "n") { - $confirmation = Read-Host "Install EXAMPLE stuff? (y/n) " - if ($confirmation -eq "y") { - foreach ($line in Get-Content $PSSCriptRoot\newFile.txt) { - if ($line.contains("#")) { - continue - } - winget install --id $line -e - } - } -} diff --git a/Template/template.txt b/Template/template.txt deleted file mode 100644 index 5c633b4..0000000 --- a/Template/template.txt +++ /dev/null @@ -1 +0,0 @@ -#This is a comment, commented lines will be ignored diff --git a/Utils/Utils.ps1 b/Utils/Utils.ps1 deleted file mode 100644 index f39116d..0000000 --- a/Utils/Utils.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -$utils = "0" - -while ($utils -ne "y" -and $utils -ne "n") { - $utils = Read-Host "Install utils stuff? (y/n) " - if ($utils -eq "y") { - foreach ($line in Get-Content $PSSCriptRoot\utils.txt) { - if ($line.contains("#")) { - continue - } - winget install --id $line -e - } - } -} diff --git a/Utils/Utils.txt b/Utils/Utils.txt deleted file mode 100644 index 5ff4abe..0000000 --- a/Utils/Utils.txt +++ /dev/null @@ -1,9 +0,0 @@ -Spotify.Spotify -Discord.Discord -LogMeIn.LastPass -TUG.TexLive -Mozilla.Firefox -Google.Chrome -Corsair.iCUE -flux.flux -RARLab.WinRAR \ No newline at end of file diff --git a/json/games.json b/json/games.json new file mode 100644 index 0000000..6af7a86 --- /dev/null +++ b/json/games.json @@ -0,0 +1,32 @@ +[ + { + "mode": "id", + "identifier": "Valve.Steam", + "source": "winget", + "scope": "machine" + }, + { + "mode": "id", + "identifier": "GOG.Galaxy", + "source": "winget", + "scope": "machine" + }, + { + "mode": "id", + "identifier": "Ubisoft.Uplay", + "source": "winget", + "scope": "machine" + }, + { + "mode": "id", + "identifier": "EpicGames.EpicGamesLauncher", + "source": "winget", + "scope": "machine" + }, + { + "mode": "id", + "identifier": "ElectronicArts.EADesktop", + "source": "winget", + "scope": "machine" + } +] diff --git a/json/programming.json b/json/programming.json new file mode 100644 index 0000000..2f635e7 --- /dev/null +++ b/json/programming.json @@ -0,0 +1,50 @@ +[ + { + "mode": "id", + "identifier": "Microsoft.WindowsTerminal", + "source": "winget", + "scope": "user" + }, + { + "mode": "id", + "identifier": "Microsoft.WindowsTerminal", + "source": "winget", + "scope": "user" + }, + { + "mode": "id", + "identifier": "Microsoft.VisualStudio.2022.Community", + "source": "winget", + "scope": "user" + }, + { + "mode": "id", + "identifier": "Python.Python", + "source": "winget", + "scope": "user" + }, + { + "mode": "id", + "identifier": "AnsgarBecker.HeidiSQL", + "source": "winget", + "scope": "user" + }, + { + "mode": "id", + "identifier": "Git.Git", + "source": "winget", + "scope": "user" + }, + { + "mode": "id", + "identifier": "Axosoft.GitKraken", + "source": "winget", + "scope": "user" + }, + { + "mode": "id", + "identifier": "RubyInstallerTeam.RubyWithDevKit", + "source": "winget", + "scope": "user" + } +] diff --git a/json/utils.json b/json/utils.json new file mode 100644 index 0000000..23da954 --- /dev/null +++ b/json/utils.json @@ -0,0 +1,50 @@ +[ + { + "mode": "id", + "identifier": "Spotify.Spotify", + "source": "winget", + "scope": "user" + }, + { + "mode": "id", + "identifier": "Discord.Discord", + "source": "winget", + "scope": "machine" + }, + { + "mode": "id", + "identifier": "Mozilla.Firefox", + "source": "winget", + "scope": "machine" + }, + { + "mode": "id", + "identifier": "Google.Chrome", + "source": "winget", + "scope": "machine" + }, + { + "mode": "id", + "identifier": "flux.flux", + "source": "winget", + "scope": "machine" + }, + { + "mode": "id", + "identifier": "RARLab.WinRAR", + "source": "winget", + "scope": "machine" + }, + { + "mode": "id", + "identifier": "9WZDNCRFJ3TJ", //netflix + "source": "winget", + "scope": "user" + }, + { + "mode": "id", + "identifier": "Corsair.iCUE", + "source": "winget", + "scope": "machine" + } +] diff --git a/main.ps1 b/main.ps1 index 45570ff..ca35504 100644 --- a/main.ps1 +++ b/main.ps1 @@ -21,15 +21,20 @@ foreach ($gpu in $gpus) { } } -#Programming script -.\Programming\programming.ps1 - -#Games script -.\Games\Games.ps1 - -#Util script -.\Utils\Utils.ps1 - - -#Uninstal shit -.\Uninstall\Uninstal.ps1 +Get-ChildItem -Recurse -Filter *.json | Foreach-Object { + $install = 0 + $fileName = [System.IO.Path]::GetFileNameWithoutExtension($_) + while ($install -ne "y" -and $install -ne "n") { + $install = Read-Host "Install $fileName stuff? (y/n) " + if ($install -eq "y") { + $json = Get-Content -Raw -Path $_.FullName | ConvertFrom-Json + $json | ForEach-Object { + $mode = $_.mode + $id = $_.identifier + $source = $_.source + $scope = $_.scope + winget.exe install --$mode $id -e -s $source --scope $scope --accept-package-agreements --accept-source-agreements --force + } + } + } +}