From 1402f2f146b35fd9680f023f5c231fb2be95c0fd Mon Sep 17 00:00:00 2001 From: Roberto Date: Tue, 16 Apr 2024 22:36:31 +0200 Subject: [PATCH 01/16] update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7297e23..4be8d53 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ src/utils/.md5 *.aux *.log *.synctex.gz -.idea \ No newline at end of file +.idea +cache.json From 420c9c03a3a5bfc735ccb1cb22f44751493bb131 Mon Sep 17 00:00:00 2001 From: Roberto Date: Tue, 16 Apr 2024 22:36:46 +0200 Subject: [PATCH 02/16] example of cache json --- cache-example.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 cache-example.json diff --git a/cache-example.json b/cache-example.json new file mode 100644 index 0000000..14a7efb --- /dev/null +++ b/cache-example.json @@ -0,0 +1,3 @@ +{ + "system" : "Linux" +} From 43a37d11e19c019c9119de530b88335718b690d8 Mon Sep 17 00:00:00 2001 From: archetipico <43927507+archetipico@users.noreply.github.com> Date: Tue, 16 Apr 2024 23:21:50 +0200 Subject: [PATCH 03/16] Huge refactor --- .gitignore | 8 +- setup.py | 24 ++++++ src/logo/big_name.svg | 78 +++++++++---------- src/package/MacOS/MacOSUpdate.sh | 29 ------- src/package/Windows/privileges.ps1 | 3 - system/darwin/package/arm.sh | 31 ++++++++ .../debian.sh => system/linux/package/apt.sh | 11 +-- .../linux/package/emerge.sh | 0 .../Linux => system/linux/package}/flatpak.sh | 0 .../nix.sh => system/linux/package/nixos.sh | 0 .../arch.sh => system/linux/package/pacman.sh | 4 - .../termux.sh => system/linux/package/pkg.sh | 0 .../Linux => system/linux/package}/rpm.sh | 0 .../Linux => system/linux/package}/snap.sh | 0 system/linux/package/yay.sh | 13 ++++ .../linux/package/zypper.sh | 0 system/windows/package/choco.ps1 | 3 + system/windows/package/nuget.ps1 | 3 + system/windows/package/scoop.ps1 | 3 + .../Windows => system/windows}/winUpdate.ps1 | 44 +++++++---- utils.py | 53 +++++++++++++ 21 files changed, 207 insertions(+), 100 deletions(-) create mode 100644 setup.py delete mode 100644 src/package/MacOS/MacOSUpdate.sh delete mode 100644 src/package/Windows/privileges.ps1 create mode 100644 system/darwin/package/arm.sh rename src/package/Linux/debian.sh => system/linux/package/apt.sh (84%) mode change 100755 => 100644 rename src/package/Linux/gentoo.sh => system/linux/package/emerge.sh (100%) mode change 100755 => 100644 rename {src/package/Linux => system/linux/package}/flatpak.sh (100%) mode change 100755 => 100644 rename src/package/Linux/nix.sh => system/linux/package/nixos.sh (100%) mode change 100755 => 100644 rename src/package/Linux/arch.sh => system/linux/package/pacman.sh (81%) mode change 100755 => 100644 rename src/package/Linux/termux.sh => system/linux/package/pkg.sh (100%) mode change 100755 => 100644 rename {src/package/Linux => system/linux/package}/rpm.sh (100%) mode change 100755 => 100644 rename {src/package/Linux => system/linux/package}/snap.sh (100%) mode change 100755 => 100644 create mode 100644 system/linux/package/yay.sh rename src/package/Linux/opensuse.sh => system/linux/package/zypper.sh (100%) mode change 100755 => 100644 create mode 100644 system/windows/package/choco.ps1 create mode 100644 system/windows/package/nuget.ps1 create mode 100644 system/windows/package/scoop.ps1 rename {src/package/Windows => system/windows}/winUpdate.ps1 (70%) create mode 100644 utils.py diff --git a/.gitignore b/.gitignore index 7297e23..78aa392 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,10 @@ src/utils/.md5 *.aux *.log *.synctex.gz -.idea \ No newline at end of file +.idea + + + + +__pycache__/ +cache.json \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..fca4693 --- /dev/null +++ b/setup.py @@ -0,0 +1,24 @@ +from colorama import init, Fore +from platform import system +from utils import check_packages, update_cache + +# Initialize colorama +init() + +# Check system +match system(): + case 'Darwin': + # Update system in cache + update_cache({'system': 'darwin'}) + print('{}>{} System set to Darwin'.format(Fore.BLUE, Fore.RESET)) + check_packages() + case 'Linux': + # Update system in cache + update_cache({'system': 'linux'}) + print('{}>{} System set to Linux'.format(Fore.BLUE, Fore.RESET)) + check_packages() + case 'Windows': + # Update system in cache + update_cache({'system': 'windows'}) + print('{}>{} System set to Windows'.format(Fore.BLUE, Fore.RESET)) + check_packages() diff --git a/src/logo/big_name.svg b/src/logo/big_name.svg index 4153f9b..6448645 100644 --- a/src/logo/big_name.svg +++ b/src/logo/big_name.svg @@ -1,40 +1,38 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eMerger - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +eMerger + \ No newline at end of file diff --git a/src/package/MacOS/MacOSUpdate.sh b/src/package/MacOS/MacOSUpdate.sh deleted file mode 100644 index 3862175..0000000 --- a/src/package/MacOS/MacOSUpdate.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -#Fetch MacOS version -osVersion=$(sw_vers -productVersion) - -installerPath="" -#Get major and minor version -majorVersion=$(echo $osVersion | cut -d "." -f 1) -minorVersion=$(echo $osVersion | cut -d "." -f 2) - -#Check which version is installed -if [ $majorVersion == "12" ];then - installerPath="install macOS Monterey.app" -elif [ $majorVersion == "11" ];then - installerPath="Install macOS Big Sur.app" -elif [ $minorVersion == "15"* ];then - installerPath="Install macOS Catalina.app" -elif - echo "Unsupported MacOS version." - exit 1 -fi - -#get full path -fullPath="/Applications/$installerPath/Contents/Resources/startosinstall" - -#command which updates system -softwareupdate --fetch-full-installer –full-installer-version $osVersion -echo "Inserire la password:" -#get privileges -sudo "$fullPath" --agreetolicense --forcequitapps --nointeraction --user "$USER" diff --git a/src/package/Windows/privileges.ps1 b/src/package/Windows/privileges.ps1 deleted file mode 100644 index 15b4fb3..0000000 --- a/src/package/Windows/privileges.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -# Start Powershell as administrator -Start-Process powershell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"winUpdate.ps1`"" - diff --git a/system/darwin/package/arm.sh b/system/darwin/package/arm.sh new file mode 100644 index 0000000..94578bd --- /dev/null +++ b/system/darwin/package/arm.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +osVersion=$(sw_vers -productVersion) + +installerPath="" +# Extract major and minor version numbers +majorVersion=$(echo $macOSVersion | cut -d '.' -f 1) +minorVersion=$(echo $macOSVersion | cut -d '.' -f 2) + +# Check which version is installed +if [ $majorVersion == "11" ]; then + installerPath="Install macOS Big Sur.app" +elif [ $majorVersion == "12" ]; then + installerPath="Install macOS Monterey.app" +elif [ $majorVersion == "13" ]; then + installerPath="Install macOS Ventura.app" +elif [ $majorVersion == "14" ]; then + installerPath="Install macOS Sonoma.app" +else + echo "Unsupported MacOS version." + exit 1 +fi + +# Get full path +fullPath="/Applications/$installerPath/Contents/Resources/startosinstall" + +# Command which updates system +softwareupdate --fetch-full-installer –full-installer-version $osVersion +echo "Insert password:" +# Get privileges +sudo "$fullPath" --agreetolicense --forcequitapps --nointeraction --user "$USER" diff --git a/src/package/Linux/debian.sh b/system/linux/package/apt.sh old mode 100755 new mode 100644 similarity index 84% rename from src/package/Linux/debian.sh rename to system/linux/package/apt.sh index dc26403..4960a70 --- a/src/package/Linux/debian.sh +++ b/system/linux/package/apt.sh @@ -6,15 +6,12 @@ source $SRC/utils/global.sh PWR=$(source $SRC/utils/check_pwr.sh) PKG="apt-get" - if [[ $(command -v apt) ]]; then PKG="apt" - - #These lines works on some systems only, for example I receive an error on a raspberry. - #puts RED "configuration: starting" - #try $PWR $PKG --configure -a - #puts GREEN "configuration: completed" - #puts RED "Error on --configure option" + + puts RED "configuration: starting" + try $PWR $PKG --configure -a + puts GREEN "configuration: completed" puts BLUE "Using $PKG $DEBIAN" diff --git a/src/package/Linux/gentoo.sh b/system/linux/package/emerge.sh old mode 100755 new mode 100644 similarity index 100% rename from src/package/Linux/gentoo.sh rename to system/linux/package/emerge.sh diff --git a/src/package/Linux/flatpak.sh b/system/linux/package/flatpak.sh old mode 100755 new mode 100644 similarity index 100% rename from src/package/Linux/flatpak.sh rename to system/linux/package/flatpak.sh diff --git a/src/package/Linux/nix.sh b/system/linux/package/nixos.sh old mode 100755 new mode 100644 similarity index 100% rename from src/package/Linux/nix.sh rename to system/linux/package/nixos.sh diff --git a/src/package/Linux/arch.sh b/system/linux/package/pacman.sh old mode 100755 new mode 100644 similarity index 81% rename from src/package/Linux/arch.sh rename to system/linux/package/pacman.sh index a98b49b..c404a7a --- a/src/package/Linux/arch.sh +++ b/system/linux/package/pacman.sh @@ -19,7 +19,3 @@ puts GREEN "upgrade: completed" puts RED "clean pacman caches: starting" try $PWR paccache -r puts GREEN "clean pacman caches: starting" - -puts RED "update AUR packages: starting" -try yay -Syu -puts GREEN "update AUR packages: starting" diff --git a/src/package/Linux/termux.sh b/system/linux/package/pkg.sh old mode 100755 new mode 100644 similarity index 100% rename from src/package/Linux/termux.sh rename to system/linux/package/pkg.sh diff --git a/src/package/Linux/rpm.sh b/system/linux/package/rpm.sh old mode 100755 new mode 100644 similarity index 100% rename from src/package/Linux/rpm.sh rename to system/linux/package/rpm.sh diff --git a/src/package/Linux/snap.sh b/system/linux/package/snap.sh old mode 100755 new mode 100644 similarity index 100% rename from src/package/Linux/snap.sh rename to system/linux/package/snap.sh diff --git a/system/linux/package/yay.sh b/system/linux/package/yay.sh new file mode 100644 index 0000000..28b31da --- /dev/null +++ b/system/linux/package/yay.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +SRC=$(dirname "$(readlink -f "$0")") +source $SRC/utils/global.sh + +PWR=$(source $SRC/utils/check_pwr.sh) +PKG="yay" + +puts BLUE "Using $PKG $ARCH" + +puts RED "update AUR packages: starting" +try $PKG -Syu +puts GREEN "update AUR packages: starting" diff --git a/src/package/Linux/opensuse.sh b/system/linux/package/zypper.sh old mode 100755 new mode 100644 similarity index 100% rename from src/package/Linux/opensuse.sh rename to system/linux/package/zypper.sh diff --git a/system/windows/package/choco.ps1 b/system/windows/package/choco.ps1 new file mode 100644 index 0000000..921f984 --- /dev/null +++ b/system/windows/package/choco.ps1 @@ -0,0 +1,3 @@ +Write-Host "Updating Chocolatey packages ..." +choco upgrade all -y +Write-Host "Chocolatey packages updated" \ No newline at end of file diff --git a/system/windows/package/nuget.ps1 b/system/windows/package/nuget.ps1 new file mode 100644 index 0000000..ae7c9be --- /dev/null +++ b/system/windows/package/nuget.ps1 @@ -0,0 +1,3 @@ +Write-Host "Updating NuGet packages ..." +Update-Package +Write-Host "NuGet packages updated" \ No newline at end of file diff --git a/system/windows/package/scoop.ps1 b/system/windows/package/scoop.ps1 new file mode 100644 index 0000000..5abfe2d --- /dev/null +++ b/system/windows/package/scoop.ps1 @@ -0,0 +1,3 @@ +Write-Host "Updating Scoop packages ..." +scoop update +Write-Host "Scoop packages updated" \ No newline at end of file diff --git a/src/package/Windows/winUpdate.ps1 b/system/windows/winUpdate.ps1 similarity index 70% rename from src/package/Windows/winUpdate.ps1 rename to system/windows/winUpdate.ps1 index f5cb2b6..1627815 100644 --- a/src/package/Windows/winUpdate.ps1 +++ b/system/windows/winUpdate.ps1 @@ -1,4 +1,27 @@ -# This script is focused on update Windows OS +# TODO RIMUOVERE + + + + + + + + + + + + + + + + + + + + + + +Start-Process powershell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"winUpdate.ps1`"" # Install PSWindowsUpdate if not installed if (!(Get-Module -Name PSWindowsUpdate -ListAvailable)) { @@ -7,20 +30,16 @@ if (!(Get-Module -Name PSWindowsUpdate -ListAvailable)) { } # Windows Update -Write-Host "Updating Windows..." -Write-Host "At the end your system will be rebooted..." -Get-WUInstall -AcceptAll -AutoReboot +Write-Host "Updating Windows ..." +Write-Host "At the end reboot your system" +Get-WUInstall -AcceptAll ####### Check installation and update of Chocolatey ####### # If you wanna install Chocolatey, you need this command # Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) if (!(Get-Command choco -ErrorAction SilentlyContinue)) { - Write-Host "Chocolatey not found. Skipping..." -} else { - Write-Host "Chocolatey is installed..." - Write-Host "Updating Chocolatey packages..." - choco upgrade all -y + #Write-Host "Chocolatey not found. Skipping..." } ######## Check installation and update Nuget ####### @@ -29,10 +48,6 @@ if (!(Get-Command choco -ErrorAction SilentlyContinue)) { # Move-Item -Path "$env:temp\nuget.exe" -Destination "$env:ProgramFiles\NuGet" -Force if (!(Get-Command nuget -ErrorAction SilentlyContinue)) { Write-Host "NuGet not found. Skipping..." -} else { - Write-Host "NuGet is installed..." - Write-Host "Updating Nuget packages..." - Update-Package -ProjectName YourProjectName -Reinstall } ####### Check installation and update scoop ####### @@ -40,9 +55,6 @@ if (!(Get-Command nuget -ErrorAction SilentlyContinue)) { # Set-ExecutionPolicy RemoteSigned -scope Process; iex (new-object net.webclient).downloadstring('https://get.scoop.sh') if (!(Test-Path $env:USERPROFILE\scoop)) { Write-Host "Scoop not found. Skipping..." -} else { - Write-Host "Scoop is installed..." - scoop update } Write-Host "Update completed." diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..dbb306a --- /dev/null +++ b/utils.py @@ -0,0 +1,53 @@ +from colorama import Fore +from json import dump, load +from os import path +from shutil import which + +CACHE_PATH = 'cache.json' +PACKAGES = { + "apt-get": "apt", + "osascript": "arm", + "choco": "choco", + "emerge": "emerge", + "flatpak": "flatpak", + "nixos-rebuild": "nixos", + "nuget": "nuget", + "scoop": "scoop", + "pacman": "pacman", + "pkg": "pkg", + "rpm": "rpm", + "snap": "snap", + "yay": "yay", + "zypper": "zypper" +} + +# Add value to caches +def update_cache(kv): + try: + # If the file exists + if path.exists(CACHE_PATH): + # Load its content + with open(CACHE_PATH, 'r') as file: + data = load(file) + else: + # New cache + data = {} + + # Add data to the cache + data.update(kv) + + # Write the updated data back to the file + with open(CACHE_PATH, 'w') as file: + dump(data, file, indent=4) + except Exception as e: + print(e) + +def check_packages(): + # For each package check if it exists and add it to the cache + installed_packages = [] + for k in PACKAGES.keys(): + path = which(k) + if path: + installed_packages.append(k) + update_cache({'packages': installed_packages}) + print('{}>{} The following packages were found: {}'.format(Fore.BLUE, Fore.RESET, installed_packages)) From 0a2df2e39b7a3fb1b6bb11fd7cfdff1cea8a345a Mon Sep 17 00:00:00 2001 From: archetipico <43927507+archetipico@users.noreply.github.com> Date: Tue, 16 Apr 2024 23:40:04 +0200 Subject: [PATCH 04/16] Fix --- utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils.py b/utils.py index dbb306a..8ab3fde 100644 --- a/utils.py +++ b/utils.py @@ -45,9 +45,9 @@ def update_cache(kv): def check_packages(): # For each package check if it exists and add it to the cache installed_packages = [] - for k in PACKAGES.keys(): - path = which(k) + for key, value in PACKAGES.items(): + path = which(key) if path: - installed_packages.append(k) + installed_packages.append(value) update_cache({'packages': installed_packages}) print('{}>{} The following packages were found: {}'.format(Fore.BLUE, Fore.RESET, installed_packages)) From fb2d0178f1912bf561d370a20e8c3fbb0d3a19b4 Mon Sep 17 00:00:00 2001 From: archetipico <43927507+archetipico@users.noreply.github.com> Date: Wed, 17 Apr 2024 00:04:14 +0200 Subject: [PATCH 05/16] Refactor --- README.md | 6 ++- setup.py | 49 ++++++++++-------- system/linux/package/nixos.sh | 8 +++ utils.py | 94 ++++++++++++++++++----------------- 4 files changed, 90 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 7aaecae..28e3b42 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ eMerger is a simple script to clean update your system and your packages by just
  • Raspbian
  • Termux
  • Ubuntu
  • +
  • Windows 11
  • Systems tested and not working (help wanted)

    @@ -37,13 +38,16 @@ eMerger is a simple script to clean update your system and your packages by just