Raspberry Pi config - read parameters from a seperate file - linux

I have a raspberry pi configured to boot chromium full screen which works great. However, I want my non-techy user to update the website by simply editing a file on the desktop.
/etc/xdg/lxsession/LXDE-pi/autostart:
# Link to the settings file on the desktop
source /home/pi/Desktop/websetup.config
# start chromium
#chromium --noerrdialogs --kiosk $website --incognito
I would like to have a setup file on the desktop which my user can update the website and overscanning etc without directly editing any config files above:
i.e.
websetup.config:
# Enter website to show
webbsite=https://newWebsite.com
# Overscanning on = 1, turn off = 0
overscan=0
I, however, can output $website from a .sh bash but I cannot work out how to pass the value $website to chromium as I cannot pass the actual value

ok, I have managed to work it out. I created a script called run_chromium.sh:
##
## this file is referenced in: /etc/xdg/lxsession/LXDE-pi/autostart
##
## website to show
website=https://www.website.com
## 0=overscanning off, 1=on
overscanning=1
and I linked to this script in autostart:
/bin/bash /home/pi/Desktop/run_chromium.sh

Related

how to run the admin command prompt using python?

I want to run a script on the admin cmd prompt using python os.system
import os
import sys
import keyboard
import time
os.system('cls')
print('+'* 60)
os.system('netsh wlan set hostednetwork mode=allow ssid=test3 key=987654321')
time.sleep(2)
p = input('')
keyboard.press_and_release('enter')
print('#' * 60)
os.system('netsh wlan start hostednetwork')
time.sleep(2)
keyboard.press_and_release('enter')
v = input('')
How can I call the admin cmd prompt ?
Thank you in advance
I found a way to make this happen
so my idea is to to create script to share wifi using python, and the problem is you have to execute the script using admin command prompt. and to solve that, follow my steps:
1 - create the python script for the commands(copy mine in the original question)
2 - create a simple text file like this one
pause
python name.py
pause
3 - save it under the extension of " .bat " (example.bat)
4 - go to your system directory (mine is "C:\Windows\System32")
5 - copy the the batch file there
6 - create a shortcut for this batch file (it will ask to be in your desktop, click OK)
7 - go to the properties of this shortcuted file click on advanced and give it the admin
access - click OK
8- copy or cut your script.py file to the same directory (mine is "C:\Windows\System32")
and that's it, just launch your batch file in the desktop and here you go everything works fine.

Whoops! We seem to have hit a snag. Please try again later

