mirror of https://github.com/Black-Gold/Learn
master
parent
d04bb3faf9
commit
87e02f78b9
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
import os
|
||||||
|
from aliyunsdkcore import client
|
||||||
|
from aliyunsdkcore.request import RpcRequest
|
||||||
|
|
||||||
|
product = "Domain"
|
||||||
|
version = "2016-05-11"
|
||||||
|
accesskey = "XXXXXXXXXXXXXXXXXXXX" # 请替换成自己的accesskey
|
||||||
|
accesspasswd = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX" # 请替换成自己的accesspasswd
|
||||||
|
|
||||||
|
|
||||||
|
def getip():
|
||||||
|
return os.popen("curl http://members.3322.org/dyndns/getip -s").read().replace('\n', '').replace('\r\n', '')
|
||||||
|
|
||||||
|
|
||||||
|
def getDNSrecords():
|
||||||
|
global product, version, accesskey, accesspasswd
|
||||||
|
clt = client.AcsClient(accesskey, accesspasswd, 'cn-hangzhou')
|
||||||
|
request = RpcRequest('Alidns', '2015-01-09', 'DescribeDomainRecords')
|
||||||
|
request.add_query_param("DomainName", "XXXXXXXXXXXXXXX") # 请替换成自己的域名
|
||||||
|
request.set_accept_format('json')
|
||||||
|
response = clt.do_action_with_exception(request)
|
||||||
|
return eval(response.replace('false', '0'))
|
||||||
|
|
||||||
|
|
||||||
|
def setDNSrecord(record, ip):
|
||||||
|
global product, version, accesskey, accesspassw
|
||||||
|
clt = client.AcsClient(accesskey, accesspasswd, 'cn-hangzhou')
|
||||||
|
request = RpcRequest('Alidns', '2015-01-09', 'UpdateDomainRecord')
|
||||||
|
request.add_query_param("RecordId", record['RecordId'])
|
||||||
|
request.add_query_param("RR", record['RR'])
|
||||||
|
request.add_query_param("Type", record['Type'])
|
||||||
|
request.add_query_param("Value", ip)
|
||||||
|
request.set_accept_format('json')
|
||||||
|
response = clt.do_action_with_exception(request)
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
ip = getip()
|
||||||
|
print(ip)
|
||||||
|
recordlist = getDNSrecords()
|
||||||
|
for record in recordlist["DomainRecords"]["Record"]:
|
||||||
|
setDNSrecord(record, ip)
|
@ -0,0 +1,44 @@
|
|||||||
|
def digital_to_chinese(digital):
|
||||||
|
str_digital = str(digital)
|
||||||
|
chinese = {'1': '壹', '2': '贰', '3': '叁', '4': '肆', '5': '伍', '6': '陆', '7': '柒', '8': '捌', '9': '玖', '0': '零'}
|
||||||
|
chinese2 = ['拾', '佰', '仟', '万', '厘', '分', '角']
|
||||||
|
jiao = ''
|
||||||
|
bs = str_digital.split('.')
|
||||||
|
yuan = bs[0]
|
||||||
|
if len(bs) > 1:
|
||||||
|
jiao = bs[1]
|
||||||
|
r_yuan = [i for i in reversed(yuan)]
|
||||||
|
count = 0
|
||||||
|
for i in range(len(yuan)):
|
||||||
|
if i == 0:
|
||||||
|
r_yuan[i] += '圆'
|
||||||
|
continue
|
||||||
|
r_yuan[i] += chinese2[count]
|
||||||
|
count += 1
|
||||||
|
if count == 4:
|
||||||
|
count = 0
|
||||||
|
chinese2[3] = '亿'
|
||||||
|
|
||||||
|
s_jiao = [i for i in jiao][:3] # 去掉小于厘之后的
|
||||||
|
|
||||||
|
j_count = -1
|
||||||
|
for i in range(len(s_jiao)):
|
||||||
|
s_jiao[i] += chinese2[j_count]
|
||||||
|
j_count -= 1
|
||||||
|
last = [i for i in reversed(r_yuan)] + s_jiao
|
||||||
|
|
||||||
|
last_str = ''.join(last)
|
||||||
|
print(str_digital)
|
||||||
|
print(last_str)
|
||||||
|
for i in range(len(last_str)):
|
||||||
|
digital = last_str[i]
|
||||||
|
if digital in chinese:
|
||||||
|
last_str = last_str.replace(digital, chinese[digital])
|
||||||
|
print(last_str)
|
||||||
|
return last_str
|
||||||
|
|
||||||
|
|
||||||
|
number = float(input("输入需要转换的数字:"))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
digital_to_chinese(number)
|
@ -0,0 +1,56 @@
|
|||||||
|
"""
|
||||||
|
# 基于Python3、requests
|
||||||
|
# 获取公网ip方式一
|
||||||
|
from json import load
|
||||||
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
public_ip = load(urlopen("http://jsonip.com"))["ip"]
|
||||||
|
print(public_ip)
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# import re
|
||||||
|
# import requests
|
||||||
|
#
|
||||||
|
# link = urllib.urlopen("http://txt.go.sohu.com/ip/soip")
|
||||||
|
# text = link.read()
|
||||||
|
# public_ip = re.findall(r'\d+.\d+.\d+.\d+', text)
|
||||||
|
# print(public_ip[0])
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
# 基于Python3、requests
|
||||||
|
# 输出ip为bytes类型
|
||||||
|
# 获取公网ip方式二
|
||||||
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
public_ip = urlopen("http://ip.42.pl/raw").read()
|
||||||
|
print(public_ip)
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
from json import load
|
||||||
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
public_ip = load(urlopen("http://httpbin.org/ip"))["origin"]
|
||||||
|
print(public_ip)
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
# 利用阿里获取公网IP
|
||||||
|
import requests
|
||||||
|
|
||||||
|
url = 'https://amdc.alipay.com/squery'
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'Host': 'amdc.alipay.com',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0;) Gecko/20100101 Firefox/60.0',
|
||||||
|
'Accept': 'text/html,application/xhtml,application/xml;q=0.9,*/*;q=0.8',
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br',
|
||||||
|
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2'
|
||||||
|
}
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
print(eval(response.text)['clientIp'])
|
||||||
|
|
||||||
|
"""
|
@ -0,0 +1,34 @@
|
|||||||
|
# 读取文本文件并转为莫尔斯电码,然后使用白色和黑色输出到屏幕。再加上冗余和效验码输出成视频
|
||||||
|
|
||||||
|
CODE = {'A': '●▬', 'B': '▬●●●', 'C': '▬●▬●', 'D': '▬●●', 'E': '●',
|
||||||
|
'F': '●●▬●', 'G': '▬▬●', 'H': '●●●●', 'I': '●●',
|
||||||
|
'J': '●▬▬▬', 'K': '▬●▬', 'L': '●▬●●', 'M': '▬▬', 'N': '▬●',
|
||||||
|
'O': '▬▬▬', 'P': '●▬▬●', 'Q': '▬▬●▬', 'R': '●▬●',
|
||||||
|
'S': '●●●', 'T': '▬', 'U': '●●▬', 'V': '●●●▬', 'W': '●▬▬',
|
||||||
|
'X': '▬●●▬', 'Y': '▬●▬▬', 'Z': '▬▬●●',
|
||||||
|
|
||||||
|
'0': '▬▬▬▬▬', '1': '●▬▬▬▬', '2': '●●▬▬▬', '3': '●●●▬▬',
|
||||||
|
'4': '●●●●▬', '5': '●●●●●', '6': '▬●●●●', '7': '▬▬●●●',
|
||||||
|
'8': '▬▬▬●●', '9': '▬▬▬▬●',
|
||||||
|
|
||||||
|
'.': '●▬●▬●▬', ',': '▬▬●●▬▬', ':': '▬▬▬●●●',
|
||||||
|
'?': '●●▬▬●●', '\'': '●▬▬▬▬●', '-': '▬●●●●▬',
|
||||||
|
'/': '▬●●▬●', '@': '●▬▬●▬●', '=': '▬●●●▬', ' ': '/'
|
||||||
|
}
|
||||||
|
|
||||||
|
CODE_REVERSED = {value: key for key, value in CODE.items()}
|
||||||
|
|
||||||
|
|
||||||
|
def to_morse(s):
|
||||||
|
return ' '.join(CODE.get(i.upper()) for i in s)
|
||||||
|
|
||||||
|
|
||||||
|
def from_morse(s):
|
||||||
|
return ''.join(CODE_REVERSED.get(i) for i in s.split())
|
||||||
|
|
||||||
|
|
||||||
|
morse = to_morse('living')
|
||||||
|
space = to_morse(' ')
|
||||||
|
text = from_morse('▬▬●●▬▬')
|
||||||
|
print(morse)
|
||||||
|
print(text)
|
@ -0,0 +1,29 @@
|
|||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
import os
|
||||||
|
|
||||||
|
# 请求解析url
|
||||||
|
url = 'http://xxx.oss-cn-hangzhou.aliyuncs.com'
|
||||||
|
request = requests.get(url)
|
||||||
|
response = request.text
|
||||||
|
# print(response)
|
||||||
|
|
||||||
|
# xml解析
|
||||||
|
tree = ET.ElementTree(ET.fromstring(response))
|
||||||
|
root = tree.getroot()
|
||||||
|
# print(root.attrib)
|
||||||
|
|
||||||
|
for content in root.findall('Contents'):
|
||||||
|
key = content.find('Key').text
|
||||||
|
full_url = url + key
|
||||||
|
request = requests.get(full_url)
|
||||||
|
content_type = request.headers.get('content-type')
|
||||||
|
# print(content_type)
|
||||||
|
if 'octet-stream' not in content_type:
|
||||||
|
# print(full_url)
|
||||||
|
filename = os.path.basename(full_url)
|
||||||
|
# print(filename)
|
||||||
|
local_path = '本地路径'
|
||||||
|
open(local_path + filename, 'wb').write(request.content)
|
@ -0,0 +1,37 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
header = {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0;) Gecko/20100101 Firefox/60.0',
|
||||||
|
'Accept': 'text/html,application/xhtml,application/xml;q=0.9,*/*;q=0.8',
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br',
|
||||||
|
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2'
|
||||||
|
}
|
||||||
|
|
||||||
|
link = 'https://pv.sohu.com/cityjson'
|
||||||
|
url1 = 'https://www.tianqiapi.com/api/'
|
||||||
|
url2 = url1 + '?version=v6&ip=223.6.6.6&appid=22441771&appsecret=jook9nFg'
|
||||||
|
|
||||||
|
|
||||||
|
def get_city_code(url):
|
||||||
|
response = requests.get(url, headers=header)
|
||||||
|
response_1 = response.text.rsplit('var returnCitySN = ')[1]
|
||||||
|
response_dict = response_1.rsplit(';')[0]
|
||||||
|
city_code = eval(response_dict)['cid']
|
||||||
|
# return city_code
|
||||||
|
# print(city_code)
|
||||||
|
|
||||||
|
|
||||||
|
def get_weather(url2):
|
||||||
|
response = requests.get(url2, headers=header)
|
||||||
|
response_dict = eval(response.text)
|
||||||
|
response_list = list(response_dict.values())
|
||||||
|
num_list = [1, 2, 4, 8, 13, 14, 21, 22]
|
||||||
|
for x in num_list:
|
||||||
|
print(response_list[x])
|
||||||
|
|
||||||
|
|
||||||
|
# get_city_code(link)
|
||||||
|
get_weather(url2)
|
||||||
|
|
||||||
|
|
||||||
|
# https://fleet.mdihi.com/chat/chatClient/chatbox.jsp?companyID=365030391&configID=1489&jid=6765387387&s=1
|
@ -0,0 +1,23 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def get_weather(url):
|
||||||
|
# 定义http head伪装成curl浏览器获取IP数据
|
||||||
|
headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0",}
|
||||||
|
request = requests.get(url, headers=headers)
|
||||||
|
response = eval(request.text)
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
|
||||||
|
def get_mfw_news(url):
|
||||||
|
# 定义http head伪装成curl浏览器获取IP数据
|
||||||
|
headers = {'User-Agent': "curl/10.0",
|
||||||
|
"Content-type": "application/x-www-form-urlencoded",
|
||||||
|
"Accept": "text/plain"}
|
||||||
|
request = requests.get(url, headers=headers)
|
||||||
|
response = eval(request.text)
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
|
||||||
|
get_mfw_news('http://www.moji.com/mojiweather/news.php')
|
||||||
|
get_weather('http://www.moji.com/mojiweather/forecast.php')
|
@ -0,0 +1,20 @@
|
|||||||
|
# 到期时间2020-08-29
|
||||||
|
from urllib.request import urlopen, Request
|
||||||
|
import json
|
||||||
|
|
||||||
|
host = 'http://toutiao-ali.juheapi.com'
|
||||||
|
path = '/toutiao/index'
|
||||||
|
method = 'GET'
|
||||||
|
appcode = '32394ce559ff4551936f79a7ea8237f0'
|
||||||
|
querys = 'type=keji'
|
||||||
|
bodys = {}
|
||||||
|
url = host + path + '?' + querys
|
||||||
|
|
||||||
|
|
||||||
|
request = Request(url)
|
||||||
|
request.add_header('Authorization', 'APPCODE ' + appcode)
|
||||||
|
response = urlopen(request)
|
||||||
|
content = response.read()
|
||||||
|
content_dict = json.loads(content)
|
||||||
|
# print(content.decode('utf-8'))
|
||||||
|
print(content_dict)
|
@ -0,0 +1,313 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# CREDIT TO THESE TUTORIALS:
|
||||||
|
# petr.io/en/blog/2015/11/09/read-only-raspberry-pi-with-jessie
|
||||||
|
# hallard.me/raspberry-pi-read-only
|
||||||
|
# k3a.me/how-to-make-raspberrypi-truly-read-only-reliable-and-trouble-free
|
||||||
|
|
||||||
|
if [ $(id -u) -ne 0 ]; then
|
||||||
|
echo "Installer must be run as root."
|
||||||
|
echo "Try 'sudo bash $0'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
|
echo "This script configures a Raspberry Pi"
|
||||||
|
echo "SD card to boot into read-only mode,"
|
||||||
|
echo "obviating need for clean shutdown."
|
||||||
|
echo "NO FILES ON THE CARD CAN BE CHANGED"
|
||||||
|
echo "WHEN PI IS BOOTED IN THIS STATE. Either"
|
||||||
|
echo "the filesystems must be remounted in"
|
||||||
|
echo "read/write mode, card must be mounted"
|
||||||
|
echo "R/W on another system, or an optional"
|
||||||
|
echo "jumper can be used to enable read/write"
|
||||||
|
echo "on boot."
|
||||||
|
echo
|
||||||
|
echo "Links to original tutorials are in"
|
||||||
|
echo "script source. THIS IS A ONE-WAY"
|
||||||
|
echo "OPERATION. THERE IS NO SCRIPT TO"
|
||||||
|
echo "REVERSE THIS SETUP! ALL other system"
|
||||||
|
echo "config should be complete before using"
|
||||||
|
echo "this script. MAKE A BACKUP FIRST."
|
||||||
|
echo
|
||||||
|
echo "Run time ~5 minutes. Reboot required."
|
||||||
|
echo
|
||||||
|
echo -n "CONTINUE? [y/N] "
|
||||||
|
read
|
||||||
|
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
|
||||||
|
echo "Canceled."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# FEATURE PROMPTS ----------------------------------------------------------
|
||||||
|
# Installation doesn't begin until after all user input is taken.
|
||||||
|
|
||||||
|
INSTALL_RW_JUMPER=0
|
||||||
|
INSTALL_HALT=0
|
||||||
|
INSTALL_WATCHDOG=0
|
||||||
|
|
||||||
|
# Given a list of strings representing options, display each option
|
||||||
|
# preceded by a number (1 to N), display a prompt, check input until
|
||||||
|
# a valid number within the selection range is entered.
|
||||||
|
selectN() {
|
||||||
|
for ((i=1; i<=$#; i++)); do
|
||||||
|
echo $i. ${!i}
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
REPLY=""
|
||||||
|
while :
|
||||||
|
do
|
||||||
|
echo -n "SELECT 1-$#: "
|
||||||
|
read
|
||||||
|
if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
|
||||||
|
return $REPLY
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
SYS_TYPES=(Pi\ 3\ /\ Pi\ Zero\ W All\ other\ models)
|
||||||
|
WATCHDOG_MODULES=(bcm2835_wdog bcm2708_wdog)
|
||||||
|
OPTION_NAMES=(NO YES)
|
||||||
|
|
||||||
|
echo -n "Enable boot-time read/write jumper? [y/N] "
|
||||||
|
read
|
||||||
|
if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
|
||||||
|
INSTALL_RW_JUMPER=1
|
||||||
|
echo -n "GPIO pin for R/W jumper: "
|
||||||
|
read
|
||||||
|
RW_PIN=$REPLY
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "Install GPIO-halt utility? [y/N] "
|
||||||
|
read
|
||||||
|
if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
|
||||||
|
INSTALL_HALT=1
|
||||||
|
echo -n "GPIO pin for halt button: "
|
||||||
|
read
|
||||||
|
HALT_PIN=$REPLY
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "Enable kernel panic watchdog? [y/N] "
|
||||||
|
read
|
||||||
|
if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
|
||||||
|
INSTALL_WATCHDOG=1
|
||||||
|
echo "Target system type:"
|
||||||
|
selectN "${SYS_TYPES[0]}" \
|
||||||
|
"${SYS_TYPES[1]}"
|
||||||
|
WD_TARGET=$?
|
||||||
|
fi
|
||||||
|
|
||||||
|
# VERIFY SELECTIONS BEFORE CONTINUING --------------------------------------
|
||||||
|
|
||||||
|
echo
|
||||||
|
if [ $INSTALL_RW_JUMPER -eq 1 ]; then
|
||||||
|
echo "Boot-time R/W jumper: YES (GPIO$RW_PIN)"
|
||||||
|
else
|
||||||
|
echo "Boot-time R/W jumper: NO"
|
||||||
|
fi
|
||||||
|
if [ $INSTALL_HALT -eq 1 ]; then
|
||||||
|
echo "Install GPIO-halt: YES (GPIO$HALT_PIN)"
|
||||||
|
else
|
||||||
|
echo "Install GPIO-halt: NO"
|
||||||
|
fi
|
||||||
|
if [ $INSTALL_WATCHDOG -eq 1 ]; then
|
||||||
|
echo "Enable watchdog: YES (${SYS_TYPES[WD_TARGET-1]})"
|
||||||
|
else
|
||||||
|
echo "Enable watchdog: NO"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
echo -n "CONTINUE? [y/N] "
|
||||||
|
read
|
||||||
|
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
|
||||||
|
echo "Canceled."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# START INSTALL ------------------------------------------------------------
|
||||||
|
# All selections have been validated at this point...
|
||||||
|
|
||||||
|
# Given a filename, a regex pattern to match and a replacement string:
|
||||||
|
# Replace string if found, else no change.
|
||||||
|
# (# $1 = filename, $2 = pattern to match, $3 = replacement)
|
||||||
|
replace() {
|
||||||
|
grep $2 $1 >/dev/null
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
# Pattern found; replace in file
|
||||||
|
sed -i "s/$2/$3/g" $1 >/dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Given a filename, a regex pattern to match and a replacement string:
|
||||||
|
# If found, perform replacement, else append file w/replacement on new line.
|
||||||
|
replaceAppend() {
|
||||||
|
grep $2 $1 >/dev/null
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
# Pattern found; replace in file
|
||||||
|
sed -i "s/$2/$3/g" $1 >/dev/null
|
||||||
|
else
|
||||||
|
# Not found; append on new line (silently)
|
||||||
|
echo $3 | sudo tee -a $1 >/dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Given a filename, a regex pattern to match and a string:
|
||||||
|
# If found, no change, else append file with string on new line.
|
||||||
|
append1() {
|
||||||
|
grep $2 $1 >/dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
# Not found; append on new line (silently)
|
||||||
|
echo $3 | sudo tee -a $1 >/dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Given a filename, a regex pattern to match and a string:
|
||||||
|
# If found, no change, else append space + string to last line --
|
||||||
|
# this is used for the single-line /boot/cmdline.txt file.
|
||||||
|
append2() {
|
||||||
|
grep $2 $1 >/dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
# Not found; insert in file before EOF
|
||||||
|
sed -i "s/\'/ $3/g" $1 >/dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Starting installation..."
|
||||||
|
echo "Updating package index files..."
|
||||||
|
apt-get update
|
||||||
|
|
||||||
|
echo "Removing unwanted packages..."
|
||||||
|
#apt-get remove -y --force-yes --purge triggerhappy logrotate dbus \
|
||||||
|
# dphys-swapfile xserver-common lightdm fake-hwclock
|
||||||
|
# Let's keep dbus...that includes avahi-daemon, a la 'raspberrypi.local',
|
||||||
|
# also keeping xserver & lightdm for GUI login (WIP, not working yet)
|
||||||
|
apt-get remove -y --force-yes --purge triggerhappy logrotate \
|
||||||
|
dphys-swapfile fake-hwclock
|
||||||
|
apt-get -y --force-yes autoremove --purge
|
||||||
|
|
||||||
|
# Replace log management with busybox (use logread if needed)
|
||||||
|
echo "Installing ntp and busybox-syslogd..."
|
||||||
|
apt-get -y --force-yes install ntp busybox-syslogd; dpkg --purge rsyslog
|
||||||
|
|
||||||
|
echo "Configuring system..."
|
||||||
|
|
||||||
|
# Install boot-time R/W jumper test if requested
|
||||||
|
GPIOTEST="gpio -g mode $RW_PIN up\n\
|
||||||
|
if [ \`gpio -g read $RW_PIN\` -eq 0 ] ; then\n\
|
||||||
|
\tmount -o remount,rw \/\n\
|
||||||
|
\tmount -o remount,rw \/boot\n\
|
||||||
|
fi\n"
|
||||||
|
if [ $INSTALL_RW_JUMPER -ne 0 ]; then
|
||||||
|
apt-get install -y --force-yes wiringpi
|
||||||
|
# Check if already present in rc.local:
|
||||||
|
grep "gpio -g read" /etc/rc.local >/dev/null
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
# Already there, but make sure pin is correct:
|
||||||
|
sed -i "s/^.*gpio\ -g\ read.*$/$GPIOTEST/g" /etc/rc.local >/dev/null
|
||||||
|
|
||||||
|
else
|
||||||
|
# Not there, insert before final 'exit 0'
|
||||||
|
sed -i "s/^exit 0/$GPIOTEST\\nexit 0/g" /etc/rc.local >/dev/null
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install watchdog if requested
|
||||||
|
if [ $INSTALL_WATCHDOG -ne 0 ]; then
|
||||||
|
apt-get install -y --force-yes watchdog
|
||||||
|
# $MODULE is specific watchdog module name
|
||||||
|
MODULE=${WATCHDOG_MODULES[($WD_TARGET-1)]}
|
||||||
|
# Add to /etc/modules, update watchdog config file
|
||||||
|
append1 /etc/modules $MODULE $MODULE
|
||||||
|
replace /etc/watchdog.conf "#watchdog-device" "watchdog-device"
|
||||||
|
replace /etc/watchdog.conf "#max-load-1" "max-load-1"
|
||||||
|
# Start watchdog at system start and start right away
|
||||||
|
# Raspbian Stretch needs this package installed first
|
||||||
|
apt-get install -y --force-yes insserv
|
||||||
|
insserv watchdog; /etc/init.d/watchdog start
|
||||||
|
# Additional settings needed on Jessie
|
||||||
|
append1 /lib/systemd/system/watchdog.service "WantedBy" "WantedBy=multi-user.target"
|
||||||
|
systemctl enable watchdog
|
||||||
|
# Set up automatic reboot in sysctl.conf
|
||||||
|
replaceAppend /etc/sysctl.conf "^.*kernel.panic.*$" "kernel.panic = 10"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install gpio-halt if requested
|
||||||
|
if [ $INSTALL_HALT -ne 0 ]; then
|
||||||
|
apt-get install -y --force-yes wiringpi
|
||||||
|
echo "Installing gpio-halt in /usr/local/bin..."
|
||||||
|
cd /tmp
|
||||||
|
curl -LO https://github.com/adafruit/Adafruit-GPIO-Halt/archive/master.zip
|
||||||
|
unzip master.zip
|
||||||
|
cd Adafruit-GPIO-Halt-master
|
||||||
|
make
|
||||||
|
mv gpio-halt /usr/local/bin
|
||||||
|
cd ..
|
||||||
|
rm -rf Adafruit-GPIO-Halt-master
|
||||||
|
|
||||||
|
# Add gpio-halt to /rc.local:
|
||||||
|
grep gpio-halt /etc/rc.local >/dev/null
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
# gpio-halt already in rc.local, but make sure correct:
|
||||||
|
sed -i "s/^.*gpio-halt.*$/\/usr\/local\/bin\/gpio-halt $HALT_PIN \&/g" /etc/rc.local >/dev/null
|
||||||
|
else
|
||||||
|
# Insert gpio-halt into rc.local before final 'exit 0'
|
||||||
|
sed -i "s/^exit 0/\/usr\/local\/bin\/gpio-halt $HALT_PIN \&\\nexit 0/g" /etc/rc.local >/dev/null
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add fastboot, noswap and/or ro to end of /boot/cmdline.txt
|
||||||
|
append2 /boot/cmdline.txt fastboot fastboot
|
||||||
|
append2 /boot/cmdline.txt noswap noswap
|
||||||
|
append2 /boot/cmdline.txt ro^o^t ro
|
||||||
|
|
||||||
|
# Move /var/spool to /tmp
|
||||||
|
rm -rf /var/spool
|
||||||
|
ln -s /tmp /var/spool
|
||||||
|
|
||||||
|
# Move /var/lib/lightdm and /var/cache/lightdm to /tmp
|
||||||
|
rm -rf /var/lib/lightdm
|
||||||
|
rm -rf /var/cache/lightdm
|
||||||
|
ln -s /tmp /var/lib/lightdm
|
||||||
|
ln -s /tmp /var/cache/lightdm
|
||||||
|
|
||||||
|
# Make SSH work
|
||||||
|
replaceAppend /etc/ssh/sshd_config "^.*UsePrivilegeSeparation.*$" "UsePrivilegeSeparation no"
|
||||||
|
# bbro method (not working in Jessie?):
|
||||||
|
#rmdir /var/run/sshd
|
||||||
|
#ln -s /tmp /var/run/sshd
|
||||||
|
|
||||||
|
# Change spool permissions in var.conf (rondie/Margaret fix)
|
||||||
|
replace /usr/lib/tmpfiles.d/var.conf "spool\s*0755" "spool 1777"
|
||||||
|
|
||||||
|
# Move dhcpd.resolv.conf to tmpfs
|
||||||
|
touch /tmp/dhcpcd.resolv.conf
|
||||||
|
rm /etc/resolv.conf
|
||||||
|
ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf
|
||||||
|
|
||||||
|
# Make edits to fstab
|
||||||
|
# make / ro
|
||||||
|
# tmpfs /var/log tmpfs nodev,nosuid 0 0
|
||||||
|
# tmpfs /var/tmp tmpfs nodev,nosuid 0 0
|
||||||
|
# tmpfs /tmp tmpfs nodev,nosuid 0 0
|
||||||
|
replace /etc/fstab "vfat\s*defaults\s" "vfat defaults,ro "
|
||||||
|
replace /etc/fstab "ext4\s*defaults,noatime\s" "ext4 defaults,noatime,ro "
|
||||||
|
append1 /etc/fstab "/var/log" "tmpfs /var/log tmpfs nodev,nosuid 0 0"
|
||||||
|
append1 /etc/fstab "/var/tmp" "tmpfs /var/tmp tmpfs nodev,nosuid 0 0"
|
||||||
|
append1 /etc/fstab "\s/tmp" "tmpfs /tmp tmpfs nodev,nosuid 0 0"
|
||||||
|
|
||||||
|
# PROMPT FOR REBOOT --------------------------------------------------------
|
||||||
|
|
||||||
|
echo "Done."
|
||||||
|
echo
|
||||||
|
echo "Settings take effect on next boot."
|
||||||
|
echo
|
||||||
|
echo -n "REBOOT NOW? [y/N] "
|
||||||
|
read
|
||||||
|
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
|
||||||
|
echo "Exiting without reboot."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo "Reboot started..."
|
||||||
|
reboot
|
||||||
|
exit 0
|
Loading…
Reference in new issue