How to make psql editor show line number - psql

New to the VIM. Environment: WSL2
Already set VIM to show line number, It works as expected. So I type vi test.txt in Ubuntu/WSL2, it will show line number.
But In psql, when I type \e It will not show line number.

sudo su to enter root mode.
sudo -u postgres -i
After logging as user postgres in Ubuntu then using
vim ~/.vimrc to create/edit a new vimrc file.

Related

carriage-return character ^M in json file when using docker cp

My host is windows and I am using docker desktop. When I use the command docker cp to copy files from windows to the container which is Ubuntu the json file would end up containing the carriage-return character (i.e.^M). How can I remove them?
Impediments:
docker cp windows command would copy the json as read-only by root
Docker image pull from somewhere and I only have access to user jovyan whom do not have permission to chmod. docker exec -u 0 would return error Error response from daemon: Multiple IDs found with provided prefix: 0 so I can't just login as root either.
Tried WinSCP to move the file to the container but return error say "Remote side unexpectedly closed network connection". I am using SFTP with hostname as localhost and port no. filled. I left password blank as I don't think there is password required for user jovyan since docker exec would connect to this user directly without asking password.
The simple answer here is to install conversion programs that will convert the line endings and deal with the pesky carriage returns for you, dos2unix is always a good shout.
Install:
sudo apt install dos2unix
Usage:
dos2unix <filename>
^M is the keyboard equivalent of the \r character. sed is a program installed by default in Ubuntu distros so you should be able to run this to remove these characters from the json file in your Ubuntu container:
sed -i 's/\r$//' FILENAME
If you want to know what the command does, here's the info:
sed is a stream editor that can change files
-i means to make modifications in place
s/\r$// is a replacement expression saying to replace \r at the end of lines ($ signifies the end of a line) with nothing

How can i customize greenlight from big blue button

For my one project I use greenlight
first, I installed greenlight on the server but I want to customize the landing page but I don't how to do it. so I installed rails application in my server, I did some changes like adding a custom class. but no effect on the landing page.
can someone explain me how can I fully customize greenlight directly on the server ?
Its for Greenlight V1.
After searching bit i found below steps to setup ruby on rails greenlight app on server.
If you already setup greenlight with docker then please stop docker.
for docker compose you need to run command docker-compose down. it will stop docker image and you will see 404 on your server .
You need to fork greenlight from github first then clone that project in server you can clone it anywhere on server just make sure your server is running on port 5000.
you can checkout more from here
This are all the commands I used to have greenlight running without docker which works for me
======================
apt-get install curl
sudo apt-get install gnupg2
curl -sSL https://rvm.io/mpapis.asc | sudo gpg2 --import -
sudo gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | sudo bash -s stable
source /etc/profile.d/rvm.sh
rvm requirements
rvm list known
rvm install 2.5.1
rvm use 2.5.1 --default
ruby --version
gem install rails
cd /
git clone https://github.com/bigbluebutton/greenlight.git
cd /greenlight
nano Gemfile
(mover dotenv-rails fuera del bloque test/development)
gem install bundler -v 1.16.1
sudo apt-get install libpq-dev
bundle
cp greenlight.nginx /etc/bigbluebutton/nginx/greenlight.nginx
systemctl restart nginx
rake secret
(Copy the secret generated, you will need it for .env)
bbb-conf --secret
(Copy the URL and Secret, you will need it for .env)
cp sample.env .env
nano .env
(fill the Secret and BigBlueButton credentials you generated before)
RAILS_ENV=production rake db:migrate
rails assets:precompile
rails s -p 5000 -e production
=======================================
In this project do changes as you require and run server again.
first of all you must have installed greenlight installed on server
for changing the color of theme :
vim config/application.rb
scroll down and you will found following code just replace code of color with your desire:
# Default primary color if the user does not specify one
config.primary_color_default = "#116ceb"
# Default primary color lighten if the user does not specify one
config.primary_color_lighten_default = "#e8eff9"
# Default primary color darken if the user does not specify one.
config.primary_color_darken_default = "#316cbe"
there is lots of things you can customize..(almost everything).
And one of the most important thing after making changes to any file you must have to rebuild your image of docker you can do that by running the command which is given at the end.
This command is for default settings if you have changed the name of your image please replace bigbluebutton/greenlight release-v2 with yourimage name.
you will find your image name here:
#this will open the yml file for docker settings
vim docker-compose.yml
#file will look like this:
ersion: '3'
services:
app:
entrypoint: [bin/start]
image: bigbluebutton/greenlight:release-v2 #nmae of your image
container_name: greenlight-v2
env_file: .env
restart: unless-stopped
ports:
- 127.0.0.1:5000:80
copy this command and past into the terminal blow command for rebuilding your docker image
docker-compose down && ./scripts/image_build.sh bigbluebutton/greenlight release-v2 && docker-compose up -d