Whoops! We seem to have hit a snag. Please try again later.
Codeigniter 4 shows an error when I run the CI4 application, How I resolve?
Changes:
public $baseURL = 'http://ci.local';
public $baseURL = 'http://localhost:8080';
public $indexPage = '';
This work for me try it
Go to app directory then to boot directory you will see production.php file.
That is:
app => Config => Boot => production.php
Change the ini_set('display_errors', '0') to ini_set('display_errors', '1').
Warning: When in production change back to initial ini_set('display_errors', '0')
Or
you can rename your file env in your project directory to .env after that open it and edit.
Search for # CI_ENVIRONMENT = production remove # and change production to development
Warning: When in production change back to initial CI_ENVIRONMENT = development to CI_ENVIRONMENT = production
For those experiencing intl error go to where your php installation directory edit the php.ini file remove semi-colon ";" from ;extension=intl to extension=intl. save the file and restart your server. I think this will solve that error. This particular editing of my php.ini was on php 7.2 - 8.1 so I haven't check other version of php lesser than these versions which Codeigniter 4 does not support
After installing CodeIgniter 4 when you run the app then you will get an error like this
To know the error go to the app/Config/Boot/production.php and set display_errors to 1 as below
ini_set('display_errors', '1');
Now, you will see the actual error below
Nothing to worry about it. The app needs permission. Assign the permission like as below
sudo chmod -R 777 project_name
Assume that your root folder of your CI4 project is rootproject.
Edit rootproject/.env file.
On line 17 change from:
# CI_ENVIRONMENT = production
to:
CI_ENVIRONMENT = development
Save it.
Refresh your browser that pointing to your CI4 project.
It should give you many error messages.
If there is something written as CacheException, than your cache folders are not writable.
Make it writable;
Ubuntu:
chown -Rv www-data rootproject/writable
CentOS:
chown -Rv apache rootproject/writable
Easy way:
chmod 777 -Rv rootproject/writable
In your CI4 project root, create a file named .env. It should be in the same directory as system, app e.t.c
Then, add this CI_ENVIRONMENT = development
The problem is most likely due to missing extensions. Check server requirements here.. Check your php.ini file and make sure intl and mbstring are enabled.
I had the same problem, I have a simple solution for Mac.
- in the project folder, go to 'writable'
- select all the folders contained and click on 'get information'
- go share and permissions
- in 'everyone' select 'read and write'
That's it! refresh the page
Try This
Open [xampp]/php/php.ini
Search for ;extension=intl and remove the ;
Save the php.ini file and restart Apache(server).
In Root folder change: env to .env
Change # CI_ENVIRONMENT = production to CI_ENVIRONMENT = development (ensure it is uncommented)
Your error may be related to the knit.php file.
Go to System/Third Party and change: knit.php to Knit.php (Capital)
Reload.
For those using XAMPP in MacOS:
You don't need to change the ownership of the writable directory. You only need to change permission to entire directory:
chmod -R 777 writable
When you change # CI_ENVIRONMENT = production to CI_ENVIRONMENT = development don't forget of rename the env file to .env else it will not work.
You're running in the production environment and need to change it to a Development or Testing environment to see the error messages within the browser.
There are a few ways to do this, but adding:
SetEnv CI_ENVIRONMENT development
To the Apache httpd.config file is what worked for me.
_t
I got the answer for this query; just follow these steps:
From the command line, at your project root just hit this
php spark serve
Then hit this on your browser http://localhost:8080/
Enjoy your Latest CI.
Not sure what the desired answer is, but:
If you are asking to see what is the actual error is - either change
your environment to testing/development (as suggested so far) or you
can check your logs - writable/logs/log-.php
If you wish to solve the error, we will need more information, like have
you setup virtual hosts, have you change .htaccess file in public
folder, etc. Otherwise we will be most likely betting (I bet it's virtual hosts).
In any case, a copy of the displayed error (after changing evnironment) or log file will be useful.
You can check logs file on writable/logs find error information,
If your logs information like :
CRITICAL - 2020-04-19 17:44:55 --> Invalid file: template/header.php
#0 F:\xampp\htdocs\ppdb\vendor\codeigniter4\framework\system\View\View.php(224): CodeIgniter\Exceptions\FrameworkException::forInvalidFile('template/header...')
And go fix your error, in my case i am wrong typed name on controller file
In Codeigniter 4 source code have a folder named writable, just update it's access permission. Sometimes it'll help to get rid of Whoops. Also can check the video for Ubuntu / Linux

How to setup syslog in yocto?

I like to configure syslog. It seems that are more than one way to set up syslog. I am asking for the common way/steps to do that.
I have several use cases. To simplify I like to ask how to configure syslog to write an infinity long log file in /var/log/.
Following steps:
1.) configure what messages
1.1) create own "syslog.conf" (define /var/log/myLog)
1.2) append it to "recipes-core/busybox"
2.) configure how to log
??
I found two possible places to do that:
#meta-poky
-> "meta-poky/recipes-core/busybox/busybox/poky-tiny/defconfig"
#
# System Logging Utilities
#
CONFIG_SYSLOGD=y
CONFIG_FEATURE_ROTATE_LOGFILE=y
CONFIG_FEATURE_REMOTE_LOG=y
CONFIG_FEATURE_SYSLOGD_DUP=y
CONFIG_FEATURE_SYSLOGD_CFG=y
CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=256
CONFIG_FEATURE_IPC_SYSLOG=y
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=16
CONFIG_LOGREAD=y
CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING=y
CONFIG_KLOGD=y
CONFIG_FEATURE_KLOGD_KLOGCTL=y
CONFIG_LOGGER=y
add/change:
"CONFIG_FEATURE_ROTATE_LOGFILE=n" by adding that line to meta-mylayer/conf/layer.conf"
etc.
???
# "/etc/syslog-startup.conf"
# This configuration file is used by the busybox syslog init script,
# /etc/init.d/syslog[.busybox] to set syslog configuration at start time.
DESTINATION=file # log destinations (buffer file remote)
LOGFILE=/var/log/messages # where to log (file)
REMOTE=loghost:514 # where to log (syslog remote)
REDUCE=no # reduce-size logging
DROPDUPLICATES=no # whether to drop duplicate log entries
#ROTATESIZE=0 # rotate log if grown beyond X [kByte]
#ROTATEGENS=3 # keep X generations of rotated logs
BUFFERSIZE=64 # size of circular buffer [kByte]
FOREGROUND=no # run in foreground (don't use!)
#LOGLEVEL=5 # local log level (between 1 and 8)
In the systemV init script "/etc/init.d/syslog.bussybox" the file "/etc/syslog-startup.con" is read and used for configuration.
System behaviour:
When running my system, the log wraps when the logfile reaches 200kBytes. One logfile + one log-rotate file is generated.
Any ideas how to archive that syslog writes an infinite long log-file?
I am working on the Yocto krogoth branch + meta-atmel / meta_openembedded (# krogoth too).
By checking the sources of syslog and busybox I found a possible solution. This solution shows how to configure syslog to log in two logs with max 10MByte:
1.) get valid syslog build config
1.1) download busybox -> git/busybox
1.2) build busybox via bitbake -> bitbake busybox
1.3) copy defconfig file to downloaded busybox -> cp /defconfig git/busybox/
1.4) make menueconfig
1.5) goto "System Logging Utilities"
1.6) deselect klogd because it can colide with printk
1.7) save to "defconfig"
#
# System Logging Utilities
#
# CONFIG_KLOGD is not set
# CONFIG_FEATURE_KLOGD_KLOGCTL is not set
CONFIG_LOGGER=y
CONFIG_LOGREAD=y
CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING=y
CONFIG_SYSLOGD=y
CONFIG_FEATURE_ROTATE_LOGFILE=y
CONFIG_FEATURE_REMOTE_LOG=y
CONFIG_FEATURE_SYSLOGD_DUP=y
CONFIG_FEATURE_SYSLOGD_CFG=y
CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=256
CONFIG_FEATURE_IPC_SYSLOG=y
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=64
CONFIG_FEATURE_KMSG_SYSLOG=y
2.) setup your log config
Create "syslog.conf" and enter the rules:
This is an example:
#
# /etc/syslog.conf Configuration file for busybox's syslogd utility
#
kern.notice /var/log/messages
#
# my software messages
#
user.err /var/log/mySWError
user.* /var/log/mySWFull
local0.* /var/log/mySWFull
local0.err /var/log/mySWError
#
#this prevents from logging to default log file (-O FILE or /var/log/messages)
#
*.* /dev/null
3.) modify configuration for the busybox syslog deamon
This example logs to files which are limited to 10 MBytes. If "ROTATESIZE" is not set syslog set the log filesize automatic to 200 kBytes. The content of "syslog-startup.conf" looks like:
# This configuration file is used by the busybox syslog init script,
# /etc/init.d/syslog[.busybox] to set syslog configuration at start time.
DESTINATION=file # log destinations (buffer file remote)
#LOGFILE=/var/log/messages # where to log (file)
REMOTE=loghost:514 # where to log (syslog remote)
REDUCE=no # reduce-size logging
DROPDUPLICATES=no # whether to drop duplicate log entries
ROTATESIZE=10000 # rotate log if grown beyond X [kByte]
#ROTATEGENS=3 # keep X generations of rotated logs
BUFFERSIZE=64 # size of circular buffer [kByte]
FOREGROUND=no # run in foreground (don't use!)
#LOGLEVEL=5 # local log level (between 1 and 8)
4.) get the configuration into yocto build
4.1) create following directory structure in your own layer(meta-custom):
meta-custom/recipes-core/
meta-custom/recipes-core/busybox/
meta-custom/recipes-core/busybox/busybox
4.2) copy into "meta-custom/recipes-core/busybox/busybox":
defconfig
syslog.conf
syslog-startup.conf
4.3) create in "meta-custom/recipes-core/busybox/" "busybox_1.24.1.bbappend". If you using an older/newer version of busybox you need to change the "1.24.1" number to yours. You can find your version in "/poky/meta/recipes-core/busybox/"
Add this two lines to this file:
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}/poky-tiny:"
5.) build your custom defined syslog
bitbake busybox
and transfer it into the rootfs of the image
bitbake core-image-minimal
Now it should work!
Adding to the Stefan Jaritz comment, you can skip the download step by just issuing
bitbake busybox -c devshell
Then running make menuconfig and getting the new config file from it. Note that this will use Yocto's defconfig by default, so you don't need to do worry about "what's this default config".

