+#
+# Backup-related variables
+#
+
+$curr_time = time();
+$backupdir = "/etc/ssh/globus_backup_${curr_time}";
+
+#
+# Check that we are running as root
+#
+
+$uid = $>;
+
+if ($uid != 0)
+{
+ print "--> NOTE: You must be root to run this script! <--\n";
+ exit 0;
+}
+
+#
+# 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
+{
+ print "\nPreparatory: Checking for existence of critical directories..\n";
+
+ #
+ # Remember to put in check for /etc
+ #
+
+ #
+ # Test for /etc/ssh
+ #
+
+ if ( ! -d "$sysconfdir" )
+ {
+ print "Could not find directory: '${sysconfdir}'.. creating.\n";
+ mkdir($sysconfdir, 16877);
+ # 16877 should be 755, or drwxr-xr-x
+ }
+
+ #
+ # Test for /etc/ssh/globus_backup_<curr>
+ #
+
+ if ( ! -d "${backupdir}" )
+ {
+ print "Could not find directory: '${backupdir}'.. creating.\n";
+ mkdir($backupdir, 16877);
+ }
+
+ return 0;
+}
+
+sub backup_files
+{
+ print "\nStage 1: Backing up configuration files to '${backupdir}/'..\n";
+
+ if ( -e "${sysconfdir}/ssh_config" )
+ {
+ action("cp ${sysconfdir}/ssh_config ${backupdir}/ssh_config");
+ }
+ else
+ {
+ print "${sysconfdir}/ssh_config does not exist.\n";
+ }
+
+ if ( -e "${sysconfdir}/sshd_config" )
+ {
+ action("cp ${sysconfdir}/sshd_config ${backupdir}/sshd_config");
+ }
+ else
+ {
+ print "${sysconfdir}/sshd_config does not exist.\n";
+ }
+
+ if ( -e "${sysconfdir}/moduli" )
+ {
+ action("cp ${sysconfdir}/moduli ${backupdir}/moduli");
+ }
+ else
+ {
+ print "${sysconfdir}/moduli does not exist.\n";
+ }
+}
+
+sub copy_setup_files
+{
+ my $response;
+
+ print "\nStage 2: Copying configuration files into '${sysconfdir}'..\n";
+
+ action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
+ action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
+ action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli");
+}
+
+sub runkeygen
+{
+ print "\nStage 3: 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;
+}
+