Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 10 days ago.
Improve this question
When installing PostgreSQL from apt on Ubuntu, the command initdb to initialize the cluster is done automatically, and the locale is set from the enviroment.
I like to have my system in en_US.UTF8, but initialize the cluster in a different locale.
For that I've tried to set the environment variable locally for apt
LOCALE=es_ES.UTF-8 LC_MESSAGES=C apt install postgresql-15
but it's not working. apt output shows:
/usr/lib/postgresql/15/bin/initdb -D /var/lib/postgresql/15/main --auth-local peer --auth-host scram-sha-256 --no-instructions
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
For completion a simplified version of my provision script looks like this:
MY_LOCALE="es_ES.UTF-8"
# Allow the system to use $MY_LOCALE
sed -i "s/^# ${MY_LOCALE} UTF-8/${MY_LOCALE} UTF-8/" /etc/locale.gen
locale-gen
# Uncomment these lines if $MY_LOCALE must be the default
# update-locale --reset LANG="${MY_LOCALE}" LC_CTYPE="${MY_LOCALE}"
# export LANG="${MY_LOCALE}"
# export LC_TYPE="${MY_LOCALE}"
# Set the locale locally to apt command
LOCALE="${MY_LOCALE}" LC_MESSAGES=C apt install postgresql-15
Is there any way to pass locale variables to apt/initdb on installation?
Update.
As the question is closed and no answers can be added I edit to explain my actual workaround:
MY_LOCALE="es_ES.UTF-8"
# Allow the system to use $MY_LOCALE
sed -i "s/^# ${MY_LOCALE} UTF-8/${MY_LOCALE} UTF-8/" /etc/locale.gen
locale-gen
# Uncomment these lines if $MY_LOCALE must be the default
# update-locale --reset LANG="${MY_LOCALE}" LC_CTYPE="${MY_LOCALE}"
# export LANG="${MY_LOCALE}"
# export LC_TYPE="${MY_LOCALE}"
# Backup default enviroment variables
BCK_LANG="${LANG}"
BCK_LC_CTYPE="${LC_CTYPE}"
BCK_LC_MESSAGES="${LC_MESSAGES}"
# Set the desired locale for PostgreSQL as default for the system
update-locale --reset LANG="${MY_LOCALE}" LC_CTYPE="${MY_LOCALE}" LC_MESSAGES=C
# Install PostgreSQL
apt install postgresql-15
# Restore default locale
update-locale --reset LANG="${BCK_LANG}" LC_CTYPE="${BCK_LC_CTYPE}" LC_MESSAGES="${BCK_LC_MESSAGES}"
unset BCK_LANG
unset BCK_LC_CTYPE
unset BCK_LC_MESSAGES
I don't think so.
The behavior of the Ubuntu packages has always annoyed me. Do what I do: drop the cluster that the packages create automatically and create it again with the configuration you want.
Related
I have the case that I need to use VS Code installed on Windows 10 and run it with the extension Remote - SSH on a RHEL 7.x.
The default RHEL 7.x runs with git 1.8.x. I have installed a newer git version but this is not in the default $PATH environment.
I have found this instructions https://code.visualstudio.com/docs/remote/wsl#_advanced-environment-setup-script which describe how to set the environment variables specifically for VS Code when usind WSL.
If you want to run additional commands or modify the environment this can be done in a setup script ~/.vscode-server/server-env-setup
This does seem to work only if you use WSL. Why does this not work with the Remote - SSH extension?
My special case is that I only want and need the git>=2 while usind VS Code. When I am connected regularly via ssh I would like and need the OS default tools and settings.
This gives me the special request that I don't want to edit the ~/.bashrc, ~/.cshrc or any other user environment files.
I would like to be able to edit the environment for VS Code only. Some kind, maybe like:
#!/bin/bash
export PATH=/opt/rh/rh-git29/root/usr/bin\:$PATH
export LD_LIBRARY_PATH=/opt/rh/httpd24/root/usr/lib64:$LD_LIBRARY_PATH
...
#!/bin/csh
setenv PATH /opt/rh/rh-git29/root/usr/bin\:$PATH
setenv LD_LIBRARY_PATH /opt/rh/httpd24/root/usr/lib64:$LD_LIBRARY_PATH
...
Is there anything I have not found yet where I can make my requests to work or would this be some kind of request to the VS Code Team?
Regards.
I think I found the solution in this issue comment and the follow-up response:
When vscode-server initially starts, it uses a login shell, sourcing .profile in your home directory.
However, any following interactive shells started through VS Code are non-login shells and thus only source .bashrc
A complication in fiddling with this is that vscode-server apparently caches the environment during its lifetimes, so changes to these dotfiles don't become visible until the server is restarted.
I have a better solution to minimize the proxy scope
export http_proxy=<proxy here>
export no_proxy=<no proxy here>
while IFS= read -r _file; do
if ! grep -s -q "export http_proxy=" "${_file}"; then
sed -i -e "/^ROOT/i export http_proxy=${http_proxy}" -e "/^ROOT/i export https_proxy=${http_proxy}" -e "/^ROOT/i export no_proxy=${no_proxy}" "${_file}"
fi
done < <(find ~/.vscode-server/bin -type f -name "server.sh")
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I installed vim on windows 10 using chocolatey. When I edit a file in powershell, everything works great! I even got copy and paste to work. However, when I edit a git commit message, vim doesn't redraw my screen properly. If I force a screen redraw, I can see my updated text properly, but that is super annoying.
I configured git to use vim with:
git config --global core.editor vim
How can I make vim behave properly?
TLDR
Giving git the direct fully-qualified path to my vim executable fixed things, and I don't know why:
git config --global core.editor "'C:\tools\vim\vim82\vim.exe' -f -i NONE"
Single quotes around the path are important because git doesn't know how to handle paths with backslashes.
Double quotes around the whole configuration are important so that git doesn't apply -f -f NONE to the git config command.
I found -f -i NONE on this answer, and I don't know what it does, but git commit didn't work without it.
How I found the full path
vim adds a c:\windows\vim.bat file, which is what powershell uses to launch vim when you type vim:
PS C:\Users\heath> Get-Command vim
CommandType Name Version Source
----------- ---- ------- ------
Application vim.bat 0.0.0.0 C:\windows\vim.bat
vim.bat is pretty simple:
#echo off
rem -- Run Vim --
rem # uninstall key: vim82 #
setlocal
set VIM_EXE_DIR=C:\tools\vim\vim82
if exist "%VIM%\vim82\vim.exe" set VIM_EXE_DIR=%VIM%\vim82
if exist "%VIMRUNTIME%\vim.exe" set VIM_EXE_DIR=%VIMRUNTIME%
if not exist "%VIM_EXE_DIR%\vim.exe" (
echo "%VIM_EXE_DIR%\vim.exe" not found
goto :eof
)
"%VIM_EXE_DIR%\vim.exe" %*
Thus, my full vim path is C:\tools\vim\vim82\vim.exe
MongoDB RPM packages (provided by official repo.mongodb.org repository, as of version 3.4.1) automatically and unconditionally restart server on package upgrade. This behaviour is hardcoded into postun handler:
if test $1 -ge 1
then
/usr/bin/systemctl restart mongod >/dev/null 2>&1 || :
fi
This is an inconvenient and dangerous behaviour, especially when you use configuration management tools to set up your servers. For example, I'd like to run a full Ansible playbook to set up my servers first, and then restart MongoDB manually one by one to have full control of the situation.
Is there any way to alter or disable this? Alternative MongoDB packages, maybe? Or some obscure yum/rpm command option to disable scriptlets?
I'm aware that I can switch to simple .tar.gz installation, but this is the last resort.
If you first download the rpm and install it manually using rpm; you can use the --nopostun option:
rpm -Uvh mongodb***rpm --nopostun
from the rpm man page:
--noscripts
--nopre
--nopost
--nopreun
--nopostun
--nopretrans
--noposttrans
Don't execute the scriptlet of the same name. The --noscripts option is equivalent to
--nopre --nopost --nopreun --nopostun --nopretrans --oposttrans
and turns off the execution of the corresponding %pre, %post, %preun, %postun %pretrans, and %posttrans scriptlet(s).
afaik yumcannot handle the --nopostun and other flags.
I've created an installer for my application that also installs postgreSQL.
The first question:
What is the best way to configure my database, I mean, is it better to use the postgres default user account? Or should I create a new user. Also is it better to use default public schema or should I create a new schema? As one can see, I'm seeking the best practices to use databases. Also, what kind of care do I need to take with possible already installed versions of postgreSQL from any other application?
The second question:
How to create a user using the installer?
I'm trying to create a new user different from the default user but how can I set a password for this user? I would like to do this without prompting the user in a command shell.
If it's helpful, I will happily post any of my code!
Let's go for some points that you've asked in your question.
What is the best way to configure my database, I mean, is it better to use the postgres default user account?
That doesn't matter at all as long as you have defined a strong password for the user to install it you will be good.
is it better to use default public schema or should I create a new schema?
That will depends on your software. If you want to have everything well defined and organized on the use of the database go on, create a schema to your system. If your system will be the only one using PostgreSQL why botter? Read this answer on this matter from DBA forum PostgreSQL and default Schemas
Also, what kind of care I might to take with possible already installed versions of postgreSQL of any other application?
That's a trick one and the very first problem you will have. I find out the hard way that you can't install PostgreSQL database if you already have one previously installed. Not even if you uninstall it (in this case you have to delete all associated registries from windows registry of PostgreSQL).
My advice here is that you put a message on your installer that your system needs a fresh install of PostgreSQL on the target machine and it can't have a previously installed one on it otherwise the install will fail. I know that sucks, but I couldn't find anything to do here. One other thing that I did was to add a note on the installer messages to the user that if He still want to install the system on that machine He would have to contact the "support" to do it manually.
How to create a user using the installer?
From here I will add some commands to you install PostgreSQL in unattended mode.
I'm trying to create a new user different from default user but how to set a password to this user?
The command you will need to install PostgreSQL with a user different from the default one will be:
postgresqlInstallFile[withversion].exe --mode unattended --superaccount super_user_name --superpassword yourStrongPassowordHere
It would be great here if you could ask for the password on your installer program and use a variable within above command.
That alone will install the database with a user defined by you. Here is the documentation about all parameters for PostgreSQL Unattended Install
The second problem is regarding the database of you system. The best course of action I could find was to make a Dump file from the database that I need to install (this database would be empty, with just the structure), added this dump file to the installer so I could import it to the fresh installation of the database.
The problem with this approach is you can't create a database or restore it to PostgreSQL without entering the password for the super account. What I did was
Add messages to the user that He should pay attention to the installer messages and steps so he can't get it wrong
After installing PostgreSql database comes the step to create the database so I use the command:
[path_for_postgresq]/createdb.exe -U user_you_created -W -E UTF8 -O user_you_created "NameOfYourDatabase"
Before I run the above command I showed a message to the user that he will see a prompt screen asking for a password, so He have to enter it and hit Enter. You can't add it as a parameter (PostgreSQL says it is for security measures)
After the database creation it is time to import the dump that I've added on the installer so I used:
[path_for_postgresq]/pg_restore -U user_you_created -c -d NameOfYourDatabase DumpFileOfYourDatabase.backup
Once again, before this command I showed a message to the user asking to enter the password for the database restore command.
Here I will add the code I made for the NSIS installer. Just the PostgreSQL part of it. There are a lot more on my installer you may need something more.
;--------------------------------
;Include Modern UI
!include "MUI.nsh"
;Include Process checker
!include nsProcess.nsh
;Include ZipDLL
!include zipdll.nsh
; include for some of the windows messages defines
!define ALL_USERS
!include winmessages.nsh
;--------------------------------
;General Configuration
Name "Name of your Installer"
OutFile "fileNameOfYourInstaller.exe"
ShowInstDetails "show"
InstallDir $PROFILE\FolderWhereToInstallYourSystem
; Request application privileges for Windows Vista
RequestExecutionLevel admin
; HKLM (all users) vs HKCU (current user) defines
!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
!define env_hkcu 'HKCU "Environment"'
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
Function .onInit
SetOutPath $TEMP
# the plugins dir is automatically deleted when the installer exits
InitPluginsDir
File /oname=re.bmp re.bmp #here is an image for a splash screen of the installer
splash::show 2000 re
Pop $0 ; $0 has '1' if the user closed the splash screen early,
; '0' if everything closed normally, and '-1' if some error occurred.
FunctionEnd
Function verifyInstallationDIR
IfFileExists $INSTDIR PathGood
MessageBox MB_OK "The chosen directory is not valid for installation.$\r$\nPlease start again and inform a valid path."
Quit ;if $INSTDIR wasn't created the installer will close
PathGood:
FunctionEnd
Section
SetOutPath $TEMP
CreateDirectory $INSTDIR
#Message to the user to PAY ATTENTIOM
MessageBox MB_OK "Please carefully read all messages through installation steps!"
Call verifyInstallationDIR
#Files needed to the installer
File "resources\DatabaseDumpFile.backup"
File "resources\postgresql-9.3.9-3-windows-x64.exe"
#Call postgresql installation in an unattended mode
ExecWait 'postgresqlInstallFile[withversion].exe --mode unattended --superaccount super_user_name --superpassword yourStrongPassowordHere'
Postgresql_Running_Check:
; is app.exe process running? result is stored in $R0
${nsProcess::FindProcess} "postgres.exe" $R0
${If} $R0 > 0
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "PostgreSQL process is not running yet. Wait 30 seconds and click Retry or Cancel to cancel installation." /SD IDCANCEL IDRETRY Postgresql_Running_Check
Quit
${EndIf}
;Create the database
MessageBox MB_OK "The System DataBase will be created. A console window will appear asking for a password. Please when it happens type:$\r$\n$\r$\nyourStrongPassowordHere"
ExecWait '$PROGRAMFILES64\PostgreSQL\9.3\bin\createdb.exe -U user_you_created -W -E UTF8 -O user_you_created "NameOfYourDatabase"'
MessageBox MB_OK "The System Installer will import the configuration data to the database. It will ask again for the password. Please when it happens type:$\r$\n$\r$\nyourStrongPassowordHere"
ExecWait '$PROGRAMFILES64\PostgreSQL\9.3\bin\pg_restore -U user_you_created -c -d NameOfYourDatabase DatabaseDumpFile.backup'
SectionEnd
Hope it helps.
Normally in linux Debian we do sth like this to install a package non-interactively e.g
sudo apt-get install -y Package_x_z
#[-y --assume-yes]
How we can do the same while installing a perl module e.g
sudo perl -MCPAN -e 'install DBI'
That prompt is (typically) coming from ExtUtils::MakeMaker's prompt() function. Stick export PERL_MM_USE_DEFAULT=1 in your .bashrc (or equivalent for your preferred shell) to stop the prompts. The ExUtils::MakeMaker man page documents it thus:
PERL_MM_USE_DEFAULT
If set to a true value then MakeMaker's prompt function will always return the default
without waiting for user input.
Note that this can come to bite you if you run cpan(1) on a box that's not yet had CPAN repositories configured. It will rattle on and get stuck in a prompt loop at a point where there is no default and you need to make a choice, but have no ability to do so. export PERL_MM_USE_DEFAULT=0 in the shell before running cpan(1) will of course temporarily re-enable input.
To prevent the CPAN client from asking whether to install prerequisites, start it in interactive mode
perl -MCPAN -e shell
and enter the commands:
o conf build_requires_install_policy yes
o conf prerequisites_policy follow
o conf commit
The commit command is optional, but it will update the default configuration, which I suspect is what you want. Without it, you may or may not (depending on whether autocommit is enabled in your CPAN config) need to make this change every time you want to do a prompt-less installation.
These changes will deal with all of the CPAN client's routine questions about whether to install dependencies. For distributions which have questions embedded in their install scripts, you may also want to add
o conf inactivity_timeout 60
to set how long it will wait for a response before automatically going with the default answer to the question. (Set it to 0 to change it back to "wait forever".)
What about just :
$ yes | sudo perl -MCPAN -e 'install DBI'
Ban ! your problem is solved :-)
Appending to an answer here, you can also make these changes in config file located at /usr/share/perl5/CPAN/Config.pm.
'build_requires_install_policy' => q[yes],
'prerequisites_policy' => q[follow],
This helped me to automate installation, since CPAN doesn't have these configuration by default.