nice mod for sudo in snarf linux config
[feisty_meow.git] / scripts / archival / snarf_linux_config.pl
1 #!/usr/bin/perl
2
3 ##############
4 #  Name   : snarf_linux_config
5 #  Author : Chris Koeritz
6 #  Rights : Copyright (C) 1996-$now by Author
7 #  Purpose:
8 #    Backs up the useful linux config files and names the file after the
9 #  host it's run on.
10 ##############
11 #  This program is free software; you can redistribute it and/or modify it
12 #  under the terms of the GNU General Public License as published by the Free
13 #  Software Foundation; either version 2 of the License or (at your option)
14 #  any later version.  See: "http://www.gruntose.com/Info/GNU/GPL.html" for a
15 #  version of the License.  Please send any updates to "fred@gruntose.com".
16 ##############
17
18 require "shared_snarfer.pl";
19
20 use Env qw(HOME);
21
22 # make sure we are running as root.  otherwise we have no access to look at many things in /etc.
23 if ($< != 0) {
24   printf "This script must be run as root or sudo.  Try this:\n";
25   printf "  sudo -E PERLLIB=\$PERLLIB perl $0 @ARGV\n";
26   exit 1;
27 }
28
29 &initialize_snarfer;
30
31 # get the number we use and increment it for the next use.
32 local($number) = &retrieve_number("aa_backup");
33
34 # variables used throughout.
35 local($snarf_file_base) = snarf_prefix("config-linux");
36 local($snarf_file) = &snarf_name($snarf_file_base, $number);
37
38 # store the current archive number in the file for retrieval on the
39 # other side.
40 &backup_number("aa_backup", $snarf_file_base, $number);
41
42 # write a little file showing the disk status.
43 local($infofile) = $HOME . "/disk_info.txt";
44 unlink $infofile;
45 open(INF, ">>" . $infofile);
46 print INF "Current mount configuration:\n";
47 print INF "\n";
48 close(INF);
49 system("mount >>$infofile");
50 open(INF, ">>" . $infofile);
51 print INF "\n";
52 print INF "\n";
53 print INF "Current disk configuration:\n";
54 print INF "\n";
55 close(INF);
56 system("fdisk -l >>$HOME/disk_info.txt");
57 &backup_files($snarf_file_base, $number, $HOME, ".", ("disk_info.txt"));
58 unlink $infofile;
59
60 # backup the dpkg info.
61 &backup_files($snarf_file_base, $number, "/", "var/lib/dpkg", ("status*"));
62
63 # backup the crucial hierarchies in /var...
64 #gone: &backup_hierarchy($snarf_file_base, $number, "/", "var/named");
65 #gone: &backup_hierarchy($snarf_file_base, $number, "/", "var/lib/named/master");
66
67 ###not good: &backup_hierarchy($snarf_file_base, $number, "/", "var/lib/mysql");
68 ###the mysql snarf is not necessarily usable, since we really should be
69 ###backing up the databases by another means than this.
70
71 &backup_hierarchy($snarf_file_base, $number, "/", "var/lib/webalizer");
72
73 # snag the grub bootloader files.
74 &backup_hierarchy($snarf_file_base, $number, "/", "boot/grub");
75
76 # now get the entire /etc hierarchy...
77 &backup_hierarchy($snarf_file_base, $number, "/", "etc");
78
79 # suck in the current state for the resolver.
80 &backup_hierarchy($snarf_file_base, $number, "/", "run/resolvconf");
81
82 # clean out extra files.
83 &remove_from_backup($snarf_file_base, $number, "etc/cups/ppds.dat*");
84 &remove_from_backup($snarf_file_base, $number, "etc/httpd/conf/ssl.crt/ca-bundle.crt");
85 &remove_from_backup($snarf_file_base, $number, "etc/locale");
86 &remove_from_backup($snarf_file_base, $number, "etc/alternatives");
87 &remove_from_backup($snarf_file_base, $number, "etc/opt/kde3/share/services/ksycoca");
88 &remove_from_backup($snarf_file_base, $number, "etc/preload.d");
89 &remove_from_backup($snarf_file_base, $number, "etc/rmt");
90 &remove_from_backup($snarf_file_base, $number, "etc/termcap");
91 &remove_from_backup($snarf_file_base, $number, "etc/X11/X");
92 &remove_from_backup($snarf_file_base, $number, "etc/X11/xkb");
93 &remove_from_backup($snarf_file_base, $number, "*.bak");
94 &remove_from_backup($snarf_file_base, $number, "*.cache");
95 &remove_from_backup($snarf_file_base, $number, "*.crt");
96 &remove_from_backup($snarf_file_base, $number, "*.old");
97 &remove_from_backup($snarf_file_base, $number, "*.schemas");
98 &remove_from_backup($snarf_file_base, $number, "*.so");
99 &remove_from_backup($snarf_file_base, $number, "*.xml");
100
101 # now rename the file so only the unpacker can access it.
102 &rename_archive($snarf_file);
103
104 exit 0;
105