#!/bin/bash
version=7.3.6

rm -rf "$HOME/powershell"
install_packages libc6 libgcc1 libgssapi-krb5-2 libstdc++6 zlib1g libicu72 '|' libicu71 '|' libicu70 '|' libicu69 '|' libicu68 '|' libicu67 '|' libicu66 '|' libicu65 '|' libicu63 '|' libicu60 '|' libicu57 '|' libicu55 '|' libicu52 libssl3 '|' libssl1.1 '|' libssl1.0.2 '|' libssl1.0.0 libunwind8 || exit 1
wget https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-linux-arm${arch}.tar.gz || exit 1
mkdir -p ~/powershell || error "Unable to create Powershell Directory!"
tar -xf ./powershell-${version}-linux-arm${arch}.tar.gz -C ~/powershell || error "Unable to extract / copy Powershell to directory!"
rm -f ./powershell-${version}-linux-arm${arch}.tar.gz || sudo rm -f ./powershell-${version}-linux-arm${arch}.tar.gz
status 'Creating symlink...'
sudo "$HOME/powershell/pwsh" -command 'New-Item -ItemType SymbolicLink -Path "/usr/local/bin/pwsh" -Target "$PSHOME/pwsh" -Force' || error "Unable to link Powershell to /usr/local/bin!"

status 'Creating menu entry...'
echo "[Desktop Entry]
Version=${version}
Name=Microsoft PowerShell
GenericName=shell
Exec=pwsh %U
Terminal=true
X-MultipleArgs=false
Type=Application
Icon=$(dirname "$0")/icon-64.png
Categories=Utility
StartupNotify=true" > $HOME/.local/share/applications/powershell.desktop || error 'Failed to create menu entry!'
