Adding existing users an app after it is installed and removing users from uninstalled apps
This commit is contained in:
parent
299739580f
commit
2018dee82c
|
@ -39,13 +39,13 @@ CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
|
||||||
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
|
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
|
||||||
for f in $UTILS_FILES
|
for f in $UTILS_FILES
|
||||||
do
|
do
|
||||||
source $f
|
source $f
|
||||||
done
|
done
|
||||||
|
|
||||||
APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
|
APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
|
||||||
for f in $APP_FILES
|
for f in $APP_FILES
|
||||||
do
|
do
|
||||||
source $f
|
source $f
|
||||||
done
|
done
|
||||||
|
|
||||||
MY_USERNAME=$1
|
MY_USERNAME=$1
|
||||||
|
@ -223,6 +223,9 @@ do
|
||||||
${PROJECT_NAME}-rmuser $MY_USERNAME
|
${PROJECT_NAME}-rmuser $MY_USERNAME
|
||||||
exit 672392
|
exit 672392
|
||||||
fi
|
fi
|
||||||
|
if ! grep -q "${app_name}_${MY_USERNAME}" $APP_USERS_FILE; then
|
||||||
|
echo "${app_name}_${MY_USERNAME}" >> $APP_USERS_FILE
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -40,13 +40,13 @@ COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
|
||||||
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
|
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
|
||||||
for f in $UTILS_FILES
|
for f in $UTILS_FILES
|
||||||
do
|
do
|
||||||
source $f
|
source $f
|
||||||
done
|
done
|
||||||
|
|
||||||
APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
|
APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
|
||||||
for f in $APP_FILES
|
for f in $APP_FILES
|
||||||
do
|
do
|
||||||
source $f
|
source $f
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ ! $MY_USERNAME ]; then
|
if [ ! $MY_USERNAME ]; then
|
||||||
|
@ -117,6 +117,9 @@ do
|
||||||
echo $"Removing user from ${app_name}"
|
echo $"Removing user from ${app_name}"
|
||||||
app_load_variables ${app_name}
|
app_load_variables ${app_name}
|
||||||
remove_user_${app_name} "$MY_USERNAME"
|
remove_user_${app_name} "$MY_USERNAME"
|
||||||
|
if grep -q "${app_name}_${MY_USERNAME}" $APP_USERS_FILE; then
|
||||||
|
sed -i "/${app_name}_${MY_USERNAME}/d" $APP_USERS_FILE
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,10 @@ REMOVED_APPS_FILE=/root/removed
|
||||||
|
|
||||||
INSTALLED_APPS_LIST=/usr/share/${PROJECT_NAME}/installed.txt
|
INSTALLED_APPS_LIST=/usr/share/${PROJECT_NAME}/installed.txt
|
||||||
|
|
||||||
|
# keep a list of which users have been added to which apps
|
||||||
|
# so that when a new app is added existing users can be added
|
||||||
|
APP_USERS_FILE=$HOME/app_users.txt
|
||||||
|
|
||||||
if [ ! $COMPLETION_FILE ]; then
|
if [ ! $COMPLETION_FILE ]; then
|
||||||
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
|
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
|
||||||
fi
|
fi
|
||||||
|
@ -385,6 +389,11 @@ function remove_apps {
|
||||||
do
|
do
|
||||||
if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then
|
if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then
|
||||||
if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
|
if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
|
||||||
|
echo $"Removing users for application: ${a}"
|
||||||
|
|
||||||
|
function_check remove_users_for_app
|
||||||
|
remove_users_for_app ${a}
|
||||||
|
|
||||||
echo $"Removing application: ${a}"
|
echo $"Removing application: ${a}"
|
||||||
|
|
||||||
function_check app_load_variables
|
function_check app_load_variables
|
||||||
|
@ -423,6 +432,76 @@ function install_apps_interactive {
|
||||||
echo $"Interactive settings complete"
|
echo $"Interactive settings complete"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function user_added_to_app {
|
||||||
|
user_name="$1"
|
||||||
|
app_name="$2"
|
||||||
|
|
||||||
|
if [[ $(is_valid_user "$user_name") == "1" ]]; then
|
||||||
|
if [[ $(function_exists add_user_${app_name}) == "1" ]]; then
|
||||||
|
if grep -Fxq "${app_name}_${user_name}" $APP_USERS_FILE; then
|
||||||
|
echo "1"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_users_after_install {
|
||||||
|
app_name="$1"
|
||||||
|
|
||||||
|
read_config_param MY_USERNAME
|
||||||
|
|
||||||
|
# ensure a minimum password length
|
||||||
|
if [ ! $MINIMUM_PASSWORD_LENGTH ]; then
|
||||||
|
MINIMUM_PASSWORD_LENGTH=20
|
||||||
|
fi
|
||||||
|
if [ ${#MINIMUM_PASSWORD_LENGTH} -lt 20 ]; then
|
||||||
|
MINIMUM_PASSWORD_LENGTH=20
|
||||||
|
fi
|
||||||
|
|
||||||
|
ADMIN_USERNAME=$(get_completion_param "Admin user")
|
||||||
|
if [ ! $ADMIN_USERNAME ]; then
|
||||||
|
ADMIN_USERNAME=$MY_USERNAME
|
||||||
|
fi
|
||||||
|
|
||||||
|
for d in /home/*/ ; do
|
||||||
|
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
||||||
|
if [[ "$USERNAME" != "$ADMIN_USERNAME" ]]; then
|
||||||
|
if [[ $(user_added_to_app "${USERNAME}" "${app_name}") == "0" ]]; then
|
||||||
|
valstr=$"Login for user ${USERNAME}="
|
||||||
|
if grep -q "${valstr}" /home/${ADMIN_USERNAME}/README; then
|
||||||
|
app_password=$(cat /home/${ADMIN_USERNAME}/README | grep "${valstr}" | head -n 1 | awk -F '=' '{print $2}')
|
||||||
|
else
|
||||||
|
app_password="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
|
||||||
|
echo "${valstr}${app_password}" >> /home/${ADMIN_USERNAME}/README
|
||||||
|
fi
|
||||||
|
add_user_${app_name} "${USERNAME}" "${app_password}"
|
||||||
|
echo "${app_name}_${USERNAME}" >> $APP_USERS_FILE
|
||||||
|
chown ${ADMIN_USERNAME}:${ADMIN_USERNAME} /home/${ADMIN_USERNAME}/README
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_users_for_app {
|
||||||
|
app_name="$1"
|
||||||
|
|
||||||
|
read_config_param MY_USERNAME
|
||||||
|
|
||||||
|
for d in /home/*/ ; do
|
||||||
|
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
||||||
|
if [[ "$USERNAME" != "$MY_USERNAME" ]]; then
|
||||||
|
if [[ $(user_added_to_app "${USERNAME}" "${app_name}") == "1" ]]; then
|
||||||
|
if [[ $(function_exists remove_user_${app_name}) == "1" ]]; then
|
||||||
|
remove_user_${app_name} "${USERNAME}"
|
||||||
|
fi
|
||||||
|
sed -i "/${app_name}_${USERNAME}/d" $APP_USERS_FILE
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
function install_apps {
|
function install_apps {
|
||||||
is_interactive=$1
|
is_interactive=$1
|
||||||
|
|
||||||
|
@ -459,6 +538,9 @@ function install_apps {
|
||||||
function_check app_save_variables
|
function_check app_save_variables
|
||||||
app_save_variables ${a}
|
app_save_variables ${a}
|
||||||
|
|
||||||
|
function_check add_users_after_install
|
||||||
|
add_users_after_install ${a}
|
||||||
|
|
||||||
function_check install_completed
|
function_check install_completed
|
||||||
install_completed ${a}
|
install_completed ${a}
|
||||||
echo $"${a} was installed from interactive"
|
echo $"${a} was installed from interactive"
|
||||||
|
@ -485,6 +567,9 @@ function install_apps {
|
||||||
function_check app_save_variables
|
function_check app_save_variables
|
||||||
app_save_variables ${a}
|
app_save_variables ${a}
|
||||||
|
|
||||||
|
function_check add_users_after_install
|
||||||
|
add_users_after_install ${a}
|
||||||
|
|
||||||
function_check install_completed
|
function_check install_completed
|
||||||
install_completed ${a}
|
install_completed ${a}
|
||||||
echo $"${a} was installed"
|
echo $"${a} was installed"
|
||||||
|
|
Loading…
Reference in New Issue