+#
+# Backup-related variables
+#
+
+$curr_time = time();
+$backupdir = "globus_backup_${curr_time}";
+$confbackupdir = "$backupdir/s1_conf";
+$transbackupdir = "$backupdir/s3_trans";
+
+#
+# We need to make sure it's okay to copy our setup files (if some files are already
+# present). If we do copy any files, we backup the old files so the user can (possibly)
+# reverse any damage.
+#
+
+sub test_dirs
+{
+ my $composite;
+
+ print "\nPreparatory: checking for existence of critical directories\n";
+
+ #
+ # Remember to put in check for /etc
+ #
+
+ #
+ # Test for /etc/ssh
+ #
+
+ $composite = $sysconfdir;
+ if ( ! -d "$composite" )
+ {
+ print "Could not find directory: '${composite}'.. creating.\n";
+ mkdir($composite, 16877);
+ # 16877 should be 755, or drwxr-xr-x
+ }
+
+ #
+ # Test for /etc/ssh/globus_backup_<curr>
+ #
+
+ $composite = "$sysconfdir/$backupdir";
+ if ( ! -d "${composite}" )
+ {
+ print "Could not find directory: '${composite}'.. creating.\n";
+ mkdir($composite, 16877);
+ }
+
+ #
+ # Test for /etc/ssh/globus_backup_<curr>/s1_conf
+ #
+
+ $composite = "$sysconfdir/$confbackupdir";
+ if ( ! -d "${composite}" )
+ {
+ print "Could not find directory: '${composite}'.. creating.\n";
+ mkdir($composite, 16877);
+ }
+
+ #
+ # Test for /etc/ssh/globus_backup_<curr>/s2_trans
+ #
+
+ $composite = "$sysconfdir/$transbackupdir";
+ if ( ! -d "${composite}" )
+ {
+ print "Could not find directory: '${composite}'.. creating.\n";
+ mkdir($composite, 16877);
+ }
+
+ return 0;
+}
+
+sub copy_setup_files
+{
+ my $response;
+
+ print "\nStage 1: Copying configuration files into '${sysconfdir}'..\n";
+
+ $response = "y";
+ if ( -e "${sysconfdir}/ssh_config" )
+ {
+ $response = query_boolean("${sysconfdir}/ssh_config already exists. Overwrite?", "n");
+ if ($response eq "y")
+ {
+ action("cp ${sysconfdir}/ssh_config ${sysconfdir}/${confbackupdir}/ssh_config");
+ }
+ }
+
+ if ($response eq "y")
+ {
+ action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
+ }
+
+ #
+ # Reset response for our new query
+ #
+
+ $response = "y";
+ if ( -e "${sysconfdir}/sshd_config" )
+ {
+ $response = query_boolean("${sysconfdir}/sshd_config already exists. Overwrite?", "n");
+ if ($response eq "y")
+ {
+ action("cp ${sysconfdir}/sshd_config ${sysconfdir}/${confbackupdir}/sshd_config");
+ }
+ }
+
+ if ($response eq "y")
+ {
+ action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
+ }
+
+ #
+ # Reset response for our new query
+ #
+
+ $response = "y";
+ if ( -e "${sysconfdir}/moduli" )
+ {
+ $response = query_boolean("${sysconfdir}/moduli already exists. Overwrite?", "n");
+ if ($response eq "y")
+ {
+ action("cp ${sysconfdir}/moduli ${sysconfdir}/${confbackupdir}/moduli");
+ }
+ }
+
+ if ($response eq "y")
+ {
+ action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli");
+ }
+}
+
+sub runkeygen
+{
+ print "\nStage 2: Generating ssh host keys..\n";
+
+ if ( ! -d "${sysconfdir}" )
+ {
+ print "Could not find ${sysconfdir} directory... creating\n";
+ mkdir($sysconfdir, 16877);
+ # 16877 should be 755, or drwxr-xr-x
+ }
+
+ if ( -e "${sysconfdir}/ssh_host_key" )
+ {
+ print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
+ }
+ else
+ {
+ # if $sysconfdir/ssh_host_key doesn't exist..
+ action("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
+ }
+
+ if ( -e "${sysconfdir}/ssh_host_dsa_key" )
+ {
+ print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n";
+ }
+ else
+ {
+ # if $sysconfdir/ssh_host_dsa_key doesn't exist..
+ action("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
+ }
+
+ if ( -e "${sysconfdir}/ssh_host_rsa_key" )
+ {
+ print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n";
+ }
+ else
+ {
+ # if $sysconfdir/ssh_host_rsa_key doesn't exist..
+ action("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
+ }
+
+ return 0;
+}
+