how to make tornado auto restart when certain files changes

I'm using Tornado working with Python 3 and Linux server, when I edit and save some text or XML files I want Tornado to restart itself. I checked the document and found the autoreload module and the watch function here.
It seems it only worked for pyo files. What can I do if I want it to reload when a certain URI is modified?
Setting the debug flag to True in settings forces Tornado to reload whenever a file is modified or whenever a URI is changed in app.py (or where ever you have defined your handlers). Tornado also automatically reloads template files so any changes in there will be seen instantly.
settings = {
'debug':True,
# other stuff
}
tornado.web.Application.__init__(self, handlers, **settings)
the file added must be an absolute path.
def addwatchfiles(*paths):
for p in paths:
autoreload.watch(os.path.abspath(p))
addwatchfiles('config.xml')
config.xml is at the same directory in where the server's python file start at.
You need to turn autoreload on:
tornado.autoreload.start()
tornado.autoreload.watch('myfile')
Complete example at https://gist.github.com/renaud/10356841

How to remove multiple virtual directories?

I need to remove a big amount of virtual directories, some of them don't have associated physical directories.
Ideas?
As you need to remove a large amount, I'm guessing you'll want to use some form of script.
IIS 6.0, using IISvdir.vbs( article # MSDN):
At the command prompt, use the cd command to change to the directory where the Iisvdir.vbs script is installed. The default location for this file is systemroot/system32/iisvdir.vbs.
At the command prompt, type:
cscript iisvdir.vbs /delete "Sample Web Site" VirtualDirectoryName.
Substitute your Web site name and virtual directory name as appropriate. If there are spaces in the Web site name, use quotation marks around the Web site name, as shown in the preceding example.
IIS 7 using AppCmd.exe (article # TechNet):
To remove a virtual directory, use the following syntax:
appcmd delete vdir /vdir.name: string
The variable vdir.namestring is the virtual path of the virtual directory.
For example, to remove a virtual directory named photos from the root application of a site named contoso, type the following at the command prompt, and then press ENTER:
appcmd delete vdir /vdir.name: contoso / photos
To remove a virtual directory named photos from an application named marketing in a site named contoso, type the following at the command prompt, and then press ENTER:
appcmd delete vdir /vdir.name: contoso / marketing / photos
HTH
You could also write an msbuild script to do this and use the msbuild extension pack which is available here. I have used this successfully to do exactly what you are saying for 100s of vdirs in iis 6 AND in iis 7.5.
Its pretty simple and took me longer to write the .proj file than it did to figure out how to do it.
have fun :)
the resultant msbuild target would look like as follows
<Target Name="IIS7VirtualDirectories:Delete">
<MSBuild.ExtensionPack.Web.Iis7Application
TaskAction="Delete"
Website="%(Application.WebsiteName)"
Applications="#(Application)"
MachineName="$(MachineName)"
ContinueOnError="false"/>
<MSBuild.ExtensionPack.Web.Iis7Website
TaskAction="DeleteVirtualDirectory"
Name="%(VirtualDirectory.WebsiteName)"
VirtualDirectories="#(VirtualDirectory)"
ContinueOnError="false"
MachineName="$(MachineName)"/>
</Target>
Where Application and VirtualDirectory are defined in an external proj file :)

Resources