25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Merge remote-tracking branch 'processone/pr/3813'

* processone/pr/3813:
  make-installers: Support non-root installation
  make-installers: Override code on upgrade
  make-installers: Apply cosmetic changes
This commit is contained in:
Holger Weiss 2022-05-17 12:44:34 +02:00
commit 553a1ccadf

View File

@ -64,14 +64,13 @@ fi
rel_name='ejabberd' rel_name='ejabberd'
rel_vsn=$(git describe --tags | sed -e 's/-g.*//' -e 's/-/./' | tr -d '[:space:]') rel_vsn=$(git describe --tags | sed -e 's/-g.*//' -e 's/-/./' | tr -d '[:space:]')
code_path="/opt/$rel_name-$rel_vsn" home_url='https://www.ejabberd.im'
data_path="/opt/$rel_name" doc_url='https://docs.ejabberd.im'
conf_path="$data_path/conf" upgrade_url="$doc_url/admin/upgrade/#specific-version-upgrade-notes"
pem_file="$conf_path/server.pem" admin_url="$doc_url/admin/installation/#administration-account"
url='https://docs.ejabberd.im/admin/upgrade/#specific-version-upgrade-notes' default_code_dir="/opt/$rel_name-$rel_vsn"
url_doc_admin='https://docs.ejabberd.im/admin/installation/#administration-account' default_data_dir="/opt/$rel_name"
tmp_dir=$(mktemp -d "/tmp/.$rel_name.XXXXXX") tmp_dir=$(mktemp -d "/tmp/.$rel_name.XXXXXX")
path_uninstall="$code_path/uninstall.txt"
trap 'rm -rf "$tmp_dir"' INT TERM EXIT trap 'rm -rf "$tmp_dir"' INT TERM EXIT
umask 022 umask 022
@ -83,11 +82,11 @@ create_help_file()
cat >"$file" <<-EOF cat >"$file" <<-EOF
This is the $rel_name $rel_vsn-$iteration installer for linux-$arch This is the $rel_name $rel_vsn-$iteration installer for linux-$arch
Visit Visit:
https://www.ejabberd.im/ $home_url
ejabberd Documentation site: ejabberd documentation site:
https://docs.ejabberd.im/ $doc_url
EOF EOF
} }
@ -95,7 +94,6 @@ create_help_file()
create_setup_script() create_setup_script()
{ {
local dir="$1" local dir="$1"
local tarball="$2"
cat >"$dir/setup" <<-EOF cat >"$dir/setup" <<-EOF
#!/bin/sh #!/bin/sh
@ -112,51 +110,101 @@ create_setup_script()
if [ -t 0 ] if [ -t 0 ]
then then
read -p "\$question (y/n) [n] " response read -p "\$question (y/n) [n] " response
response="\$(printf '%s' "\$response" | case "\$response" in
tr '[:upper:]' '[:lower:]')" [Yy]|[Yy][Ee][Ss])
if [ "\$response" = 'y' ] || [ "\$response" = 'yes' ] return 0
then return 0 ;;
else return 1 [Nn]|[Nn][Oo]|'')
fi return 1
;;
*)
echo 'Please respond with "yes" or "no".'
user_agrees "\$question"
;;
esac
else # Assume 'yes' if not running interactively. else # Assume 'yes' if not running interactively.
return 0 return 0
fi fi
} }
if [ \$(id -u) != 0 ] if [ \$(id -u) = 0 ]
then then
echo >&2 'The installer must be run with superuser privileges.' is_superuser=true
else
is_superuser=false
echo "Running without superuser privileges (installer wasn't invoked"
echo 'with "sudo"), cannot perform system-wide installation this way.'
if ! user_agrees 'Continue anyway?'
then
echo 'Aborting installation.'
exit 1 exit 1
fi fi
fi
if [ \$is_superuser = true ]
then
code_dir='$default_code_dir'
data_dir='$default_data_dir'
user_name='$rel_name'
group_name='$rel_name'
elif user_agrees "Install $rel_name below \$HOME/opt?"
then
code_dir="\$HOME/opt/$rel_name-$rel_vsn"
data_dir="\$HOME/opt/$rel_name"
user_name="\$(id -u -n)"
group_name="\$(id -g -n)"
else
read -p 'Installation prefix: ' prefix
if printf '%s' "\$prefix" | grep -q '^/'
then
code_dir="\$prefix/$rel_name-$rel_vsn"
data_dir="\$prefix/$rel_name"
user_name="\$(id -u -n)"
group_name="\$(id -g -n)"
else
echo >&2 'Prefix must be specified as an absolute path.'
echo >&2 'Aborting installation.'
exit 1
fi
fi
prefix="\$(dirname "\$code_dir")"
conf_dir="\$data_dir/conf"
pem_file="\$conf_dir/server.pem"
uninstall_file="\$code_dir/uninstall.txt"
if [ -e '/run/systemd/system' ] if [ -e '/run/systemd/system' ]
then is_systemd=true then is_systemd=true
else is_systemd=false else is_systemd=false
fi fi
if [ -e '$data_path' ] if [ -e "\$data_dir" ]
then is_upgrade=true then is_upgrade=true
else is_upgrade=false else is_upgrade=false
fi fi
if id -u '$rel_name' >'/dev/null' 2>&1 if id -u "\$user_name" >'/dev/null' 2>&1
then user_exists=true then user_exists=true
else user_exists=false else user_exists=false
fi fi
echo echo
echo 'The following installation paths will be used:' echo 'The following installation paths will be used:'
echo '- $code_path' echo "- \$code_dir"
if [ \$is_upgrade = true ] if [ \$is_upgrade = true ]
then echo "- $data_path (existing files won't be modified)" then echo "- \$data_dir (existing files won't be modified)"
else echo '- $data_path' else echo "- \$data_dir (for configuration, database, and log files)"
fi fi
if [ \$is_superuser = true ]
then
if [ \$is_systemd = true ] if [ \$is_systemd = true ]
then echo '- /etc/systemd/system/$rel_name.service' then
echo '- /etc/systemd/system/$rel_name.service'
if [ \$is_upgrade = false ]
then echo 'The $rel_name service is going to be enabled and started.'
fi
fi fi
if [ \$user_exists = false ] if [ \$user_exists = false ]
then echo 'The $rel_name user is going to be created.' then echo 'The $rel_name user is going to be created.'
fi fi
if [ \$is_systemd = true ] && [ \$is_upgrade = false ]
then echo 'The $rel_name service is going to be enabled and started.'
fi fi
if ! user_agrees 'Install $rel_name $rel_vsn now?' if ! user_agrees 'Install $rel_name $rel_vsn now?'
then then
@ -165,8 +213,8 @@ create_setup_script()
fi fi
echo echo
if [ \$user_exists = false ] if [ \$user_exists = false ] && [ \$is_superuser = true ]
then useradd -r -d '$data_path' '$rel_name' then useradd -r -d "\$data_dir" "\$user_name"
fi fi
host=\$(hostname --fqdn 2>'/dev/null' || :) host=\$(hostname --fqdn 2>'/dev/null' || :)
@ -174,68 +222,131 @@ create_setup_script()
then host='localhost' then host='localhost'
fi fi
tar --skip-old-files -C "\$(dirname '$code_path')" -xf '$tarball' mkdir -p "\$prefix"
chown -R -h 'root:root' '$code_path' tar -cf - '$rel_name' | tar --skip-old-files -C "\$prefix" -xf -
chown 'root:$rel_name' '$code_path/lib/epam-'*'/priv/bin/epam' tar -cf - '$rel_name-$rel_vsn' | tar -C "\$prefix" -xf -
chmod '4750' '$code_path/lib/epam-'*'/priv/bin/epam'
if [ \$is_superuser = true ]
then
if [ \$is_upgrade = false ]
then chown -R -h "\$user_name:\$group_name" "\$data_dir"
fi
chown -R -h "\$(id -u -n):\$group_name" "\$code_dir"
chmod -R g+rX "\$code_dir"
chmod '4750' "\$code_dir/lib/epam-"*'/priv/bin/epam'
else
sed -i "s/^INSTALLUSER=.*/INSTALLUSER=\"\$user_name\"/" \
"\$code_dir/bin/${rel_name}ctl"
sed -i "s/^USER=.*/USER=\$user_name/" \
"\$code_dir/bin/$rel_name.init"
sed -i \
-e "s/^User=.*/User=\$user_name/" \
-e "s/^Group=.*/Group=\$group_name/" \
"\$code_dir/bin/$rel_name.service"
fi
if [ "\$code_dir" != '$default_code_dir' ]
then
sed -i "s|$default_code_dir|\$code_dir|g" \
"\$code_dir/bin/${rel_name}ctl" \
"\$code_dir/bin/$rel_name.init" \
"\$code_dir/bin/$rel_name.service"
fi
if [ "\$data_dir" != '$default_data_dir' ]
then
sed -i "s|$default_data_dir|\$data_dir|g" \
"\$code_dir/bin/${rel_name}ctl" \
"\$code_dir/bin/$rel_name.init" \
"\$code_dir/bin/$rel_name.service" \
"\$data_dir/conf/$rel_name.yml" \
"\$data_dir/conf/${rel_name}ctl.cfg"
fi
if [ \$is_upgrade = false ] if [ \$is_upgrade = false ]
then then
sed -i "s/ - localhost$/ - \$host/" '$conf_path/$rel_name.yml' sed -i "s/ - localhost$/ - \$host/" "\$conf_dir/$rel_name.yml"
openssl req -x509 \ openssl req -x509 \
-batch \ -batch \
-nodes \ -nodes \
-newkey rsa:4096 \ -newkey rsa:4096 \
-keyout '$pem_file' \ -keyout "\$pem_file" \
-out '$pem_file' \ -out "\$pem_file" \
-days 3650 \ -days 3650 \
-subj "/CN=\$host" >'/dev/null' 2>&1 || : -subj "/CN=\$host" >'/dev/null' 2>&1 || :
if [ -e '$pem_file' ] if ! [ -e "\$pem_file" ]
then chown '$rel_name:$rel_name' '$pem_file' then
else echo 'Failed to create a TLS certificate for ejabberd.' >&2 echo 'Failed to create a TLS certificate for $rel_name.' >&2
elif [ \$is_superuser = true ]
then
chown "\$user_name:\$group_name" "\$pem_file"
fi fi
fi fi
if [ \$is_systemd = true ] case \$is_systemd,\$is_superuser in
then true,true)
cp '$code_path/bin/$rel_name.service' '/etc/systemd/system/' cp "\$code_dir/bin/$rel_name.service" '/etc/systemd/system/'
systemctl -q daemon-reload systemctl -q daemon-reload
if [ \$is_upgrade = false ] if [ \$is_upgrade = false ]
then systemctl -q --now enable '$rel_name' then systemctl -q --now enable '$rel_name'
fi fi
elif [ \$is_upgrade = false ] ;;
then true,false)
echo 'You might want to install a systemd unit (see the'
echo "\$code_dir/bin directory for an example)."
;;
false,*)
echo 'You might want to install an init script (see the' echo 'You might want to install an init script (see the'
echo '$code_path/bin directory for an example).' echo "\$code_dir/bin directory for an example)."
fi ;;
esac
echo
echo '$rel_name $rel_vsn has been installed successfully.' echo '$rel_name $rel_vsn has been installed successfully.'
echo echo
echo >$path_uninstall cat >"\$uninstall_file" <<-_EOF
echo '# To uninstall ejabberd, first remove the service:' >>$path_uninstall # To uninstall $rel_name, first remove the service. If you're using systemd:
echo 'systemctl --now disable ejabberd' >>$path_uninstall systemctl --now disable $rel_name
echo 'rm -rf /etc/systemd/system/ejabberd.service' >>$path_uninstall rm -f /etc/systemd/system/$rel_name.service
echo >>$path_uninstall
echo '# Remove the binary files' >>$path_uninstall
echo 'rm -rf /opt/ejabberd-*' >>$path_uninstall
echo >>$path_uninstall
echo '# If you want to remove your config, database and logs:' >>$path_uninstall
echo 'rm -rf /opt/ejabberd' >>$path_uninstall
if [ \$is_upgrade = true ] # Remove the binary files:
rm -rf \$code_dir
# If you want to remove your configuration, database and logs:
rm -rf \$data_dir
_EOF
if [ \$is_superuser = true ]
then then
cat >>"\$uninstall_file" <<-_EOF
# To remove the user running $rel_name:
userdel \$user_name
_EOF
fi
if [ \$is_upgrade = false ]
then
if [ \$is_systemd = true ] && [ \$is_superuser = true ]
then
echo 'Now you can check $rel_name is running correctly:'
echo ' systemctl status $rel_name'
echo
fi
echo 'Next you may want to edit $rel_name.yml to set up hosts,'
echo 'register an account and grant it admin rigts, see:'
echo
echo '$admin_url'
else
echo 'Please check the following web site for upgrade notes:' echo 'Please check the following web site for upgrade notes:'
echo echo
echo '$url' echo '$upgrade_url'
echo echo
if [ \$is_systemd = true ] && [ \$is_superuser = true ]
then
echo 'If everything looks fine, restart the $rel_name service:' echo 'If everything looks fine, restart the $rel_name service:'
echo ' systemctl restart ejabberd' echo ' systemctl restart $rel_name'
else else
echo 'Now you can check ejabberd is running correctly:' echo 'If everything looks fine, restart the $rel_name service.'
echo ' systemctl status ejabberd' fi
echo
echo 'Next you may want to edit ejabberd.yml to setup hosts,'
echo 'register an account and grant it admin rigts, see:'
echo '$url_doc_admin'
fi fi
EOF EOF
chmod +x "$dir/setup" chmod +x "$dir/setup"
@ -243,16 +354,16 @@ create_setup_script()
for arch in $architectures for arch in $architectures
do do
tar_name="$rel_name-$rel_vsn-linux-$arch.tar" tar_name="$rel_name-$rel_vsn-linux-$arch.tar.gz"
tgz_name="$tar_name.gz"
installer_name="$rel_name-$rel_vsn-$iteration-linux-$arch.run" installer_name="$rel_name-$rel_vsn-$iteration-linux-$arch.run"
test -e "$tgz_name" || tools/make-binaries test -e "$tar_name" || tools/make-binaries
echo "$myself: Putting together installer for $arch ..." echo "$myself: Putting together installer for $arch ..."
gzip -c -d <"$tgz_name" >"$tmp_dir/$tar_name" tar -C "$tmp_dir" -xzpf "$tar_name"
create_help_file "$tmp_dir/help.txt" create_help_file "$tmp_dir/help.txt"
create_setup_script "$tmp_dir" "$tar_name" create_setup_script "$tmp_dir"
"$makeself" --help-header "$tmp_dir/help.txt" "$tmp_dir" "$installer_name" "$rel_name $rel_vsn" './setup' "$makeself" --help-header "$tmp_dir/help.txt" \
"$tmp_dir" "$installer_name" "$rel_name $rel_vsn" './setup'
find "$tmp_dir" -mindepth 1 -delete find "$tmp_dir" -mindepth 1 -delete
done done
echo "$myself: Created installers successfully." echo "$myself: Created installers successfully."