Skip to content

Commit

Permalink
Installer updates mostly (#2428)
Browse files Browse the repository at this point in the history
* Add Ubuntu 24.xx installer.
Minor update to debian 12 & added 13 - needs testing.

* Make run.sh and update.sh check for venv.

* More compatibility with venv installs

* do testing with debian, and update --list

* Add PopOS 24.04 and Shellcheck updates

* add default case to pop OS

* Add detected OS to install.sh --list

* Allow bypass of system package steps or of musicbot install steps.

* more tweaks and options

* use pypi discord.py

* try to add install path option

* no = supported here

* Move the default check.

* Clean up service install. 
Remove cli alias as unsupported.
Adjust post install message for venv.
Add --no-sudo option.

* more service install tweaks

* output formatting

* don't touch options.ini if it exists already.
fix copy and sed.

* service setup assumes previous cd to clone dir.

* Turn the template into just an example file.
Installer now has its own internal template to generate service files.

* add / change warning about install directory with --service option.

* more output tweaks

* Ap add all (#6)

Adds new sub-command as `autoplaylist [+ | add] all` which allows users to add all songs in the queue to the auto playlist. 

Conflicts:
	musicbot/bot.py

* Use discord via git repo ... test test test






I should have left the installers broken...

* Add some root/sudo checks.

* Try to install winget and restart for env vars.

* Fix env vars maybe, add file extension un-hide logic

* Add anybranch option, fix ffmpeg error when installed but no update.

* Install path and cleaning output.

* fix winget issues with ffmpeg

* set appropriate repo url.

* checks

* add certificate pre-fetch to installer...

* add lock to summon.
also tidy code

* Fix extractor checks to work with and without plugins like oauth2.
SpotifyPlaylist objects only allow track member types.

* fix summon message on stream
  • Loading branch information
itsTheFae authored Sep 28, 2024
1 parent 30c8577 commit a572e71
Show file tree
Hide file tree
Showing 16 changed files with 1,014 additions and 363 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.pyc
~*/
.vscode/
*.service

audio_cache/
dectalk/
Expand Down
5 changes: 4 additions & 1 deletion config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
"cmd-save-exists": "This song is already in the autoplaylist.",
"cmd-save-invalid": "There is no valid song playing.",
"cmd-save-success": "Added <{0}> to the autoplaylist.",
"cmd-save-success-multiple": "Added {0} songs to the autoplaylist.",
"cmd-unsave-does-not-exist": "This song is not yet in the autoplaylist.",
"cmd-unsave-success": "Removed <{0}> from the autoplaylist.",
"cmd-autoplaylist-does-not-exist": "This song is not yet in the autoplaylist.",
"cmd-autoplaylist-invalid": "The supplied song link is invalid.",
"cmd-autoplaylist-option-invalid": "Invalid option \"{0}\" specified, use +, -, add, or remove",
"cmd-autoplaylist-success": "Removed <{0}> from the autoplaylist.",
"cmd-autoplaylist-add-all-empty-queue": "The queue is empty. Add some songs with `{0}play`!",
"cmd-save-all-exist": "All songs in the queue are already in the autoplaylist.",
"cmd-joinserver-response": "Click here to add me to a server: \n{}",
"cmd-play-spotify-album-process": "Processing album `{0}` (`{1}`)",
"cmd-play-spotify-album-queued": "Enqueued `{0}` with **{1}** songs.",
Expand Down Expand Up @@ -81,7 +84,7 @@
"cmd-resume-reply": "Resumed music in `{0.name}`",
"cmd-resume-none": "Player is not paused.",
"cmd-shuffle-reply": "Shuffled `{0}`'s queue.",
"cmd-clear-reply": "Cleared `{0}`'s queue",
"cmd-clear-reply": "Cleared `{0}'s` queue",
"cmd-remove-none": "There's nothing to remove!",
"cmd-remove-reply": "Removed `{0}` added by `{1}`",
"cmd-remove-missing": "Nothing found in the queue from user `%s`",
Expand Down
2 changes: 1 addition & 1 deletion install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CD "%~dp0"

SET InstFile="%~dp0%\install.ps1"
IF exist %InstFile% (
powershell.exe -noprofile -executionpolicy bypass -file "%InstFile%"
powershell.exe -noprofile -executionpolicy bypass -file "%InstFile%" %*
) ELSE (
echo Could not locate install.ps1
echo Please ensure it is available to continue the automatic install.
Expand Down
150 changes: 111 additions & 39 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# This script is designed to be used without pulling the repository first!
# You can simply download and run it to have MusicBot installed for you.
# Current the script only supports one installation per user account.
# Currently the script only supports one installation per user account.
#
# Notice:
# If you want to run this .ps1 script without setting execution policy in PowerShell,
# you can make use of the following command in command-prompt.
#
# powershell.exe -noprofile -executionpolicy bypass -file install.ps1
#
# Last tested:
# Win 10 Home 22H2 x64 - 2024/09/26
# --------------------------------------------------CLI Parameters-----------------------------------------------------
param (
# -anybranch Enables the use of any named branch, if it exists on repo.
[switch]$anybranch = $false
)
# Where to put MusicBot by default. Updated by repo detection.
# prolly should be param, but someone who cares about windows can code for it.
$Install_Dir = (pwd).Path + '\MusicBot\'

# ---------------------------------------------Install notice and prompt-----------------------------------------------
"MusicBot Installer"
""
Expand All @@ -34,32 +45,71 @@ if($iagree -ne "Y" -and $iagree -ne "y")
Return
}

if (-Not (Get-Command winget -ErrorAction SilentlyContinue) )
{
# First, unhide file extensions...
$FERegPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
$HideExt = (Get-ItemProperty -Path $FERegPath -Name "HideFileExt").HideFileExt
if ($HideExt -eq 1) {
""
"Sorry, you must install WinGet to use this installer."
"Supposedly included with Windows, but we couldn't find it."
"You can get it via Microsoft Store, the Official repo on github, or "
"use the following link to quickly download an installer for it:"
" https://aka.ms/getwinget "
""
Return
"Microsoft hates you and hides file extensions by default."
"We're going to un-hide them to make things less confusing."
Set-ItemProperty -Name "HideFileExt" -Value 0 -Path $FERegPath -Force
}
else

# If no winget, try to download and install.
if (-Not (Get-Command winget -ErrorAction SilentlyContinue) )
{
""
"Checking WinGet can be used..."
"If prompted, you must agree to the MS terms to continue installing."
"Microsoft WinGet tool is required to continue installing."
"It will be downloaded from:"
" https://aka.ms/getwinget "
""
winget list -q Git.Git
"Please complete the Windows installer when prompted."
""

# download and run the installer.
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "https://aka.ms/getwinget" -OutFile "winget.msixbundle"
$ProgressPreference = 'Continue'
Start-Process "winget.msixbundle"

# wait for user to finish installing winget...
$ready = Read-Host "Is WinGet installed and ready to continue? [y/n]"
if ($ready -ne "Y" -and $ready -ne "y") {
# exit if not ready.
Return
}

# check if winget is available post-install.
if (-Not (Get-Command winget -ErrorAction SilentlyContinue) ) {
"WinGet is not available. Installer cannot continue."
Return
}
}

#
""
"Checking WinGet can be used..."
"If prompted, you must agree to the MS terms to continue installing."
""
winget list -q Git.Git
""

# since windows is silly with certificates and certifi may not always work,
# we queitly spawn some requests that -may- populate the certificate store.
# this isn't a sustainable approach, but it seems to work...
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "https://discord.com" -OutFile "cert.fetch" 2>&1 | Out-Null
Invoke-WebRequest -Uri "https://spotify.com" -OutFile "cert.fetch" 2>&1 | Out-Null
$ProgressPreference = 'Continue'
Remove-Item "cert.fetch"

# -----------------------------------------------------CONSTANTS-------------------------------------------------------

$DEFAULT_URL_BASE = "https://discordapp.com/api"
$MB_RepoURL = "https://github.com/Just-Some-Bots/MusicBot.git"

# ----------------------------------------------INSTALLING DEPENDENCIES------------------------------------------------
$NeedsEnvReload = 0

# Check if git is installed
"Checking if git is already installed..."
Expand All @@ -69,6 +119,7 @@ if (!($LastExitCode -eq 0))
# install git
"Installing git..."
Invoke-Expression "winget install Git.Git"
$NeedsEnvReload = 1
"Done."
}
else
Expand All @@ -85,6 +136,7 @@ if (!($LastExitCode -eq 0))
# install python version 3.11 with the py.exe launcher.
"Installing python..."
Invoke-Expression "winget install Python.Python.3.11 --custom \`"/passive Include_launcher=1\`""
$NeedsEnvReload = 1
"Done."
}
else
Expand All @@ -95,12 +147,13 @@ else

# Check if ffmpeg is installed
"Checking if FFmpeg is already installed..."
Invoke-Expression "winget list -q Gyan.FFmpeg" | Out-Null
Invoke-Expression "winget list -q ffmpeg" | Out-Null
if (!($LastExitCode -eq 0))
{
# install FFmpeg
"Installing FFmpeg..."
Invoke-Expression "winget install Gyan.FFmpeg"
Invoke-Expression "winget install ffmpeg"
$NeedsEnvReload = 1
"Done."
}
else
Expand All @@ -109,10 +162,11 @@ else
}
""

# NOTE: if we need to refresh the environment vars (Path, etc.) after installing
# the above packages, we may need to add some other dependency which provides
# RefreshEnv.bat or manually manage paths to newly installed exes.
# Users should be able to get around this by restarting the powershell script.
# try to reload environment variables...
if ($NeedsEnvReload -eq 1)
{
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
}

# --------------------------------------------------PULLING THE BOT----------------------------------------------------

Expand All @@ -125,32 +179,44 @@ if((Test-Path $MB_Reqs_File) -and (Test-Path $MB_Module_Dir) -and (Test-Path $MB
""
"Installer detected an existing clone, and will continue installing with the current source."
""
$Install_Dir = (pwd).Path
} else {
""
"MusicBot currently has three branches available."
" master - Stable MusicBot, least updates and may at times be out-of-date."
" review - Newer MusicBot, usually stable with less updates than the dev branch."
" dev - The newest MusicBot, latest features and changes which may need testing."
if($anybranch) {
" * - WARNING: Any branch name is allowed, if it exists on github."
}
""
$experimental = Read-Host "Enter the branch name you want to install"
if($experimental -eq "dev")
{
"Installing dev branch..."
$branch = "dev"
}
if($experimental -eq "review")
{
"Installing review branch..."
$branch = "review"
}
else
{
"Installing master branch..."
$branch = "master"
$experimental = $experimental.Trim()
switch($experimental) {
"dev" {
"Installing dev branch..."
$branch = "dev"
}
"review" {
"Installing review branch..."
$branch = "review"
}
default {
if($anybranch -and $experimental -and $experimental -ne "master")
{
"Installing with $experimental branch, if it exists..."
$branch = $experimental
}
else
{
"Installing master branch..."
$branch = "master"
}
}
}

Invoke-Expression "git clone https://github.com/Just-Some-Bots/MusicBot.git MusicBot -b $branch"
Invoke-Expression "cd MusicBot"
Invoke-Expression "git clone $MB_RepoURL '$Install_Dir' -b $branch"
Invoke-Expression "cd '$Install_Dir'"
""
}

Expand All @@ -169,14 +235,15 @@ $versionArray = "3.8", "3.9", "3.10", "3.11", "3.12"

foreach ($version in $versionArray)
{
Invoke-Expression "py -$version -c 'exit()'" | Out-Null
Invoke-Expression "py -$version -c 'exit()' 2>&1" | Out-Null
if($LastExitCode -eq 0)
{
$PYTHON = "py -$version"
}
}

"Using $PYTHON to install and run MusicBot..."
""
Invoke-Expression "$PYTHON -m pip install --upgrade -r requirements.txt"

# -------------------------------------------------CONFIGURE THE BOT---------------------------------------------------
Expand All @@ -190,7 +257,9 @@ if($iagree -ne "Y" -and $iagree -ne "y")
{
"All done!"
"Remember to configure your bot token and other options before you start."
"You can use run.bat to start the MusicBot."
"You must open a new command prompt before using run.bat to start the MusicBot."
"MusicBot was installed to:"
" $Install_Dir"
Return
}

Expand Down Expand Up @@ -265,4 +334,7 @@ else
"Saving your config..."
Set-Content -Path ".\config\options.ini" -Value $config

"You can now use run.bat to run the bot"
"You can use run.bat to run the bot."
"Restart your command prompt first!"
"MusicBot was installed to:"
" $Install_Dir"
Loading

0 comments on commit a572e71

Please sign in to comment.