Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: rpc_do_call #1

Open
wants to merge 315 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
315 commits
Select commit Hold shift + click to select a range
a46624b
fix typo
Feb 7, 2018
c216a9f
add information readme
Feb 7, 2018
12b288c
add information
Feb 8, 2018
18e1283
add information readme
Feb 8, 2018
fb6b009
add information readme
Feb 8, 2018
498f46f
add git
Feb 8, 2018
7d70fe0
update btc/bch wallet
Feb 10, 2018
e233eb1
add ltc donattion
Feb 10, 2018
98dae1d
remove ltc wallet
Feb 10, 2018
8374893
add info readme
Feb 12, 2018
9953218
fix package compilation crypto
Feb 13, 2018
6b74958
fix typo package crypto
Feb 13, 2018
b897e4c
fix error downloading package compil crypto
Feb 13, 2018
b40f29d
fix typo
Feb 13, 2018
85c1e05
fix typo
Feb 13, 2018
cec64ad
add sleep after package crypto
Feb 13, 2018
7c79bb4
fix typo
Feb 13, 2018
0ea5d51
fix typo
Feb 13, 2018
331158a
add info readme
Feb 15, 2018
ba441b7
add compil script
Feb 15, 2018
518648a
fix error
Feb 17, 2018
e09cb42
add condition
Feb 17, 2018
42ce15f
delete compil.sh for update
Feb 17, 2018
6324d51
add compil script
Feb 17, 2018
c2343da
fix typo and add condition
Feb 17, 2018
d5776ca
fix typo compil.sh
Feb 17, 2018
9cbed88
add info compil.sh
Feb 17, 2018
7ae5bdb
update readme
Feb 18, 2018
a3fb805
add all firewall rules algo
Feb 18, 2018
58c54a0
Add eth donation
Feb 19, 2018
b255355
Added fix for some coins
mario1987 Apr 30, 2018
ef11f74
Update README.md
May 9, 2018
48d1e97
Update README.md
Jun 4, 2018
42b2232
Update install.sh
Jun 12, 2018
8abcfc0
Update README.md
Jun 12, 2018
3fc35f4
Update README.md
Jun 12, 2018
42d405f
change to systemd
Jun 12, 2018
58058f9
update to systemd
Jun 12, 2018
45c526e
fix typo
Jun 12, 2018
63ea83b
Merge pull request #1 from xavatar/update
Jun 12, 2018
a12855e
add nginx log + fix typo
Jun 14, 2018
08e8753
add info 18.04 github
Jun 14, 2018
632cc89
update readme
Jun 14, 2018
82ae2bf
fix typo
Jun 25, 2018
338bbea
fix typo log nginx
Jun 25, 2018
a93558e
fix typo reload php-fpm
Jun 25, 2018
f6936c1
fix typo
Jun 25, 2018
56f7a9a
fix typo start service php-fpm
Jun 25, 2018
be8aec2
fix typo
Jun 26, 2018
e812ffa
fix typo
Jun 26, 2018
f1c9aab
fix typo
Jun 26, 2018
ebf0876
Merge pull request #4 from mario1987/master
Jun 26, 2018
8912028
Fix Typo
Jun 26, 2018
1b73a52
Add information IP (admin panel)
Jun 26, 2018
66ec6d7
add info server name
Jun 26, 2018
47c0c29
add info admin panel
Jun 30, 2018
42038bb
Update README.md
Jun 30, 2018
72e07d2
Update compil.sh
Jun 30, 2018
56a735a
Update README.md
Jul 7, 2018
e69300b
Update README.md
Jul 7, 2018
5be598f
Update README.md
Jul 7, 2018
4b91d1f
Update README.md
Jul 8, 2018
ec6f15f
update typo
xavatar Oct 14, 2018
cddc62e
update date
xavatar Oct 14, 2018
32fee1a
update typo
xavatar Oct 14, 2018
d92d845
Update README.md
xavatar Mar 1, 2020
aeb612c
add gettext package to compil
xavatar Apr 4, 2020
7fdf4ee
Create packagecompil.sh
xavatar Apr 4, 2020
12225ba
Update compil.sh
xavatar Apr 4, 2020
ed427e0
typo
xavatar Apr 4, 2020
06fa0df
Create install-test
xavatar Apr 7, 2020
ecaf49b
create test
xavatar Apr 7, 2020
c30a290
fix typo
xavatar Apr 8, 2020
d3170d5
change name
xavatar Apr 8, 2020
fbe7cbd
Executable!
xavatar Apr 8, 2020
2cddcfb
make exec
xavatar Apr 8, 2020
47a54f6
Executable!
xavatar Apr 8, 2020
2ddf904
re exec
xavatar Apr 8, 2020
425c893
made a file executable
xavatar Apr 8, 2020
2c1cadc
add function.sh
xavatar Apr 8, 2020
cf4e09a
made function.sh executable
xavatar Apr 8, 2020
da0ddef
test change
xavatar Apr 8, 2020
5c6e4bd
fck executable
xavatar Apr 8, 2020
60a413d
add function
xavatar Apr 8, 2020
dbb143a
add function.sh
xavatar Apr 8, 2020
6e7b46c
Update install-test.sh
xavatar Apr 8, 2020
97d76f0
fix typo
xavatar Apr 8, 2020
17e7e80
change php version to 7.3
xavatar Apr 8, 2020
147866a
add done php7.3
xavatar Apr 8, 2020
50fdff6
fix typo
xavatar Apr 8, 2020
4b54046
Create prerequisite.sh
xavatar Apr 8, 2020
2b8fd73
update
xavatar Apr 8, 2020
a38d1bc
Merge branch 'master' of https://github.com/xavatar/yiimp_install_scrypt
xavatar Apr 8, 2020
da44ba1
Create getip.sh
xavatar Apr 8, 2020
7a97a54
add repo php7.3
xavatar Apr 8, 2020
ee517df
add apt update before php7.3
xavatar Apr 8, 2020
43e851b
typo
xavatar Apr 8, 2020
72eefee
chg for test
xavatar Apr 8, 2020
995e5ac
chg rep fct
xavatar Apr 8, 2020
393f490
Create editconf.py
xavatar Apr 8, 2020
a44343d
chg fct
xavatar Apr 8, 2020
aafb5a2
Merge branch 'master' of https://github.com/xavatar/yiimp_install_scrypt
xavatar Apr 8, 2020
cb18efa
fix typo
xavatar Apr 8, 2020
7a32a41
fix rep fct
xavatar Apr 8, 2020
89c467c
update systemcrl start/restart/reload
xavatar Apr 8, 2020
4a80b8e
fix systemctl
xavatar Apr 8, 2020
33a383d
chg sleep php-fpm
xavatar Apr 8, 2020
633a8aa
variable repo yiimp
xavatar Apr 8, 2020
6b3f9a3
some chg
xavatar Apr 8, 2020
cc867bf
chg typo
xavatar Apr 8, 2020
a1e357a
fix typo
xavatar Apr 8, 2020
95bb9b6
remove aptitude
xavatar Apr 8, 2020
7ced470
fix typo
xavatar Apr 8, 2020
2b3a0a5
remove apt-get
xavatar Apr 8, 2020
e007acb
chg typo
xavatar Apr 8, 2020
99c17b6
update question
xavatar Apr 8, 2020
e83619f
fix double make stratum
xavatar Apr 8, 2020
aaa5cbe
update date
xavatar Apr 8, 2020
0ce269a
Update install-test.sh
xavatar Apr 8, 2020
8df3b05
add version yiimp
xavatar Apr 8, 2020
327e104
Merge branch 'master' of https://github.com/xavatar/yiimp_install_scrypt
xavatar Apr 8, 2020
ce09d2e
fix typo
xavatar Apr 8, 2020
3ef8a1c
fix yiimp version
xavatar Apr 8, 2020
525cd18
add version
xavatar Apr 8, 2020
d93db0a
add info
xavatar Apr 8, 2020
a68c86e
add clear
xavatar Apr 8, 2020
df7f0c2
add inform
xavatar Apr 8, 2020
5de3958
Merge branch 'master' of https://github.com/xavatar/yiimp_install_scrypt
xavatar Apr 8, 2020
5a6667d
fix yiimpver
xavatar Apr 8, 2020
02e77c2
fix done creating server
xavatar Apr 8, 2020
d6573e2
fix yiimp ver
xavatar Apr 8, 2020
1916cfa
fix typo + add end information
xavatar Apr 8, 2020
3ec41c1
fix typo
xavatar Apr 8, 2020
29362fe
remove select gityiimp + remove choice admin panel
xavatar Apr 8, 2020
9db9b72
fix typo prerequisite
xavatar Apr 8, 2020
51237ec
remove time zone
xavatar Apr 8, 2020
d4f50b3
prevent apache remove
xavatar Apr 8, 2020
625fc05
fix typo + add echo to find error sed
xavatar Apr 9, 2020
5250a5c
add sudo sed for fix yiimp rootdir
xavatar Apr 9, 2020
ed214f5
add verif process
xavatar Apr 9, 2020
83ab852
typo
xavatar Apr 9, 2020
b918b2f
typo
xavatar Apr 9, 2020
259c9b5
typo
xavatar Apr 9, 2020
80f3d81
Update README.md
xavatar Apr 9, 2020
cb98bf8
fix pool.conf
xavatar Apr 9, 2020
ee7fdd3
Merge branch 'master' of https://github.com/xavatar/yiimp_install_scrypt
xavatar Apr 9, 2020
4e7553a
remove php7.1-mcrypt
xavatar Apr 9, 2020
74d9281
fix typo phpenmod mbstring
xavatar Apr 9, 2020
67b92e4
fix typo
xavatar Apr 9, 2020
1b97455
test extension php
xavatar Apr 9, 2020
ac8e30b
Update install-test.sh
xavatar Apr 9, 2020
674e123
fix permission
xavatar Apr 9, 2020
671dbb5
fix permission
xavatar Apr 9, 2020
42b1c22
add reboot final install
xavatar Apr 9, 2020
98ee318
fix permission
xavatar Apr 9, 2020
f442846
fix permission
xavatar Apr 9, 2020
833a8ea
fix permission
xavatar Apr 9, 2020
f93627a
fix permission
xavatar Apr 9, 2020
1b6696c
fix typo
xavatar Apr 9, 2020
1b0e79e
fix typo
xavatar Apr 9, 2020
ab070a4
update serverconfig.php
xavatar Apr 9, 2020
355e97b
chg serverconfig.php
xavatar Apr 9, 2020
496df8d
add web rdme
xavatar Apr 9, 2020
df0f2a5
fix permission + typo
xavatar Apr 9, 2020
678b5ce
Merge branch 'master' of https://github.com/xavatar/yiimp_install_scrypt
xavatar Apr 9, 2020
d6ed353
test add support ubun 18x
xavatar Apr 9, 2020
0845bb0
move result process ufw fail2
xavatar Apr 9, 2020
15454fb
advert to chg Panel Admin address
xavatar Apr 9, 2020
25f83f2
update fck perm
xavatar Apr 9, 2020
02d140b
fix typo
xavatar Apr 9, 2020
46e56e5
another chg perm
xavatar Apr 9, 2020
9452fdf
remove php-auth ubun18
xavatar Apr 9, 2020
0a79ada
some fix (githubrepo + banner)
xavatar Apr 9, 2020
71e6e05
some fix (/root/backup + crontab screen + copy screen-scrypt.sh
xavatar Apr 10, 2020
db66fff
Create delcoin.sh
xavatar Apr 10, 2020
26cb607
fix perm rep /root/backup
xavatar Apr 10, 2020
b663c3a
Create coin.list
xavatar Apr 10, 2020
1d98948
add coin 007
xavatar Apr 10, 2020
194662f
conf backup sql
xavatar Apr 10, 2020
ff990bf
chg conf sauv sql
xavatar Apr 10, 2020
29f80d9
try fix error backup frontend
xavatar Apr 10, 2020
ce8cdac
Create install-test2
xavatar Apr 10, 2020
a9060f7
test
xavatar Apr 10, 2020
cc000ce
test install 2
xavatar Apr 10, 2020
8d23fd8
fix error screen main
xavatar Apr 10, 2020
ab0990e
add information
xavatar Apr 10, 2020
9e5614b
add no passwd sudo
xavatar Apr 10, 2020
1a96ef9
some fix (add crontab screen-scrypt,error save sql frontend...)
xavatar Apr 10, 2020
ab80d1d
fix typo
xavatar Apr 10, 2020
17c0a26
fix error rep sauv sql
xavatar Apr 10, 2020
6ac5585
remove choice yiimp
xavatar Apr 10, 2020
fdfbc02
fix typo
xavatar Apr 10, 2020
6bf5fb8
misc
xavatar Apr 10, 2020
9b7a3fd
update readme
xavatar Apr 10, 2020
bb912ba
modif readme
xavatar Apr 10, 2020
992ea76
update arbo
xavatar Apr 10, 2020
6e4a79d
move delcoin.sh
xavatar Apr 10, 2020
ba044cb
Create changelog
xavatar Apr 10, 2020
3986ae1
fix typo
xavatar Apr 10, 2020
7a34cc1
typo
xavatar Apr 10, 2020
1a90c7d
add thanks cryptopool-builders
xavatar Apr 10, 2020
21963e7
chg name v01
xavatar Apr 10, 2020
79b0de7
Update changelog
xavatar Apr 10, 2020
9927f5d
Create RELEASE
xavatar Apr 10, 2020
64c474f
Update README.md
xavatar Apr 11, 2020
a0e6d13
add readme chg panel
xavatar Apr 11, 2020
1691c74
Merge branch 'master' of https://github.com/xavatar/yiimp_install_scrypt
xavatar Apr 11, 2020
0705150
Update README.md
xavatar Apr 11, 2020
c830be6
add inf
xavatar Apr 11, 2020
413550f
upd readme
xavatar Apr 11, 2020
5043804
move script screen to utils
xavatar Apr 11, 2020
6a9923a
Update changelog
xavatar Apr 11, 2020
8b6fc18
Update changelog
xavatar Apr 11, 2020
0d211b6
Update changelog
xavatar Apr 11, 2020
00ef8b4
chg name file utils
xavatar Apr 11, 2020
bdf29ed
Update README.md
xavatar Apr 11, 2020
4a80cb7
chg typo
xavatar Apr 12, 2020
16a148b
chg info
xavatar Apr 12, 2020
2620dd4
Update README.md
xavatar Apr 12, 2020
97233cc
update readme
xavatar Apr 12, 2020
29429b9
updt final info
xavatar Apr 12, 2020
023d9a6
fix blank
xavatar Apr 12, 2020
1f12535
fix typo
xavatar Apr 12, 2020
6dfcd05
chg address youtube video
xavatar Apr 12, 2020
0a11dba
fix typo
xavatar Apr 12, 2020
54ebedf
add speep5 before return service
xavatar Apr 12, 2020
5e88315
fix error screen main "backup sql frontend"
xavatar Apr 13, 2020
0c71485
some fix + cleanup code
xavatar Apr 13, 2020
a1737c6
miss -i sed "backup sql frontend"
xavatar Apr 13, 2020
c6d91d4
Merge pull request #21 from xavatar/premaster
xavatar Apr 13, 2020
ac83bad
Create install-oct18.sh
xavatar Apr 19, 2020
ceee7a6
Update install-v0.1.sh
xavatar Apr 19, 2020
8de0e15
Update install-v0.1.sh
xavatar Apr 19, 2020
5e44026
Update install-v0.1.sh
xavatar Apr 19, 2020
e8e9eba
Create install-debug.sh
xavatar Apr 19, 2020
06961fb
update install-debug & install-v0.1
xavatar Apr 19, 2020
8f715fc
Update install-v0.1.sh
xavatar Apr 19, 2020
6985cb0
fix typo
xavatar Apr 19, 2020
0e7ca45
add sleep after install nginx-mariadb-php
xavatar Apr 19, 2020
8b2ee41
upd readme
xavatar Apr 19, 2020
d757fd8
Update README.md
xavatar Apr 19, 2020
8cb5fc2
Rename install-oct18.sh to install-v0.11.sh
xavatar Apr 26, 2020
b08701b
Update README.md
xavatar Apr 29, 2020
7ed2506
Hold update openssl
xavatar Apr 29, 2020
6994cad
hold update openssl
xavatar Apr 29, 2020
23c4065
hold update openssl
xavatar Apr 29, 2020
9593ed5
Rename install-v0.1.sh to install-v0.111.sh
xavatar Apr 29, 2020
6f9e75b
Update and rename install-v0.11.sh to install-v0.1.sh
xavatar Apr 29, 2020
6969694
Update install-v0.111.sh
xavatar Apr 29, 2020
7ad7472
Rename install-v0.111.sh to install-v0.11.sh
xavatar Apr 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 61 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,80 @@
# yiimp
Install script for yiimp on Ubuntu 16.04
# Yiimp_install_scrypt v0.2 (update Avril, 2020)

While I did add some server security to the script, it is every server owners responsibility to fully secure their own servers. After the installation you will still need to customize your serverconfig.php file to your liking, add your API keys, and build/add your coins to the control panel.
Site : https://www.xavatar.com

Discord : https://discord.gg/zcCXjkQ

TUTO Youtube (16.04 / 18.04 - Without SSL) : https://www.youtube.com/watch?v=qE0rhfJ1g2k

Official Yiimp (used in this script for Yiimp Installation): https://github.com/tpruvot/yiimp

Original Yiimp Installer : https://github.com/cryptopool-builders/multipool_original_yiimp_installer

There will be several wallets already in yiimp. These have nothing to do with the installation script and are from the database import from the yiimp github.

If you need further assistance we have a small but growing discord channel at https://discord.gg/uQ5wdTC
***********************************

*****Do not run the script as root*****
## Install script for yiimp on Ubuntu Server 16.04 / 18.04 (use Tpruvot's Yiimp)

This script has an interactive beginning and will ask for the following information:
USE THIS SCRIPT ON FRESH INSTALL UBUNTU Server 16.04 / 18.04 !

Your time zone
Server Name
Support Email Address
Server Admin Email Address
If you would like fail2ban installed
If you would like to have SSL (LetsEncrypt) installed - Your domain must be pointed to your server prior to running the script or SSL will fail to install.
New custom location for yiimp admin login.
Connect on your VPS =>
- apt update
- apt upgrade
- reboot
- adduser pool (pool it's just an example...)
- adduser pool sudo
- su - pool
- sudo apt -y install git
- git clone https://github.com/xavatar/yiimp_install_scrypt.git
- cd yiimp_install_scrypt/
- bash install.sh (DO NOT RUN THE SCRIPT AS ROOT or SUDO)
- At the end, you MUST REBOOT to finalize installation...

Once those questions are answered the script will then be fully automated for the rest of the install.
Finish !
- Go http://xxx.xxx.xxx.xxx or https://xxx.xxx.xxx.xxx (if you have chosen LetsEncrypt SSL). Enjoy !
- Go http://xxx.xxx.xxx.xxx/AdminPanel or https://xxx.xxx.xxx.xxx/AdminPanel to access Panel Admin

1. Update and Upgrade Ubuntu Packages
2. Install Aptitude
3. Install and configure Nginx
4. Install MariaDB with random root password
5. Install php7
6. Install various dev packages required for building blocknotify and stratum
7. Install SendMail
8. Install Fail2Ban if selected
9. Install and configur phpmyadmin with random password for phpmyadmin user
10. Clone yiimp build packages, create directory structure, set file permissions, and more
11. Update server clock
12. Install LetsEncrypt if selected
13. Create yiimp database, create 2 users with random passwords - passwords saved in ~/.my.cnf
14. Import the sql dumps from yiimp
15. Create base yiimp serverconfig.php file to get you going
16. Updates all directory permissions
If you are issue after installation (nginx,mariadb... not found), use this script : bash install-debug.sh (watch the log during installation)

This install script will get you 95% ready to go with yiimp. There are a few things you need to do after the main install is finished.
###### :bangbang: **Kudaraidee Install Script :**
- Instead Tpruvot's Yiimp, you can use the Kudaraidee's Repo Yiimp : git clone -b Kudaraidee https://github.com/Kudaraidee/yiimp.git
- It's an updated Yiimp, with more algo, some fix....

You must update the following files:
###### :bangbang: **YOU MUST UPDATE THE FOLLOWING FILES :**
- **/var/web/serverconfig.php :** update this file to include your public ip (line = YAAMP_ADMIN_IP) to access the admin panel (Put your PERSONNAL IP, NOT IP of your VPS). update with public keys from exchanges. update with other information specific to your server..
- **/etc/yiimp/keys.php :** update with secrect keys from the exchanges (not mandatory)
- **If you want change 'AdminPanel' to access Panel Admin :** Edit this file "/var/web/yaamp/modules/site/SiteController.php" and Line 11 => change 'AdminPanel'

1. /var/web/serverconfig.php - update this file to include your public ip to access the admin panel. update with public keys from exchanges. update with other information specific to your server..
2. /etc/yiimp/keys.php - update with secrect keys from the exchanges.

After you add the missing information to those files then run:
bash main.sh
bash loop2.sh
bash block.sh
###### :bangbang: **IMPORTANT** :

To download and run
- The configuration of yiimp and coin require a minimum of knowledge in linux
- Your mysql information (login/Password) is saved in **~/.my.cnf**

curl -Lo install.sh https://raw.githubusercontent.com/crombiecrunch/yiimp_install_scrypt/master/install.sh
***********************************

bash install.sh
###### This script has an interactive beginning and will ask for the following information :

- Server Name (no http:// or www !!!!! Example : crypto.com OR pool.crypto.com OR 80.41.52.63)
- Are you using a subdomain (mypoolx11.crypto.com)
- Enter support email
- Set stratum to AutoExchange
- Your Public IP for admin access (Put your PERSONNAL IP, NOT IP of your VPS)
- Install Fail2ban
- Install UFW and configure ports
- Install LetsEncrypt SSL

If this helped you or you feel giving please donate BTC Donation: 16xpWzWP2ZaBQWQCDAaseMZBFwnwRUL4bD
***********************************

**This install script will get you 95% ready to go with yiimp. There are a few things you need to do after the main install is finished.**

While I did add some server security to the script, it is every server owners responsibility to fully secure their own servers. After the installation you will still need to customize your serverconfig.php file to your liking, add your API keys, and build/add your coins to the control panel.

There will be several wallets already in yiimp. These have nothing to do with the installation script and are from the database import from the yiimp github.

Feel free to join our Discord channel at https://discord.gg/zdBbAQ
If you need further assistance we have a small but growing discord channel at https://discord.gg/zcCXjkQ

Crombie Crunch
If this helped you or you feel giving please donate :
- BTC Donation : 1C1hnjk3WhuAvUN6Ny6LTxPD3rwSZwapW7
- BCH Donation : 1PqjApUdjwU9k4v1RDWf6XveARyEXaiGUz
- ETH Donation : 0xc23E6902fF8Cd8878EDADE18Dc49B3505395F0a1
1 change: 1 addition & 0 deletions RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.2
20 changes: 20 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Yiimp Install Scrypt v0.2 // 10.04.2020
Thanks to cryptopool-builders !!!!!!!!

Information =>
* Works with Ubuntu Server 16.04 / 18.04
* Update PHP 7.3
* Change Aptitude by APT
* Remove question Panel Admin
* Remove question Time Zone
* Add screen-scrypt to crontab
* Add script to remove all coin (utils/delcoin.sh)

Fix =>
* Fix command cli « Yiimp » : OK
* Fix Backup SQL FrontEnd : OK (/var/yiimp/sauv)
* Fix Permission on some folder

Change =>
* /etc/screen-scrypt.sh = add to crontab (main,loop2,blocks,debug)
* /var/yiimp/sauv = Backup SQL FrontEnd
137 changes: 137 additions & 0 deletions conf/editconf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/python3
#
# This is a helper tool for editing configuration files during the setup
# process. The tool is given new values for settings as command-line
# arguments. It comments-out existing setting values in the configuration
# file and adds new values either after their former location or at the
# end.
#
# The configuration file has settings that look like:
#
# NAME=VALUE
#
# If the -s option is given, then space becomes the delimiter, i.e.:
#
# NAME VALUE
#
# If the -c option is given, then the supplied character becomes the comment character
#
# If the -w option is given, then setting lines continue onto following
# lines while the lines start with whitespace, e.g.:
#
# NAME VAL
# UE

import sys, re

# sanity check
if len(sys.argv) < 3:
print("usage: python3 editconf.py /etc/file.conf [-s] [-w] [-c <CHARACTER>] [-t] NAME=VAL [NAME=VAL ...]")
sys.exit(1)

# parse command line arguments
filename = sys.argv[1]
settings = sys.argv[2:]

delimiter = "="
delimiter_re = r"\s*=\s*"
comment_char = "#"
folded_lines = False
testing = False
while settings[0][0] == "-" and settings[0] != "--":
opt = settings.pop(0)
if opt == "-s":
# Space is the delimiter
delimiter = " "
delimiter_re = r"\s+"
elif opt == "-w":
# Line folding is possible in this file.
folded_lines = True
elif opt == "-c":
# Specifies a different comment character.
comment_char = settings.pop(0)
elif opt == "-t":
testing = True
else:
print("Invalid option.")
sys.exit(1)

# sanity check command line
for setting in settings:
try:
name, value = setting.split("=", 1)
except:
import subprocess
print("Invalid command line: ", subprocess.list2cmdline(sys.argv))

# create the new config file in memory

found = set()
buf = ""
input_lines = list(open(filename))

while len(input_lines) > 0:
line = input_lines.pop(0)

# If this configuration file uses folded lines, append any folded lines
# into our input buffer.
if folded_lines and line[0] not in (comment_char, " ", ""):
while len(input_lines) > 0 and input_lines[0][0] in " \t":
line += input_lines.pop(0)

# See if this line is for any settings passed on the command line.
for i in range(len(settings)):
# Check that this line contain this setting from the command-line arguments.
name, val = settings[i].split("=", 1)
m = re.match(
"(\s*)"
+ "(" + re.escape(comment_char) + "\s*)?"
+ re.escape(name) + delimiter_re + "(.*?)\s*$",
line, re.S)
if not m: continue
indent, is_comment, existing_val = m.groups()

# If this is already the setting, do nothing.
if is_comment is None and existing_val == val:
# It may be that we've already inserted this setting higher
# in the file so check for that first.
if i in found: break
buf += line
found.add(i)
break

# comment-out the existing line (also comment any folded lines)
if is_comment is None:
buf += comment_char + line.rstrip().replace("\n", "\n" + comment_char) + "\n"
else:
# the line is already commented, pass it through
buf += line

# if this option oddly appears more than once, don't add the setting again
if i in found:
break

# add the new setting
buf += indent + name + delimiter + val + "\n"

# note that we've applied this option
found.add(i)

break
else:
# If did not match any setting names, pass this line through.
buf += line

# Put any settings we didn't see at the end of the file.
for i in range(len(settings)):
if i not in found:
name, val = settings[i].split("=", 1)
buf += name + delimiter + val + "\n"

if not testing:
# Write out the new file.
with open(filename, "w") as f:
f.write(buf)
else:
# Just print the new file to stdout.
print(buf)
Loading