]> cat aescling's git repositories - mastodon.git/blob - lib/cli.rb
Add explanation to mute dialog, refactor and clean up mute/block UI (#11992)
[mastodon.git] / lib / cli.rb
1 # frozen_string_literal: true
2
3 require 'thor'
4 require_relative 'mastodon/media_cli'
5 require_relative 'mastodon/emoji_cli'
6 require_relative 'mastodon/accounts_cli'
7 require_relative 'mastodon/feeds_cli'
8 require_relative 'mastodon/search_cli'
9 require_relative 'mastodon/settings_cli'
10 require_relative 'mastodon/statuses_cli'
11 require_relative 'mastodon/domains_cli'
12 require_relative 'mastodon/preview_cards_cli'
13 require_relative 'mastodon/cache_cli'
14 require_relative 'mastodon/version'
15
16 module Mastodon
17 class CLI < Thor
18 def self.exit_on_failure?
19 true
20 end
21
22 desc 'media SUBCOMMAND ...ARGS', 'Manage media files'
23 subcommand 'media', Mastodon::MediaCLI
24
25 desc 'emoji SUBCOMMAND ...ARGS', 'Manage custom emoji'
26 subcommand 'emoji', Mastodon::EmojiCLI
27
28 desc 'accounts SUBCOMMAND ...ARGS', 'Manage accounts'
29 subcommand 'accounts', Mastodon::AccountsCLI
30
31 desc 'feeds SUBCOMMAND ...ARGS', 'Manage feeds'
32 subcommand 'feeds', Mastodon::FeedsCLI
33
34 desc 'search SUBCOMMAND ...ARGS', 'Manage the search engine'
35 subcommand 'search', Mastodon::SearchCLI
36
37 desc 'settings SUBCOMMAND ...ARGS', 'Manage dynamic settings'
38 subcommand 'settings', Mastodon::SettingsCLI
39
40 desc 'statuses SUBCOMMAND ...ARGS', 'Manage statuses'
41 subcommand 'statuses', Mastodon::StatusesCLI
42
43 desc 'domains SUBCOMMAND ...ARGS', 'Manage account domains'
44 subcommand 'domains', Mastodon::DomainsCLI
45
46 desc 'preview_cards SUBCOMMAND ...ARGS', 'Manage preview cards'
47 subcommand 'preview_cards', Mastodon::PreviewCardsCLI
48
49 desc 'cache SUBCOMMAND ...ARGS', 'Manage cache'
50 subcommand 'cache', Mastodon::CacheCLI
51
52 option :dry_run, type: :boolean
53 desc 'self-destruct', 'Erase the server from the federation'
54 long_desc <<~LONG_DESC
55 Erase the server from the federation by broadcasting account delete
56 activities to all known other servers. This allows a "clean exit" from
57 running a Mastodon server, as it leaves next to no cache behind on
58 other servers.
59
60 This command is always interactive and requires confirmation twice.
61
62 No local data is actually deleted, because emptying the
63 database or removing files is much faster through other, external
64 means, such as e.g. deleting the entire VPS. However, because other
65 servers will delete data about local users, but no local data will be
66 updated (such as e.g. followers), there will be a state mismatch
67 that will lead to glitches and issues if you then continue to run and use
68 the server.
69
70 So either you know exactly what you are doing, or you are starting
71 from a blank slate afterwards by manually clearing out all the local
72 data!
73 LONG_DESC
74 def self_destruct
75 require 'tty-prompt'
76
77 prompt = TTY::Prompt.new
78
79 exit(1) unless prompt.ask('Type in the domain of the server to confirm:', required: true) == Rails.configuration.x.local_domain
80
81 prompt.warn('This operation WILL NOT be reversible. It can also take a long time.')
82 prompt.warn('While the data won\'t be erased locally, the server will be in a BROKEN STATE afterwards.')
83 prompt.warn('A running Sidekiq process is required. Do not shut it down until queues clear.')
84
85 exit(1) if prompt.no?('Are you sure you want to proceed?')
86
87 inboxes = Account.inboxes
88 processed = 0
89 dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
90
91 if inboxes.empty?
92 prompt.ok('It seems like your server has not federated with anything')
93 prompt.ok('You can shut it down and delete it any time')
94 return
95 end
96
97 prompt.warn('Do NOT interrupt this process...')
98
99 Account.local.without_suspended.find_each do |account|
100 payload = ActiveModelSerializers::SerializableResource.new(
101 account,
102 serializer: ActivityPub::DeleteActorSerializer,
103 adapter: ActivityPub::Adapter
104 ).as_json
105
106 json = Oj.dump(ActivityPub::LinkedDataSignature.new(payload).sign!(account))
107
108 unless options[:dry_run]
109 ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
110 [json, account.id, inbox_url]
111 end
112
113 account.suspend!
114 end
115
116 processed += 1
117 end
118
119 prompt.ok("Queued #{inboxes.size * processed} items into Sidekiq for #{processed} accounts#{dry_run}")
120 prompt.ok('Wait until Sidekiq processes all items, then you can shut everything down and delete the data')
121 rescue TTY::Reader::InputInterrupt
122 exit(1)
123 end
124
125 map %w(--version -v) => :version
126
127 desc 'version', 'Show version'
128 def version
129 say(Mastodon::Version.to_s)
130 end
131 end
132 end
This page took 0.101404 seconds and 4 git commands to generate.