automated method to install multiple packages?
paulirish opened this issue · 14 comments
I love this sort of list; really nice job putting it together.
Once Package Control is in place, is there a nice way to bulk install all these packages? I ask because I'm putting together a larger framework and I'd like the install script to be able to set up the SublimeText packages on its own.
So ideally, you run my install script (let's assume its a shell script on os x, windows):
- if ST2 is installed, install PackageControl if it's not there already.
- once PC is in, install a list of these packages (or my own list)
- you then open ST2 all the magic is there, waiting for you
Is this at all possible?
ping @wbond as he's the expert here.
To install Package Control, http://sublime.wbond.net/Package%20Control.sublime-package needs to be placed inside of the Installed Packages/ folder. The next time Sublime starts, it will install the package.
To batch install other packages, a Package Control.sublime-settings file needs to be placed into the Packages/User/ folder. Inside of the settings file should be a JSON object with the key "installed_packages" that references a list of package names. When Package Control starts, if any of those packages are not present, the will be automatically downloaded and installed. Here is an example: http://pastebin.com/NLEavL1K.
Magic. Exactly what I needed to hear. :)
Thanks Will! Your contributions are incredible.
@wbond, that is awesome! Perhaps I'll create that file here so people can bulk install all these packages.
@paulirish Could the Package Control.sublime-package file & other custom settings files be installed by running one install script? And @wbond Could Package Control & this install script be installed with one command & then you restart Sublime?
It would be fairly trivial to write a bash script that utilizes wget/curl to perform the download and install on OS X and Linux. I'm sure there is some way to do the same on Windows with WSH, there is just the slight added complexity that the Windows versions of Sublime can be portable, so there isn't always a definitive place for the config folder.
I've got a Puppet manifest to install the dev (or beta) and then, after the program has been run for the first time (and the base packages have been installed/directories created), it will go on to install whatever other packages you specify.
https://github.com/alister/puppet-sublimetext2
@paulirish @wbond, it would be nice to have a oneliner like @mrmartineau suggested, but to be executed not from the editor, from command line. As you can see in the snippet below, I use curl to download package_control on Linux and cp to paste my package list, but after that I have to open, wait and close Sublime Text 2 manually several times for it complete. I don't think I can open sublime text 2 just to execute a script and close with a command.
ST2=~/.config/sublime-text-2
mkdir -p $ST2/{Installed\ Packages,Packages/User}
curl http://sublime.wbond.net/Package%20Control.sublime-package \
> $ST2/Installed\ Packages/Package\ Control.sublime-package
cp $DOTFILES/st2/* $ST2/Packages/User
# Open Sublime Text and wait a bunch of minutes for package_control to install
# itself and all packages (several errors and manual restarts are expected)
@mmacedo I have wrote a little gist to make this process little easier:
https://gist.github.com/vishaltelangre/5075346
Thanks @mmacedo. I will link to your post in the wiki
@mrmartineau @mmacedo @paulirish @wbond. Go figure...
I've been working on automating the sublime install+config. I started with a shell script then changed to python. A network admin buddy of mine is learning python so I decided to rewrite it as a python application and make it cross-platform so he can see the python-equivalent of a bash script.
Note: I haven't implemented the Windows portion yet but it should work in both Linux and OSX.
Since there's interest here, I migrated the code into its own repository @ https://github.com/evanplaice/sublime-text-seed.
The setup.py
script handles the following:
-
_Check and install
Sublime Text
_If
Sublime Text
isn't found, it automates the install viaapt-get
(*nix),homebrew
(OSX), orchocolatey
(Windows). -
_Install
Package Control
_Since
Package Control
needs to be installed separately, it fetches it withurllib2
via aGET
request. -
_Copy the configuration_
The config files found in the config directory are copied to the default settings locations, which differ for each OS.
-
_Copy the license (Not Implemented)_
If found , the license file is setup.
Note: Which is included in
.gitignore
by default to prevent a credential leak.
And in Powershell 5:
$packageControl = "http://sublime.wbond.net/Package%20Control.sublime-package"
$sublimeConfig = "$env:APPDATA\Sublime Text 3"
$packagesRoot = "$sublimeConfig\Installed Packages"
$userPackages = "$sublimeConfig\Packages\User"
Invoke-WebRequest $packageControl -OutFile "$packagesRoot\Package Control.sublime-package"
$packagesToInstall = @{
installed_packages = @(
"SFTP",
"Git"
)
}
ConvertTo-Json $packagesToInstall | Out-File "$userPackages\Package Control.sublime-settings" -Encoding ASCII
building on @evanplaice code .. i have also included automatic sublime projects creation in https://github.com/ahmadassaf/sublime-text-bootstrap
@ahmadassaf @evanplaice The code you have is extremely insecure in terms of installing Package Control:
- Is uses HTTP, allowing MITM attacks
- It uses a domain name that Package Control stopped using years ago
Modern versions of Sublime Text include a command to install Package Control securely. If you want to automate things, just call that command (look in the Default.sublime-commands for the command name).
Thanks a lot @wbond for this info. I have just updated the link to the one i noticed in the latest instructions https://packagecontrol.io/Package%20Control.sublime-package
@wbond Thanks for the heads-up. The package control setup has been updated to use the more secure source link. Using the command pallet would be great but this tool is intended to be used as a complete unattended setup. AFAIK, it's not possible to launch commands in sublime directly from the CLI.
@ahmadassaf Nice work. When I get the chance I'll have to review the changes you made in detail, I could probably learn a few things from the improvements you made.