How do I edit a file after I shell to a Docker container?

I successfully shelled to a Docker container using:
docker exec -i -t 69f1711a205e bash
Now I need to edit file and I don't have any editors inside:
root#69f1711a205e:/# nano
bash: nano: command not found
root#69f1711a205e:/# pico
bash: pico: command not found
root#69f1711a205e:/# vi
bash: vi: command not found
root#69f1711a205e:/# vim
bash: vim: command not found
root#69f1711a205e:/# emacs
bash: emacs: command not found
root#69f1711a205e:/#
How do I edit files?
As in the comments, there's no default editor set - strange - the $EDITOR environment variable is empty. You can log in into a container with:
docker exec -it <container> bash
And run:
apt-get update
apt-get install vim
Or use the following Dockerfile:
FROM confluent/postgres-bw:0.1
RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "vim"]
Docker images are delivered trimmed to the bare minimum - so no editor is installed with the shipped container. That's why there's a need to install it manually.
EDIT
I also encourage you to read my post about the topic.
If you don't want to add an editor just to make a few small changes (e.g., change the Tomcat configuration), you can just use:
docker cp <container>:/path/to/file.ext .
which copies it to your local machine (to your current directory). Then edit the file locally using your favorite editor, and then do a
docker cp file.ext <container>:/path/to/file.ext
to replace the old file.
You can use cat if it's installed, which will most likely be the case if it's not a bare/raw container. It works in a pinch, and ok when copy+pasting to a proper editor locally.
cat > file
# 1. type in your content
# 2. leave a newline at end of file
# 3. ctrl-c / (better: ctrl-d)
cat file
cat will output each line on receiving a newline. Make sure to add a newline for that last line. ctrl-c sends a SIGINT for cat to exit gracefully. From the comments you see that you can also hit ctrl-d to denote end-of-file ("no more input coming").
Another option is something like infilter which injects a process into the container namespace with some ptrace magic: https://github.com/yadutaf/infilter
To keep your Docker images small, don't install unnecessary editors. You can edit the files over SSH from the Docker host to the container:
vim scp://remoteuser#containerip//path/to/document
You can use cat if installed, with the > caracter.
Here is the manipulation :
cat > file_to_edit
#1 Write or Paste you text
#2 don't forget to leave a blank line at the end of file
#3 Ctrl + C to apply configuration
Now you can see the result with the command
cat file
For common edit operations I prefer to install vi (vim-tiny), which uses only 1491 kB or nano which uses 1707 kB.
In other hand vim uses 28.9 MB.
We have to remember that in order for apt-get install to work, we have to do the update the first time, so:
apt-get update
apt-get install vim-tiny
To start the editor in CLI we need to enter vi.
You can open existing file with
cat filename.extension
and copy all the existing text on clipboard.
Then delete old file with
rm filename.extension
or rename old file with
mv old-filename.extension new-filename.extension
Create new file with
cat > new-file.extension
Then paste all text copied on clipboard, press Enter and exit with save by pressing ctrl+z. And voila no need to install any kind of editors.
Sometime you must first run the container with root:
docker exec -ti --user root <container-id> /bin/bash
Then in the container, to install Vim or something else:
apt-get install vim
I use "docker run" (not "docker exec"), and I'm in a restricted zone where we cannot install an editor. But I have an editor on the Docker host.
My workaround is: Bind mount a volume from the Docker host to the container (https://docs.docker.com/engine/reference/run/#/volume-shared-filesystems), and edit the file outside the container. It looks like this:
docker run -v /outside/dir:/container/dir
This is mostly for experimenting, and later I'd change the file when building the image.
After you shelled to the Docker container, just type:
apt-get update
apt-get install nano
You can just edit your file on host and quickly copy it into and run it inside the container. Here is my one-line shortcut to copy and run a Python file:
docker cp main.py my-container:/data/scripts/ ; docker exec -it my-container python /data/scripts/main.py
If you use Windows container and you want change any file, you can get and use Vim in Powershell console easily.
To shelled to the Windows Docker container with PowerShell:
docker exec -it <name> powershell
First install Chocolatey package manager
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression;
Install Vim
choco install vim
Refresh ENVIRONMENTAL VARIABLE
You can just exit and shell back to the container
Go to file location and Vim it vim file.txt
See Stack Overflow question
sed edit file in place
It would be a good option here, if:
To modify a large file, it's impossible to use cat.
Install Vim is not allowed or takes too long.
My situation is using the MySQL 5.7 image when I want to change the my.cnf file, there is no vim, vi, and Vim install takes too long (China Great Firewall). sed is provided in the image, and it's quite simple. My usage is like
sed -i /s/testtobechanged/textwanted/g filename
Use man sed or look for other tutorials for more complex usage.
It is kind of screwy, but in a pinch you can use sed or awk to make small edits or remove text. Be careful with your regex targets of course and be aware that you're likely root on your container and might have to re-adjust permissions.
For example, removing a full line that contains text matching a regex:
awk '!/targetText/' file.txt > temp && mv temp file.txt
(More)
If you can only shell into container with bin/sh (in case bin/bash doesn't work)
and apt or apt-get doesn't work in the container, check whether apk is installed by entering apk in command prompt inside the container.
If yes, you can install nano as follows:
apk add nano
then nano will work as usual
An easy way to edit a few lines would be:
echo "deb http://deb.debian.org/debian stretch main" > sources.list
You can install nano
yum install nano
You can also use a special container which will contain only the command you need: Vim. I chose python-vim. It assumes that the data you want to edit are in a data container built with the following Dockerfile:
FROM debian:jessie
ENV MY_USER_PASS my_user_pass
RUN groupadd --gid 1001 my_user
RUN useradd -ms /bin/bash --home /home/my_user \
-p $(echo "print crypt("${MY_USER_PASS:-password}", "salt")" | perl) \
--uid 1001 --gid 1001 my_user
ADD src /home/my_user/src
RUN chown -R my_user:my_user /home/my_user/src
RUN chmod u+x /home/my_user/src
CMD ["true"]
You will be able to edit your data by mounting a Docker volume (src_volume) which will be shared by your data container (src_data) and the python-vim container.
docker volume create --name src_volume
docker build -t src_data .
docker run -d -v src_volume:/home/my_user/src --name src_data_1 src_data
docker run --rm -it -v src_volume:/src fedeg/python-vim:latest
That way, you do not change your containers. You just use a special container for this work.
First login as root :
docker run -u root -ti bash
Type following commands:
apt-get update &&
apt-get install nano
docker comes up with no editors. so simply install vim, 36MB space don't kill your docker!
Make sure to update the container before trying to install the editor.
apt-get update
apt-get install nano vi

MediaWiki Scribunto Lua error: Internal error: The interpreter exited with status 2

I have done a fresh installation on my local development machine of MediaWiki 1.24.2.
I have installed Scribunto and checked it is installed correctly on the list of extensions.
I'm getting an error when I try and create an InfoBox. The error is:
Lua error: Internal error: The interpreter exited with status 2
These are the steps I have taken the following steps to try and fix this.
I have been to the Mediawiki Scribunto page
I have added these lines to my LocalSettings.php file:
$wgScribuntoEngineConf['luastandalone']['memoryLimit'] = 209715200; # bytes
$wgMaxShellMemory = 204800; # in KB
This has not fixed things. I'm a but confused as to how to switch on error logging. The help page just says:
Assigning a file path to $wgScribuntoEngineConf['luastandalone']['errorFile'] and examining that output can be valuable in diagnosing memory allocation errors.
How do I assign a file path? - Solved Thanks for the help with this.
I enclose a [link][2] to my php.ini file and my LocalSettings.php file (Zipped together)
UPDATE - I have now managed to add a log file and the error in the log file is:
/var/www/extensions/Scribunto/engines/LuaStandalone/binaries/lua5_1_5_linux_32_generic/lua: Syntax error: "(" unexpected
UPDATE TWO
These are the full steps I take to replicate the error:
Start by checking for any package updates available and installing them
sudo apt-get update
sudo apt-get upgrade
Now install Apache, PHP and MySQL
sudo apt-get install apache2 -y
sudo apt-get install php5 libapache2-mod-php5 -y
sudo apt-get install mysql-server php5-mysql -y
sudo apt-get install php-apc php5-intl imagemagick
sudo apt-get install phpmyadmin
We can check the internal IP address of our Raspberry Pi with the following command (Make a note of it)
hostname -I
We can now create a database for our new MediaWIki installation. Start by logging in as root using the password you created earlier
mysql -u root -p
Here we are adding database=mediawikidb user=mediawikiuser and password=mediawikipassword:
CREATE DATABASE mediawikidb;
CREATE USER mediawikiuser#localhost IDENTIFIED BY 'mediawikipassword';
GRANT index, create, select, insert, update, delete, alter, lock tables on mediawikidb.* TO mediawikiuser#localhost;
Now we can make some changes to php.ini so we can increase the maximum file size and memory limit
cd /etc/php5/apache2/
nano php.ini
Replace 'upload_max_filesize = 2M' with 'upload_max_filesize = 64M'
Replace 'post_max_size = 8M' with 'post_max_size = 64M'
Save the file
Now we are going to empty the /var/www folder and change its ownership to pi
cd /var/www
sudo chown pi: .
sudo rm *
Now we can download MediaWiki, uncompress it and copy it into /var/www
mkdir /var/www/mediawiki
wget http://releases.wikimedia.org/mediawiki/1.24/mediawiki-1.24.2.tar.gz
tar -xvzf mediawiki-*.tar.gz
sudo mv mediawiki-*/* /var/www/
Now we can restart the relevant services
sudo service apache2 restart
sudo service mysql restart
Now open a browser and go to localhost and start the installation
To Complete Installation copy LocalSettings.php to /var/www/mediawiki
Now install Scribunto
Download from http://www.mediawiki.org/wiki/Special:ExtensionDistributor/Scribunto
tar -xzf Scribunto-REL1_24-b060fbd.tar.gz -C /var/www/mediawiki/extensions
sudo nano /etc/mediawiki/LocalSettings.php
add these lines at the end of the file and save
require_once "$IP/extensions/Scribunto/Scribunto.php";
$wgScribuntoDefaultEngine = 'luastandalone';
$wgScribuntoEngineConf['luastandalone']['memoryLimit'] = 209715200; # bytes
$wgMaxShellMemory = 204800; # in KB
$wgScribuntoEngineConf['luastandalone']['errorFile'] = '/var/tmp/luaerror.log';
chmod -R 777 /var/www/mediawiki/extentions/Scribunto/engines/LuaStandalone/
Now visit 'http://en.wikipedia.org/wiki/Special:Export' and enter Template:Infobox in the big box. Tick all three boxes and click Export
Open the file in Notepad or similar and do a find and replace text/plain with CONTENT_FORMAT_TEXT
Login to MediaWiki and go to Special:Import
Once everything has imported correctly go to the homepage and enter this at the top of the page:
{{Infobox
|title = test Infobox
|header1 = Main Heading
|header2 = First set of data
|label2 = Label
|data2 = Data
|header3 = Remove this line (optional)
|label3 = More Label
|data3 = More data
}}
Many thanks
Finally fixed. I did:
sudo apt-get install lua
Then added the following to my LocalSettings.php
$wgScribuntoEngineConf['luastandalone']['luaPath'] = '/usr/bin/lua5.1';
I assume the lua binary included with Scribunto is not ok with the Raspberry Pi?

How to start bitnami rubystack environment on Linux

On windows, I use file user Bitnami Rubystack to start the environment.
How can I start it on Linux Ubuntu?
This is for anyone that finds there way to this question in the future.
You need to go to the /home/bitnami/stack folder.
bitnami#ubuntu:~$ cd /home/bitnami/stack
Now run sudo ./rubyconsole
bitnami#ubuntu:~/stack$ sudo ./rubyconsole
You will be asked for the bitnami user password. Enter bitnami.
[sudo] password for bitnami: bitnami
Now the prompt will change to indicate you are in the bitnami ruby console. See below.
Now go to the projects folder.
root#ubuntu:/opt/bitnami# cd projects
root#ubuntu:/opt/bitnami/projects#
Now you can create your rails project.
To autorun at startup for Ubuntu Precise:
sudo -i
cd /etc/init.d/
ln -s /opt/rubystack-1.9.3-24/ctlscript.sh bitnami-rubystack
chmod +x bitnami-rubystack
update-rc.d bitnami-rubystack defaults
update-rc.d bitnami-rubystack enable
To remove:
sudo update-rc.d -f bitnami-rubystack remove
I began with the instructions from the Bitnami wiki, but they didn't seem to work out of the box: http://wiki.bitnami.com/Native_Installers_Quick_Start_Guide#How_to_start_automatically_the_Stack_on_Linux.3f
If you want to start manually:
sudo -i
cd /opt/rubystack-1.9.3-24
chmod +x manager-linux-x64.run
./manager-linux-x64.run

Resources