Add conf file and parameters values
Signed-off-by: Alban Vidal <alban.vidal@zordhak.fr>
This commit is contained in:
parent
452a94b993
commit
57623a2cb8
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
conf
|
@ -33,31 +33,102 @@
|
|||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
# Current git directory
|
||||||
|
GIT_DIR="$(realpath ${0%/*})"
|
||||||
|
|
||||||
|
# Conf file path
|
||||||
|
CONF_FILE="$GIT_DIR/conf"
|
||||||
|
|
||||||
|
# Used if parameter id required - Do not edit
|
||||||
|
RELOAD_PARAMATER=false
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# Function to request parameters
|
||||||
|
function func_read_param() {
|
||||||
|
# $1 => PARAM => Parameter name
|
||||||
|
PARAM="$1"
|
||||||
|
# after shitf, $@ => Detail of selected param
|
||||||
|
shift
|
||||||
|
DETAIL="$@"
|
||||||
|
# Display and read reponse
|
||||||
|
read -p "${DETAIL}: " VALUE
|
||||||
|
# Delete line if exist, and write in conf file
|
||||||
|
sed -i "/$PARAM/d" $CONF_FILE
|
||||||
|
# Write param name and value in conf file
|
||||||
|
echo "${PARAM}='$VALUE'" >> $CONF_FILE
|
||||||
|
# Set to true to reload this script
|
||||||
|
RELOAD_PARAMATER=true
|
||||||
|
}
|
||||||
|
|
||||||
|
# List names of parameter variables and description of parameter
|
||||||
|
LIST_PARAM="
|
||||||
|
UNATTENDED_EMAIL Unattended email alert
|
||||||
|
GIT_USERNAME Git username
|
||||||
|
GIT_EMAIL Git email
|
||||||
|
"
|
||||||
|
|
||||||
|
IFS=$'\n'
|
||||||
|
|
||||||
|
# Test if conf file exist
|
||||||
|
if [ -f $CONF_FILE ] ;then
|
||||||
|
# If conf file exist, load it and test if each variable is defined
|
||||||
|
. $CONF_FILE
|
||||||
|
for DETAIL_PARAM in $LIST_PARAM ;do
|
||||||
|
PARAM=${DETAIL_PARAM%% *} # Delete all after first space
|
||||||
|
DETAIL=${DETAIL_PARAM#* } # Delete all before first space
|
||||||
|
# If variable is not defined, or if variable is empty, do request it
|
||||||
|
if [ -z ${!PARAM} ] ;then
|
||||||
|
func_read_param $PARAM $DETAIL
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
# Conf file does not exist
|
||||||
|
touch $CONF_FILE # Create empty conf file
|
||||||
|
# For all variable, do request it
|
||||||
|
for DETAIL_PARAM in $LIST_PARAM ;do
|
||||||
|
PARAM=${DETAIL_PARAM%% *} # Delete all after first space
|
||||||
|
DETAIL=${DETAIL_PARAM#* } # Delete all before first space
|
||||||
|
func_read_param $PARAM $DETAIL
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If reload is required
|
||||||
|
if $RELOAD_PARAMATER ; then
|
||||||
|
$0 # Restart this script
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
|
||||||
# Install the packages
|
# Install the packages
|
||||||
apt-get -y install -y git tig bash-completion unattended-upgrades apt-listchanges logrotate
|
apt-get -y install \
|
||||||
|
git \
|
||||||
|
tig \
|
||||||
|
bash-completion \
|
||||||
|
unattended-upgrades \
|
||||||
|
apt-listchanges \
|
||||||
|
logrotate
|
||||||
|
|
||||||
# Configure auto updates
|
# Configure auto updates
|
||||||
sed -i \
|
sed -i \
|
||||||
-e 's#^//Unattended-Upgrade::Mail .*#Unattended-Upgrade::Mail "unattended@zordhak.fr";#' \
|
-e "s#^//Unattended-Upgrade::Mail .*#Unattended-Upgrade::Mail '$UNATTENDED_EMAIL';#" \
|
||||||
-e 's#^//Unattended-Upgrade::MailOnlyOnError .*#Unattended-Upgrade::MailOnlyOnError "true";#' \
|
-e 's#^//Unattended-Upgrade::MailOnlyOnError .*#Unattended-Upgrade::MailOnlyOnError "true";#' \
|
||||||
/etc/apt/apt.conf.d/50unattended-upgrades
|
/etc/apt/apt.conf.d/50unattended-upgrades
|
||||||
|
|
||||||
# Git global username and email
|
# Set git global config
|
||||||
read -p "Git username: " GIT_USERNAME
|
|
||||||
read -p "Git email: " GIT_EMAIL
|
|
||||||
|
|
||||||
git config --global user.name "$GIT_USERNAME"
|
git config --global user.name "$GIT_USERNAME"
|
||||||
git config --global user.email "$GIT_EMAIL"
|
git config --global user.email "$GIT_EMAIL"
|
||||||
|
|
||||||
## Symbolic links
|
## Symbolic links
|
||||||
# Bashrc
|
# Bashrc
|
||||||
ln -sf /srv/git/basic_config_debian/root/.bashrc /root/
|
ln -sf $GIT_DIR/root/.bashrc /root/
|
||||||
# Profile
|
# Profile
|
||||||
ln -sf /srv/git/basic_config_debian/root/.profile /root/
|
ln -sf $GIT_DIR/root/.profile /root/
|
||||||
mkdir -p /root/.profile.d
|
mkdir -p /root/.profile.d
|
||||||
ln -sf /srv/git/basic_config_debian/root/.profile.d/00_connexion_info.conf /root/.profile.d/
|
ln -sf $GIT_DIR/root/.profile.d/00_connexion_info.conf /root/.profile.d/
|
||||||
# vimrc
|
# vimrc
|
||||||
ln -sf /srv/git/basic_config_debian/root/.vimrc /root/
|
ln -sf $GIT_DIR/root/.vimrc /root/
|
||||||
|
|
||||||
## Tune logrotate
|
## Tune logrotate
|
||||||
# Fix logrotate bug
|
# Fix logrotate bug
|
||||||
|
Loading…
Reference in New Issue
Block a user