Skip to content

Commit 127cff1

Browse files
nsheapsclaude
andauthored
Add 1Password formula wrappers for macOS and Linux (#124)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 74832d2 commit 127cff1

7 files changed

Lines changed: 187 additions & 1 deletion

File tree

.config/cspell/project.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,13 @@ wtype
6363
dotool
6464
appimage
6565

66+
# 1Password / APT terms
67+
onepassword
68+
dearmor
69+
debsig
70+
keyrings
71+
sourcelist
72+
sourceparts
73+
6674
# Config terms
6775
keytype

.rubocop.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ Layout/LineLength:
99
AllowedPatterns:
1010
- "# renovate: .*"
1111

12+
Layout/ArgumentAlignment:
13+
EnforcedStyle: with_fixed_indentation
14+
15+
Layout/MultilineMethodCallIndentation:
16+
EnforcedStyle: indented
17+
18+
Layout/MultilineOperationIndentation:
19+
EnforcedStyle: indented
20+
21+
Layout/LineEndStringConcatenationIndentation:
22+
EnforcedStyle: indented
23+
1224
Naming/FileName:
1325
Enabled: false
1426

Aliases/1password

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Casks/onepassword.rb

Aliases/1password-cli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Formula/onepassword-cli.rb

Casks/onepassword.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
cask 'onepassword' do
2+
name '1Password'
3+
desc '1Password desktop application'
4+
homepage 'https://1password.com'
5+
url 'https://github.com/nsheaps/brew-meta-formula/archive/refs/tags/v1.0.0.tar.gz'
6+
sha256 'b14702dd54ea5c48d2ebeb6425015c14794159a6b9d342178c81d2f2e79ed2db'
7+
version '1.0.0'
8+
9+
# macOS: 1Password recommends downloading from 1password.com, which is
10+
# exactly what the upstream Homebrew cask automates.
11+
on_macos do
12+
depends_on macos: '>= :monterey'
13+
depends_on cask: '1password'
14+
end
15+
16+
# Linux: 1Password recommends installing via their APT repository.
17+
# The APT repo is set up by the onepassword-cli formula (shared repo),
18+
# so we depend on that and just install the desktop package.
19+
on_linux do
20+
depends_on formula: 'nsheaps/devsetup/onepassword-cli'
21+
22+
postflight do
23+
system_command '/usr/bin/sudo',
24+
args: [
25+
'apt-get', 'update',
26+
'-o', 'Dir::Etc::sourcelist=sources.list.d/1password.list',
27+
'-o', 'Dir::Etc::sourceparts=-',
28+
'-o', 'APT::Get::List-Cleanup=0'
29+
]
30+
system_command '/usr/bin/sudo',
31+
args: ['apt-get', 'install', '-y', '1password']
32+
end
33+
end
34+
35+
def install
36+
system 'touch', 'trick-brew-to-install-meta-formula'
37+
prefix.install 'trick-brew-to-install-meta-formula'
38+
end
39+
40+
def caveats
41+
if OS.mac?
42+
<<~CAVEAT
43+
1Password has been installed via the upstream Homebrew cask.
44+
Update with: brew upgrade --cask 1password
45+
CAVEAT
46+
else
47+
<<~CAVEAT
48+
1Password has been installed via the official 1Password APT repository.
49+
Update with: sudo apt-get update && sudo apt-get upgrade 1password
50+
CAVEAT
51+
end
52+
end
53+
end

Formula/onepassword-cli.rb

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
class OnepasswordCli < Formula
2+
desc '1Password CLI - command-line access to 1Password'
3+
homepage 'https://developer.1password.com/docs/cli/'
4+
url 'https://github.com/nsheaps/brew-meta-formula/archive/refs/tags/v1.0.0.tar.gz'
5+
sha256 'b14702dd54ea5c48d2ebeb6425015c14794159a6b9d342178c81d2f2e79ed2db'
6+
version '1.0.0'
7+
license :cannot_represent
8+
9+
livecheck do
10+
skip 'Upstream package manager handles updates (brew cask on macOS, apt on Linux)'
11+
end
12+
13+
def install
14+
system 'touch', 'trick-brew-to-install-meta-formula'
15+
prefix.install 'trick-brew-to-install-meta-formula'
16+
end
17+
18+
def post_install
19+
if OS.mac?
20+
install_macos_cask
21+
elsif OS.linux?
22+
install_linux_apt
23+
end
24+
end
25+
26+
def caveats
27+
if OS.mac?
28+
<<~CAVEAT
29+
1Password CLI has been installed as a Homebrew cask.
30+
Update with: brew upgrade --cask 1password-cli
31+
CAVEAT
32+
else
33+
<<~CAVEAT
34+
1Password CLI has been installed via the official 1Password APT repository.
35+
Update with: sudo apt-get update && sudo apt-get upgrade 1password-cli
36+
CAVEAT
37+
end
38+
end
39+
40+
private
41+
42+
def install_macos_cask
43+
return if system(HOMEBREW_BREW_FILE, 'list', '--cask', '1password-cli', err: :close, out: :close)
44+
45+
system HOMEBREW_BREW_FILE, 'install', '--cask', '1password-cli'
46+
end
47+
48+
def install_linux_apt
49+
setup_apt_repo
50+
apt_update_args = [
51+
'sudo', 'apt-get', 'update',
52+
'-o', 'Dir::Etc::sourcelist=sources.list.d/1password.list',
53+
'-o', 'Dir::Etc::sourceparts=-',
54+
'-o', 'APT::Get::List-Cleanup=0'
55+
]
56+
system(*apt_update_args)
57+
system 'sudo', 'apt-get', 'install', '-y', '1password-cli'
58+
end
59+
60+
def setup_apt_repo
61+
ohai 'Setting up 1Password APT repository...'
62+
arch = Hardware::CPU.arm? ? 'arm64' : 'amd64'
63+
install_apt_gpg_key
64+
install_apt_source(arch)
65+
install_debsig_policy
66+
end
67+
68+
def install_apt_gpg_key
69+
gpg_keyring = '/usr/share/keyrings/1password-archive-keyring.gpg'
70+
return if File.exist?(gpg_keyring)
71+
72+
gpg_cmd = 'curl -sS https://downloads.1password.com/linux/keys/1password.asc ' \
73+
"| sudo gpg --dearmor --output #{gpg_keyring}"
74+
system 'bash', '-c', gpg_cmd
75+
end
76+
77+
def install_apt_source(arch)
78+
gpg_keyring = '/usr/share/keyrings/1password-archive-keyring.gpg'
79+
sources_file = '/etc/apt/sources.list.d/1password.list'
80+
return if File.exist?(sources_file)
81+
82+
deb_line = "deb [arch=#{arch} signed-by=#{gpg_keyring}] " \
83+
"https://downloads.1password.com/linux/debian/#{arch} stable main"
84+
system 'bash', '-c', "echo '#{deb_line}' | sudo tee #{sources_file}"
85+
end
86+
87+
def install_debsig_policy
88+
install_debsig_policy_file
89+
install_debsig_keyring
90+
end
91+
92+
def install_debsig_policy_file
93+
policy_dir = '/etc/debsig/policies/AC2D62742012EA22'
94+
return if File.exist?("#{policy_dir}/1password.pol")
95+
96+
system 'sudo', 'mkdir', '-p', policy_dir
97+
pol_cmd = 'curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol ' \
98+
"| sudo tee #{policy_dir}/1password.pol"
99+
system 'bash', '-c', pol_cmd
100+
end
101+
102+
def install_debsig_keyring
103+
keyring_dir = '/usr/share/debsig/keyrings/AC2D62742012EA22'
104+
return if File.exist?("#{keyring_dir}/debsig.gpg")
105+
106+
system 'sudo', 'mkdir', '-p', keyring_dir
107+
debsig_cmd = 'curl -sS https://downloads.1password.com/linux/keys/1password.asc ' \
108+
"| sudo gpg --dearmor --output #{keyring_dir}/debsig.gpg"
109+
system 'bash', '-c', debsig_cmd
110+
end
111+
end

Formula/op-exec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class OpExec < Formula
1212
url 'https://github.com/nsheaps/op-exec.git', branch: 'main'
1313
end
1414

15-
depends_on '1password-cli'
15+
depends_on 'nsheaps/devsetup/onepassword-cli'
1616

1717
def install
1818
bin.install Dir['bin/*']

0 commit comments

Comments
 (0)