#!/usr/bin/env ruby # encoding: utf-8 require 'rubygems' require 'commander/import' require 'aptly_cli' program :version, AptlyCli::VERSION program :description, 'Aptly repository API client' command :file_list do |c| c.syntax = 'aptly-cli file_list [options]' c.summary = 'List all directories that contain uploaded files' c.description = 'List all directories' c.example 'List all directories for file uploads', 'aptly-cli file_list' c.option '--directory DIRECTORY', String, 'Directory to list packages on server' c.action do |args, options| aptly_command = AptlyCli::AptlyFile.new if options.directory puts aptly_command.file_get(options.directory) else puts aptly_command.file_dir() end end end command :file_upload do |c| c.syntax = 'aptly-cli file_upload [options]' c.summary = 'Parameter --directory is upload directory name. Directory would be created if it doesn’t exist.' c.description = 'File upload' c.example 'description', 'aptly-cli file_upload --upload /local/copy/of/package.deb --directory /aptlyserver_directory/' c.option '--directory DIRECTORY', String, 'Directory to load packages into' c.option '--upload UPLOAD', String, 'Package(s) to upload' c.action do |args, options| aptly_command = AptlyCli::AptlyFile.new puts aptly_command.file_post(:file_uri => options.directory, :package => options.upload, :local_file => options.upload) end end command :file_delete do |c| c.syntax = 'aptly-cli file_delete [options]' c.summary = 'Deletes all files in upload directory and directory itself. Or delete just a file' c.description = 'File delete' c.example 'Delete package redis-server found in redis upload directory', 'aptly-cli file_delete --target /redis/redis-server_2.8.3_i386-cc1.deb' c.option '--target TARGET', String, 'Path to directory or specific package to delete' c.action do |args, options| aptly_command = AptlyCli::AptlyFile.new puts aptly_command.file_delete(options.target) end end command :repo_create do |c| c.syntax = 'aptly-cli repo_create [options]' c.summary = 'Create a new repository, requires --name' c.description = 'Create a new repository, requires --name' c.example 'create repo', 'aptly-cli repo_create --name meagasoftware' c.example 'creat repo with distribution set to "trusty"', 'aptly-cli repo_create --name megatronsoftware --default_distribution trusty' c.option '--name NAME', String, 'Local repository name, required' c.option '--comment COMMENT', String, 'Text describing local repository for the user' c.option '--default_distribution DISTRIBUTION', String, 'Default distribution when publishing from this local repo' c.option '--default_component COMPONENT', String, 'Default component when publishing from this local repo' c.action do |args, options| puts options.name aptly_command = AptlyCli::AptlyRepo.new repo_options = { :name => options.name.to_s, :comment => options.comment.to_s, :DefaultDistribution => options.default_distribution.to_s, :DefaultComponent => options.default_component.to_s } puts aptly_command.repo_create(repo_options) end end command :repo_delete do |c| c.syntax = 'aptly-cli repo_delete [options]' c.summary = 'Delete a local repository, requires --name' c.description = 'Delete a local repository, requires --name' c.example 'description', 'aptly-cli repo_delete --name megatronsoftware' c.option '--name NAME', String, 'Local repository name, required' c.option '--force' c.action do |args, options| aptly_command = AptlyCli::AptlyRepo.new repo_options = { :name => options.name.to_s, :force => options.force.to_s } puts aptly_command.repo_delete(repo_options) end end command :repo_edit do |c| c.syntax = 'aptly-cli repo_edit [options]' c.summary = 'Edit a local repository metadata, requires --name' c.description = 'Edit a local repository metadata, requires --name' c.example 'Change default distribution', 'aptly-cli repo_edit --name megatronsoftware --default_distribution trusty' c.option '--name NAME', String, 'Local repository name, required' c.option '--comment COMMENT', String, 'Edit repository comment' c.option '--default_distribution DISTRIBUTION', String, 'Edit DefaultDistribution for repo' c.option '--default_component COMPONENT', String, 'Edit DefaultComponent for repo' c.action do |args, options| aptly_command = AptlyCli::AptlyRepo.new if options.default_distribution repo_options = { :DefaultDistribution => options.default_distribution.to_s } end if options.default_component repo_options = { :DefaultComponent => options.default_component.to_s } end if options.comment repo_options = { :Comment => options.comment.to_s } end puts aptly_command.repo_edit(options.name.to_s, repo_options) end end command :repo_list do |c| c.syntax = 'aptly-cli repo_list [options]' c.summary = 'Show list of currently available local repositories' c.description = 'Show list of currently available local repositories' c.example 'description', 'aptly-cli repo_list' c.action do |args, options| aptly_command = AptlyCli::AptlyRepo.new puts aptly_command.repo_list() end end command :repo_package_query do |c| c.syntax = 'aptly-cli repo_package_query [options]' c.summary = 'List all packages in local repository or perform search on repository contents and return result., requires --name' c.description = 'List all packages or search on repo contents, requires --name' c.example 'description', 'aptly-cli repo_package_query --name megatronsoftware -query geoipupdate' c.option '--name NAME', String, 'Local repository name, required' c.option '--query QUERY', String, 'Package to query' c.option '--with_deps', 'Return results with dependencies' c.option '--format FORMAT', String, 'Format type to return, compact by default. "details" is an option' c.action do |args, options| aptly_command = AptlyCli::AptlyRepo.new if options.query repo_options = { :name => options.name.to_s, :query => options.query.to_s } elsif options.with_deps and options.query.nil? repo_options = { :name => options.name.to_s, :with_deps => options.with_deps.to_s } elsif options.format and options.query.nil? repo_options = { :name => options.name.to_s, :format => options.format.to_s } else repo_options = { :name => options.name.to_s } end puts aptly_command.repo_package_query(repo_options) end end command :repo_upload do |c| c.syntax = 'aptly-cli repo_upload [options]' c.summary = 'Import packages from files (uploaded using File Upload API) to the local repository. If directory specified, aptly would discover package files automatically. Adding same package to local repository is not an error. By default aptly would try to remove every successfully processed file and directory :dir (if it becomes empty after import).' c.description = 'Import packages from files' c.example 'description', 'aptly-cli repo_upload --name rocksoftware --dir rockpackages --noremove' c.option '--name NAME', String, 'Local repository name, required' c.option '--dir DIR', String, 'Directory where packages are stored via File API' c.option '--file FILE', String, 'Specific file to upload, if not provided the entire directory of files will be uploaded' c.option '--noremove', 'Flag to not remove any files that were uploaded via File API after repo upload' c.option '--forcereplace', 'flag to replace file(s) already in the repo' c.action do |args, options| aptly_command = AptlyCli::AptlyRepo.new puts aptly_command.repo_upload({ :name => options.name, :dir => options.dir, :file => options.file, :noremove => options.noremove, :forcereplace => options.forcereplace }) end end command :repo_show do |c| c.syntax = 'aptly-cli repo_show [options]' c.summary = 'Returns basic information about local repository' c.description = 'Returns basic information about local repository, require --name' c.example 'description', 'aptly-cli repo_show --name megatronsoftware' c.option '--name NAME', String, 'Local repository name, required' c.action do |args, options| aptly_command = AptlyCli::AptlyRepo.new puts aptly_command.repo_show(options.name) end end command :publish_drop do |c| c.syntax = 'aptly-cli publish_drop [options]' c.summary = 'Delete published repository, clean up files in published directory.' c.description = 'Delete published repository' c.example 'Delete publish repository prefix precisetest', 'aptly-cli publish_drop --distribution precisetest' c.option '--prefix PREFIX', String, 'prefix, optional' c.option '--distribution DISTRIBUTION', String, 'distribution' c.option '--force', 'force published repository removal even if component cleanup fails' c.action do |args, options| aptly_command = AptlyCli::AptlyPublish.new puts aptly_command.publish_drop({ :prefix => options.prefix, :distribution => options.distribution, :force => options.force }) end end command :publish_list do |c| c.syntax = 'aptly-cli publish_list [options]' c.summary = 'List published repositories.' c.description = 'List published repositories.' c.example 'List published repositories', 'aptly-cli publish_list' c.action do |args, options| aptly_command = AptlyCli::AptlyPublish.new puts aptly_command.publish_list() end end command :publish_repo do |c| c.syntax = 'aptly-cli publish_repo [options]' c.summary = 'Publish local repository or snapshot under specified prefix. Storage might be passed in prefix as well, e.g. s3:packages/. To supply empty prefix, just remove last part (POST /api/publish/:prefix/<:repos>or<:snapshots>' c.description = 'Publish local repository or snapshot under specified prefix' c.example 'publish multiple repos as source', 'aptly-cli publish_repo --sourcekind local --name precise/megatronsoftware,trusty/rocksoftware22 --architectures i386 amd64' c.example 'publish one repo, two archs, forceoverwrite', 'aptly-cli publish_repo --sourcekind local --name megatronsoftware --architectures i386 amd64 --forceoverwrite true' c.example 'publish 2 snapshots into one publish point', 'aptly-cli publish_repo --sourcekind snapshot --name precise/rocksoftware300,main/rocksoftware200 --label test_snap' c.example 'description', 'aptly-cli publish_repo --sourcekind snapshot --name precise/rocksoftware300 --origin testorigin' c.example 'publish repo with signing keyring', 'aptly-cli publish_repo --sourcekind snapshot --name precise/rocksoftware300 --origin testorigin --gpg_keyring /etc/apt/trustdb.gpg' c.option '--name NAME', Array, 'Local repository name with optional component, required' c.option '--sourcekind SOURCEKIND', String, 'Local for local repositories and snapshot for snapshots, required' c.option '--prefix PREFIX', String, 'prefix' c.option '--distribution DISTRIBUTION', String, 'Distribution name, if missing aptly would try to guess from sources' c.option '--label LABEL', String, 'value of Label: field in published repository stanza' c.option '--origin ORIGIN', String, 'value of Origin: field in published repository stanza' c.option '--forceoverwrite', 'when publishing, overwrite files in pool/ directory without notice' c.option '--architectures ARCHITECTURES', Array, 'override list of published architectures' c.option '--gpg_skip', 'Don’t sign published repository' c.option '--gpg_batch', 'should be set if passing passphrase' c.option '--gpg_key GPGKEY', String, 'gpg key name (local to aptly server/user)' c.option '--gpg_keyring GPGKEYRING', String, 'gpg keyring filename (local to aptly server/user)' c.option '--gpg_secret_keyring GPGSECRET', String, 'gpg secret keyring filename (local to aptly server/user)' c.option '--gpg_passphrase GPGPASS', String, 'gpg key passphrase (if using over http, would be transmitted in clear text!)' c.option '--gpg_passphrase_file GPGPASSFILE', String, 'gpg passphrase file (local to aptly server/user)' c.action do |args, options| aptly_command = AptlyCli::AptlyPublish.new puts aptly_command.publish_repo(options.name, { :sourcekind => options.sourcekind, :prefix => options.prefix, :label => options.label, :distribution => options.distribution, :origin => options.origin, :forceoverwrite => options.forceoverwrite, :architectures => options.architectures, :skip => options.gpg_skip, :batch => options.gpg_batch, :gpgKey => options.gpg_key, :keyring => options.gpg_keyring, :secretKeyring => options.gpg_secret_keyring, :passphrase => options.gpg_passphrase, :passphraseFile => options.gpg_passphrase_file }) end end command :publish_update do |c| c.syntax = 'aptly-cli publish_update [options]' c.summary = 'Update published repository. If local repository has been published, published repository would be updated to match local repository contents. If snapshots have been been published, it is possible to switch each component to new snapshot' c.description = 'Update published repository' c.example 'description', 'aptly-cli publish_update --forceoverwrite --distribution precise' c.option '--prefix PREFIX', String, 'Publishing prefix, default root' c.option '--distribution DISTRIBUTION', String, 'Distribution name' c.option '--snapshots SNAPSHOTS', String, 'When updating published snapshots, list of objects component/name seperated by space' c.option '--forceoverwrite', 'When publishing, overwrite files in pool/ directory without notice' c.option '--gpg_skip', 'Don’t sign published repository' c.option '--gpg_batch', 'should be set if passing passphrase' c.option '--gpg_key GPGKEY', String, 'gpg key name (local to aptly server/user)' c.option '--gpg_keyring GPGKEYRING', String, 'gpg keyring filename (local to aptly server/user)' c.option '--gpg_secret_keyring GPGSECRET', String, 'gpg secret keyring filename (local to aptly server/user)' c.option '--gpg_passphrase GPGPASS', String, 'gpg key passphrase (if using over http, would be transmitted in clear text!)' c.option '--gpg_passphrase_file GPGPASSFILE', String, 'gpg passphrase file (local to aptly server/user)' c.action do |args, options| aptly_command = AptlyCli::AptlyPublish.new puts aptly_command.publish_update({ :prefix => options.prefix, :distribution => options.distribution, :forceoverwrite => options.forceoverwrite, :skip => options.gpg_skip, :batch => options.gpg_batch, :gpgKey => options.gpg_key, :keyring => options.gpg_keyring, :secretKeyring => options.gpg_secret_keyring, :passphrase => options.gpg_passphrase, :passphraseFile => options.gpg_passphrase_file, :snapshots => options.snapshots}) end end command :snapshot_create do |c| c.syntax = 'aptly-cli snapshot_create [options]' c.summary = 'Create snapshot of current local repository :name contents as new snapshot with name :snapname' c.description = 'Create snapshot, require --name' c.example 'Creating new snapshot megasoftware22-snap from megasoftware22 repo', 'aptly-cli snapshot_create --name megasoftware22-snap --repo meagsoftware22' c.option '--name NAME', String, 'Name of new snapshot, required' c.option '--repo REPO', String, 'Name of repo to snapshot' c.option '--description DESCRIPTION', String, 'Set description for snapshot' c.action do |args, options| aptly_command = AptlyCli::AptlySnapshot.new puts aptly_command.snapshot_create(options.name, options.repo, options.description) end end command :snapshot_delete do |c| c.syntax = 'aptly-cli snapshot_delete [options]' c.summary = 'Delete snapshot. Snapshot can’t be deleted if it is published. aptly would refuse to delete snapshot if it has been used as source to create other snapshots, but that could be overridden with force parameter' c.description = 'Delete snapshot, require --name' c.example 'Deleting the snapshot megasoftware22', 'aptly-cli snapshot_delete --name megatronsoftware22' c.example 'Deleting the snapshot megasoftware22 with force option', 'aptly-cli snapshot_delete --name megatronsoftware22 --force' c.option '--name NAME', String, 'Local snapshot name, required' c.option '--force', 'Force' c.action do |args, options| aptly_command = AptlyCli::AptlySnapshot.new puts aptly_command.snapshot_delete(options.name, options.force) end end command :snapshot_diff do |c| c.syntax = 'aptly-cli snapshot_diff [options]' c.summary = 'Calculate difference between two snapshots --name (left) and --withsnapshot (right).' c.description = 'Calculate difference between two snapshots, require --name, require --withsnapshot' c.example 'Show difference between megatronsoftware and rocksoftware snapshots', 'aptly-cli snapshot_diff --name megatronsoftware --withsnapshot rocksoftware' c.option '--name NAME', String, 'Local snapshot name (left)' c.option '--withsnapshot WITHSNAPSHOT', String, 'Snapshot to diff against (right)' c.action do |args, options| aptly_command = AptlyCli::AptlySnapshot.new puts aptly_command.snapshot_diff(options.name, options.withsnapshot) end end command :snapshot_list do |c| c.syntax = 'aptly-cli snapshot_list [options]' c.summary = 'Return list of all snapshots created in the system' c.description = 'Return list of all snapshots created in the system' c.example 'Return list of all snapshots created in the system', 'aptly-cli snapshot_list' c.example 'Return list sorted by time', 'aptly-cli snapshot_list --sort time' c.option '--sort', String, 'Set sort by' c.action do |args, options| aptly_command = AptlyCli::AptlySnapshot.new puts aptly_command.snapshot_list(options.sort) end end command :snapshot_search do |c| c.syntax = 'aptly-cli snapshot_search [options]' c.summary = 'List all packages in snapshot or perform search on snapshot contents and return result' c.description = 'List all packages in snapshot or perform search' c.example 'List all packages in snapshot megasoftware22-snap', 'aptly-cli snapshot_search --name megasoftware22-snap' c.example 'List all packages in snapshot megasoftware22-snap with format set to details', 'aptly-cli snapshot_search --name megasoftware22-snap --format details' c.example 'Search for package called nginx in snapshot megasoftware22-snap', 'aptly-cli snapshot_search --name megasoftware22-snap --query nginx' c.option '--name NAME', String, 'Name of snapshot to search, required' c.option '--query QUERY', String, 'Specific package to query' c.option '--withdeps', 'Include package dependencies' c.option '--format FORMAT', String, 'Format the respone of the snapshot search results, compact by default.' c.action do |args, options| aptly_command = AptlyCli::AptlySnapshot.new puts aptly_command.snapshot_search(options.name, { :query => options.query, :format => options.format, :withdeps => options.withdeps }) end end command :snapshot_show do |c| c.syntax = 'aptly-cli snapshot_show [options]' c.summary = 'Get information about snapshot by name' c.description = 'Get information about snapshot by name., require --name' c.example 'Show snapshot information for repo named megatronsoftware', 'aptly-cli snapshot_show --name megatronsoftware' c.option '--name NAME', String, 'Local snapshot name, required' c.action do |args, options| aptly_command = AptlyCli::AptlySnapshot.new puts aptly_command.snapshot_show(options.name) end end command :snapshot_update do |c| c.syntax = 'aptly-cli snapshot_update [options]' c.summary = 'Update snapshot’s description or name' c.description = 'Update snapshot’s description or name, require --name' c.example 'Updating the snapshot megasoftware22 to a new name', 'aptly-cli snapshot_update --name megasoftware22 --new_name meagsoftware12-12-13' c.option '--name NAME', String, 'Local snapshot name, required' c.option '--new_name NEWNAME', String, 'New name for the snapshot' c.option '--description DESCRIPTION', String, 'Update description for snapshot' c.action do |args, options| aptly_command = AptlyCli::AptlySnapshot.new puts aptly_command.snapshot_update(options.name, options.new_name, options.description) end end command :graph do |c| c.syntax = 'aptly-cli graph [options]' c.summary = 'Download a graph of repository layout. Current options are "svg" and "png"' c.description = 'Download an svg or png graph of repository layout' c.example 'description', 'aptly-cli graph png > ~/repo_graph.png' c.option '--type GRAPH_TYPE', String, 'Type of graph to download, present options are png or svg' c.action do |args, options| aptly_command = AptlyCli::AptlyMisc.new puts aptly_command.get_graph(options.type) end end command :version do |c| c.syntax = 'aptly-cli version' c.description = 'Display aptly server version' c.example 'description', 'aptly-cli version' c.action do |args, options| aptly_command = AptlyCli::AptlyMisc.new puts aptly_command.get_version() end end