summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/install-system106
-rwxr-xr-xscripts/system/vyatta_update_login.pl132
2 files changed, 194 insertions, 44 deletions
diff --git a/scripts/install-system b/scripts/install-system
index 8d52e11b..eb4c7bb3 100755
--- a/scripts/install-system
+++ b/scripts/install-system
@@ -221,34 +221,39 @@ select_partition () {
text=$2
echo -n "Looking for appropriate partitions: "
- progress_indicator start
+ progress_indicator start
# initialize out global var. using globals in this way is bad form. I know.
PARTITION=''
# list only the partitions in /proc/partitions.
parts=$(cat /proc/partitions | awk '{ if ($4!="name") { print $4 " "} }' | egrep "[0-9]" | egrep -v "loop" | tr -d '\n')
-
+
# Get the partition sizes for display
- # only show partitions that have sizes, i.e. remove loops
+ # only show linux partitions that have sizes, i.e. remove loops
display=''
for part in $parts
do
- lsize=$(get_drive_size $part)
- if [ "$lsize" -a $lsize -ge $minsize ]; then
- display="$display $part\t\t$lsize"MB"\n"
+ rootdev=$(echo $part | sed 's/[0-9]//g')
+ parttype=$(fdisk -l /dev/$rootdev | grep $part | grep Linux)
+ if [ -n "$parttype" ]; then
+ lsize=$(get_drive_size $part)
+ if [ "$lsize" -a $lsize -ge $minsize ]; then
+ display="$display $part\t\t$lsize"MB"\n"
+ myparts="$myparts $part"
+ fi
fi
done
- progress_indicator stop
+ progress_indicator stop
echo "OK"
- if [ -n "$parts" ]; then
+ if [ -n "$myparts" ]; then
lpartition=''
while [ -z "$lpartition" ]
do
# take the first partition as the default
- lpartition=$(echo $parts | /usr/bin/awk '{ print $1 }')
+ lpartition=$(echo $myparts | /usr/bin/awk '{ print $1 }')
echo "I found the following partitions suitable for the Vyatta image:"
echo -e "Partition\tSize"
@@ -256,7 +261,7 @@ select_partition () {
echo
echo -n "$text [$lpartition]: "
- lpartition=$(get_response "$lpartition" "$parts")
+ lpartition=$(get_response "$lpartition" "$myparts")
echo
done
else
@@ -266,6 +271,47 @@ select_partition () {
PARTITION=$lpartition
}
+## check_config_partition
+# look to see if this partition contains a config file
+# and back it up
+check_config_partition() {
+ lpart=$1
+
+ # Look to see if this is a config partition
+ mkdir -p /mnt/tmp
+ output=$(mount /dev/$lpart /mnt/tmp 2>&1)
+ if [ $? != 0 ]; then
+ echo -e "Cannot mount /dev/$lpart"."\nPlease see $INSTALL_LOG for more details.\nExiting.."
+ echo -e "Cannot mount /dev/$lpart"."\nmount /dev/$ldrive$part /mnt/tmp\nExiting..." >> $INSTALL_LOG
+ echo "$output" >> $INSTALL_LOG
+ exit 1
+ fi
+
+ # Look to see if there is a config partition there
+ if [ -f /mnt/tmp/opt/vyatta/etc/config/.vyatta_config ] || [ -f /mnt/tmp/.vyatta_config ]; then
+ response=''
+ while [ -z "$response" ]
+ do
+ echo "/dev/$lpart has an old configuration directory!"
+ echo -ne "Would you like me to save the data on it\nbefore I delete it? (Yes/No) [Yes]: "
+ response=$(get_response "Yes" "Yes No Y N")
+ if [ "$response" == "yes" ] || [ "$response" == "y" ]; then
+ mkdir -p /mnt/config
+ if [ -d /mnt/tmp/opt/vyatta/etc/config ]; then
+ output=$(cp -pR /mnt/tmp/opt/vyatta/etc/config/* /mnt/config)
+ else
+ output=$(cp -pR /mnt/tmp/* /mnt/config)
+ fi
+ if [ -n "$output" ]; then
+ echo -e "Warning: error in copying the old config partition.\nSee $INSTALL_LOG for more details."
+ echo -e "Warning: error in copying the old config partition.\ncp -pR /mnt/tmp/* /mnt/config\n$output\n" >> $INSTALL_LOG
+ fi
+ fi
+ done
+ fi
+ umount /mnt/tmp
+}
+
# Delete all existing partitions for an automated install
# $1 is the drive to delete partitions from
delete_partitions () {
@@ -278,38 +324,7 @@ delete_partitions () {
for part in $partitions
do
# Look to see if this is a config partition
- mkdir -p /mnt/tmp
- output=$(mount /dev/$ldrive$part /mnt/tmp 2>&1)
- if [ $? != 0 ]; then
- echo -e "Cannot mount /dev/$ldrive$part"."\nPlease see $INSTALL_LOG for more details.\nExiting.."
- echo -e "Cannot mount /dev/$ldrive$part"."\nmount /dev/$ldrive$part /mnt/tmp\nExiting..." >> $INSTALL_LOG
- echo "$output" >> $INSTALL_LOG
- exit 1
- fi
-
- # Look to see if there is a config parition there
- if [ -f /mnt/tmp/opt/vyatta/etc/config/.vyatta_config ] || [ -f .vyatta_config ]; then
- response=''
- while [ -z "$response" ]
- do
- echo "/dev/$ldrive$part has an old configuration directory!"
- echo -ne "Would you like me to save the data on it\nbefore I delete it? (Yes/No) [Yes]: "
- response=$(get_response "Yes" "Yes No Y N")
- if [ "$response" == "yes" ] || [ "$response" == "y" ]; then
- mkdir -p /mnt/config
- if [ -d /mnt/tmp/opt/vyatta/etc/config ]; then
- output=$(cp -pR /mnt/tmp/opt/vyatta/etc/config/* /mnt/config)
- else
- output=$(cp -pR /mnt/tmp/* /mnt/config)
- fi
- if [ -n "$output" ]; then
- echo -e "Warning: error in copying the old config partition.\nSee $INSTALL_LOG for more details."
- echo -e "Warning: error in copying the old config partition.\ncp -pR /mnt/tmp/* /mnt/config\n$output\n" >> $INSTALL_LOG
- fi
- fi
- done
- fi
- umount /mnt/tmp
+ check_config_partition "$ldrive$part"
echo "Removing partition $part on /dev/$ldrive" >> $INSTALL_LOG
output=$(parted /dev/$ldrive rm $part)
@@ -318,7 +333,7 @@ delete_partitions () {
echo -e "Warning: cannot delete partition $part on $ldrive.\nPlease see $INSTALL_LOG for more details."
echo -e "Warning: cannot delete partition $part on $ldrive.\nparted /dev/$ldrive rm $part\n$output" >> $INSTALL_LOG
fi
-
+
# We add a bogus sleep here because the loop needs to wait for udev
sleep 5
done
@@ -642,13 +657,16 @@ setup_method_manual() {
fi
done
+ # check for an old config on the partition
+ check_config_partition "$ROOT_PARTITION"
+
# create the ext3 fs on the part
make_filesystem "$ROOT_PARTITION"
# We need to set the INSTALL_DRIVE if it wasn't set when the user ran parted
# We assume that we will use the boot sector of the same drive that the partition is on
# TODO: Allow different drives to function as the boot device
- if [ -z "INSTALL_DRIVE" ]; then
+ if [ -z "$INSTALL_DRIVE" ]; then
INSTALL_DRIVE=$(echo $ROOT_PARTITION | sed 's/[0-9]//g')
fi
}
diff --git a/scripts/system/vyatta_update_login.pl b/scripts/system/vyatta_update_login.pl
new file mode 100755
index 00000000..985ef7b4
--- /dev/null
+++ b/scripts/system/vyatta_update_login.pl
@@ -0,0 +1,132 @@
+#!/usr/bin/perl
+
+use strict;
+use lib "/opt/vyatta/share/perl5";
+use VyattaConfig;
+
+# handle "user"
+my $uconfig = new VyattaConfig;
+$uconfig->setLevel("system login user");
+my %users = $uconfig->listNodeStatus();
+my @user_keys = sort keys %users;
+if ((scalar(@user_keys) <= 0) || !(grep /^root$/, @user_keys)
+ || ($users{'root'} eq 'deleted')) {
+ # root is deleted
+ print STDERR "User \"root\" cannot be deleted\n";
+ exit 1;
+}
+
+# we have some users
+for my $user (@user_keys) {
+ if ($users{$user} eq 'deleted') {
+ system("sudo /opt/vyatta/sbin/vyatta_update_login_user.pl -d '$user'");
+ exit 1 if ($? >> 8);
+ } elsif ($users{$user} eq 'added' || $users{$user} eq 'changed') {
+ my $fname = $uconfig->returnValue("$user full-name");
+ my $level = $uconfig->returnValue("$user level");
+ my $p = $uconfig->returnValue("$user authentication encrypted-password");
+ system("sudo /opt/vyatta/sbin/vyatta_update_login_user.pl '$user' "
+ . "'$fname' '$p' '$level'");
+ exit 1 if ($? >> 8);
+ } else {
+ # not changed. do nothing.
+ }
+}
+
+my $PAM_RAD_CFG = '/etc/pam_radius_auth.conf';
+my $PAM_RAD_BEGIN = '# BEGIN Vyatta Radius servers';
+my $PAM_RAD_END = '# END Vyatta Radius servers';
+
+sub is_pam_radius_present {
+ if (!open(AUTH, '/etc/pam.d/common-auth')) {
+ print STDERR "Cannot open /etc/pam.d/common-auth\n";
+ exit 1;
+ }
+ my $present = 0;
+ while (<AUTH>) {
+ if (/\ssufficient\spam_radius_auth\.so$/) {
+ $present = 1;
+ last;
+ }
+ }
+ close AUTH;
+ return $present;
+}
+
+sub remove_pam_radius {
+ return 1 if (!is_pam_radius_present());
+ my $cmd = 'sudo sh -c "'
+ . 'sed -i \'/\tsufficient\tpam_radius_auth\.so$/d;'
+ . '/\tpam_unix\.so /{s/ use_first_pass$//}\' '
+ . '/etc/pam.d/common-auth && '
+ . 'sed -i \'/\tsufficient\tpam_radius_auth\.so$/d\' '
+ . '/etc/pam.d/common-account"';
+ system($cmd);
+ return 0 if ($? >> 8);
+ return 1;
+}
+
+sub add_pam_radius {
+ return 1 if (is_pam_radius_present());
+ my $cmd = 'sudo sh -c "'
+ . 'sed -i \'s/^\(auth\trequired\tpam_unix\.so.*\)$'
+ . '/auth\tsufficient\tpam_radius_auth.so\n\1 use_first_pass/\' '
+ . '/etc/pam.d/common-auth && '
+ . 'sed -i \'s/^\(account\trequired\tpam_unix\.so.*\)$'
+ . '/account\tsufficient\tpam_radius_auth.so\n\1/\' '
+ . '/etc/pam.d/common-account"';
+ system($cmd);
+ return 0 if ($? >> 8);
+ return 1;
+}
+
+sub remove_radius_servers {
+ system("sudo sed -i '/^$PAM_RAD_BEGIN\$/,/^$PAM_RAD_END\$/{d}' "
+ . "$PAM_RAD_CFG");
+ return 0 if ($? >> 8);
+ return 1;
+}
+
+sub add_radius_servers {
+ my $str = shift;
+ system("sudo sh -c \""
+ . "echo '$PAM_RAD_BEGIN\n$str$PAM_RAD_END\n' >> $PAM_RAD_CFG\"");
+ return 0 if ($? >> 8);
+ return 1;
+}
+
+# handle "radius-server"
+my $rconfig = new VyattaConfig;
+$rconfig->setLevel("system login radius-server");
+my %servers = $rconfig->listNodeStatus();
+my @server_keys = sort keys %servers;
+if (scalar(@server_keys) <= 0) {
+ # all radius servers deleted
+ exit 1 if (!remove_pam_radius());
+ exit 0;
+}
+
+# we have some servers
+my $all_deleted = 1;
+my $server_str = '';
+remove_radius_servers();
+for my $server (@server_keys) {
+ if ($servers{$server} ne 'deleted') {
+ $all_deleted = 0;
+ my $port = $rconfig->returnValue("$server port");
+ my $secret = $rconfig->returnValue("$server secret");
+ my $timeout = $rconfig->returnValue("$server timeout");
+ $server_str .= "$server:$port\t$secret\t$timeout\n";
+ }
+}
+
+if ($all_deleted) {
+ # all radius servers deleted
+ exit 1 if (!remove_pam_radius());
+} else {
+ exit 1 if (!add_radius_servers($server_str));
+ exit 1 if (!add_pam_radius());
+}
+
+exit 0;
+