A variety of simple automation scripts and enhancements to Sway and i3.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

195 行
5.8KB

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use IO::Prompter;
  5. use File::Which qw( which );
  6. # Configurable variables
  7. my $lang = 'en-CA';
  8. my $install = "$ENV{HOME}/.local/bin";
  9. my $working = "/tmp/firefox.new";
  10. # Download link as provided by https://www.mozilla.org/$lang/firefox/developer/
  11. my $url = 'https://download.mozilla.org/?product=firefox-devedition-latest-ssl'
  12. . '&os=linux64&lang='.$lang;
  13. # Ensure that we can unzip
  14. unless (which("bunzip2")) {
  15. die "Requires bunzip2. Try:\n"
  16. . "sudo apt install zutils or your distro's equivalent\n";
  17. }
  18. # Only understood argument is to not bother verifying the package
  19. my ($download_key, $verify) = (0,1);
  20. if (defined $ARGV[0]) {
  21. if ($ARGV[0] eq '--no-verify') {
  22. $verify = 0;
  23. } else {
  24. die "Didn't understand argument $ARGV[0]\n";
  25. }
  26. }
  27. # If verification is to be done, make sure we have the key
  28. unless ($verify) {
  29. print "Checking for Mozilla GPG key in keyring...\n";
  30. system("gpg --list-keys release\@mozillla.com 2>&1 > /dev/null");
  31. if ($?) {
  32. my $YN = prompt (-in => *STDIN, "You don't currently have "
  33. . "Mozilla's GPG key in your keyring.\n"
  34. . "Would you like to install it? If not, installation "
  35. . "will not be verified. [y/N]: ",
  36. -single
  37. );
  38. if ($YN eq 'y' || $YN eq 'Y') {
  39. $download_key = 1;
  40. } else {
  41. $verify = 0;
  42. }
  43. }
  44. }
  45. # If a previous download still exists remove it
  46. if ( -e $working ) {
  47. system("rm -rf $working");
  48. if ($?) {
  49. die "Working directory "
  50. . $working
  51. . "already exists and failed to remove: $!\n";
  52. }
  53. }
  54. # Get version currently installed
  55. my $current = `$install/firefox/firefox-bin --version`;
  56. $current =~ s/.*\s([^\s])/$1/;
  57. chomp $current;
  58. use WWW::Mechanize;
  59. my $mech = WWW::Mechanize->new();
  60. # $url is actually going to redirect to the proper current dowload so just get
  61. # the redirect.
  62. my $head = $mech->head($url);
  63. my ($location, $version);
  64. # This redirect will have the version id, so we can use that to determine if a
  65. # new version actually exists
  66. if ($head->{'_msg'}) {
  67. $version = $location = $head->{'_previous'}->{'_headers'}->{'location'};
  68. $version =~ s/^.*\-([^\-]*)\.tar\.bz2$/$1/;
  69. if ($version eq $current) {
  70. die "Current ($current) is the same as New ($version)\n";
  71. }
  72. } else {
  73. print "unable to find new download\n";
  74. }
  75. mkdir($working) || die "Couldn't make $working: $!\n";
  76. # Download package
  77. print "Fetching package $location...\n";
  78. $mech->get($location);
  79. $mech->save_content( $working."/firefox-".$version.".tar.bz2",
  80. binmode => ':raw',
  81. decoded_by_headers => 1
  82. );
  83. # If verification is required, get signature as well
  84. if ($verify) {
  85. $location .= '.asc';
  86. print "Fetching GPG signature $location...\n";
  87. $mech->get($location);
  88. $mech->save_content( $working."/firefox-".$version.".tar.bz2.asc",
  89. binmode => ':raw',
  90. decoded_by_headers => 1
  91. );
  92. }
  93. # If key still needs to be fetched, get it
  94. if ($download_key) {
  95. $location =~ s/linux-x86_64.*$/KEY/;
  96. print "Fetching GPG key $location...\n";
  97. $mech->get($location);
  98. $mech->save_content( $working."/mozilla.pgp",
  99. binmode => ':raw',
  100. decoded_by_headers => 1
  101. );
  102. # And install it
  103. print "Installing Mozilla GPG key in keyring...\n";
  104. system("gpg --import $working/mozilla.pgp 2>&1 > /dev/null");
  105. if ($?) {
  106. die "Warning: failed to import key. Cannot verify integrity.\n"
  107. . "Downloaded to "
  108. . $working
  109. . ". You can check and install it to "
  110. . $install
  111. . "manually: "
  112. . $!
  113. . "\n";
  114. }
  115. unlink("$working/mozilla.pgp");
  116. }
  117. # Verify the package
  118. if ($verify) {
  119. print "Verifying download with Mozilla GPG key...\n";
  120. system("gpg --verify $working/firefox-$version.tar.bz2.asc");
  121. if ($?) {
  122. die "Warning: failed to verify download. Signing failed.\n"
  123. . "Downloaded to "
  124. . $working
  125. . ". You can check and install it to "
  126. . $install
  127. . " manually: "
  128. . $!
  129. . "\n";
  130. }
  131. }
  132. # Uncompress
  133. print "Uncompressing download with bunzip2...\n";
  134. system("bunzip2 $working/firefox-$version.tar.bz2");
  135. if ($?) {
  136. die "Failed to uncompress: $!\n";
  137. }
  138. # Extract
  139. print "Extracting from TAR archive...\n";
  140. system("tar -xf $working/firefox-$version.tar -C $working");
  141. if ($?) {
  142. die "Failed to extract: $!\n";
  143. }
  144. # Bin the old backup
  145. if (-e "$install/.firefox.old") {
  146. print "Removing previous backup folder...\n";
  147. system("rm -rf $install/.firefox.old");
  148. if ($?) {
  149. die "Failed to remove: $!\n";
  150. }
  151. }
  152. # Move current to old
  153. print "Backing up currently installed version ("
  154. . $current
  155. . ") to "
  156. . $install
  157. . "/.firefox.old...\n";
  158. system("mv $install/firefox $install/.firefox.old");
  159. if ($?) {
  160. die "Failed to move: $!\n";
  161. }
  162. # Move new to current
  163. print "Moving new version to $install for final installation...\n";
  164. system("mv $working/firefox $install/");
  165. if ($?) {
  166. die "Failed to move: $!\n";
  167. }
  168. # Hurray!
  169. print "Installation of version "
  170. . $version
  171. . " complete. You should restart firefox whenever it is convenient.\n";
  172. exit();