首次提交
This commit is contained in:
@@ -0,0 +1,205 @@
|
||||
#!/bin/sh
|
||||
|
||||
# 检查参数数量
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: $0 <sequence_number>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
dir_path="/root/u"
|
||||
|
||||
# 检查U盘目录是否存在
|
||||
if [ ! -d "$dir_path" ]; then
|
||||
echo "U盘目录不存在,正在创建U盘目录..."
|
||||
mkdir -p "$dir_path" # 创建目录
|
||||
else
|
||||
echo "U盘目录已经存在."
|
||||
fi
|
||||
|
||||
|
||||
# 获取命令行参数
|
||||
sequence_number=$1
|
||||
|
||||
# 定义一个函数来执行复制操作并输出结果
|
||||
copy_file() {
|
||||
local source_file="$1"
|
||||
local target_dir="$2"
|
||||
if [ -f "$source_file" ]; then
|
||||
cp "$source_file" "$target_dir"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "文件 $source_file 已成功复制到 $target_dir 目录。"
|
||||
else
|
||||
echo "复制文件 $source_file 时出错。"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "当前目录下未找到 $source_file 文件。"
|
||||
fi
|
||||
}
|
||||
# 添加 启动脚本 到 /etc/init.d/
|
||||
copy_file "S79hostapd" "/etc/init.d/"
|
||||
copy_file "S90E-CAP" "/etc/init.d/"
|
||||
#copy_file "S99Check_reboot" "/etc/init.d/"
|
||||
|
||||
# 移除 启动脚本
|
||||
rename_file() {
|
||||
local original_name="$1"
|
||||
local new_name="$2"
|
||||
|
||||
if [ -f "$original_name" ]; then
|
||||
mv "$original_name" "$new_name"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "已成功将 $original_name 重命名为 $new_name"
|
||||
else
|
||||
echo "重命名 $original_name 时出错。"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "$original_name 文件不存在"
|
||||
fi
|
||||
}
|
||||
rename_file "/etc/init.d/S49weston" "/etc/init.d/_S49weston"
|
||||
rename_file "/etc/init.d/S41dhcpcd" "/etc/init.d/_S41dhcpcd"
|
||||
|
||||
# 生成 /etc/hostapd.conf 文件
|
||||
hostapd_config="# 无线网络接口名称,可通过 ifconfig 或 ip addr 命令查看
|
||||
interface=wlan0
|
||||
# 使用的驱动程序,通常为 nl80211
|
||||
driver=nl80211
|
||||
# 热点的 SSID
|
||||
ssid=E-CAP_${sequence_number}
|
||||
# 通道号,可根据需要调整
|
||||
channel=6
|
||||
# 认证和加密模式
|
||||
hw_mode=g
|
||||
ieee80211n=1
|
||||
wmm_enabled=1
|
||||
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
|
||||
macaddr_acl=0
|
||||
auth_algs=1
|
||||
ignore_broadcast_ssid=0
|
||||
wpa=2
|
||||
wpa_key_mgmt=WPA-PSK
|
||||
wpa_pairwise=TKIP
|
||||
rsn_pairwise=CCMP
|
||||
# 热点的密码
|
||||
wpa_passphrase=12345678"
|
||||
|
||||
echo "$hostapd_config" > /etc/hostapd.conf
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "文件 /etc/hostapd.conf 已成功生成。"
|
||||
else
|
||||
echo "生成 /etc/hostapd.conf 文件时出错。"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 生成 /etc/dnsmasq.conf 文件
|
||||
dnsmasq_config="# 监听的接口
|
||||
interface=wlan0
|
||||
# DHCP 服务的 IP 地址范围
|
||||
dhcp-range=192.168.10.10,192.168.10.100,255.255.255.0,12h
|
||||
# 网关地址
|
||||
dhcp-option=3,192.168.10.1
|
||||
# DNS 服务器地址
|
||||
dhcp-option=6,8.8.8.8
|
||||
# 本地 DNS 服务器地址
|
||||
server=8.8.8.8
|
||||
# 禁用 DNS 缓存
|
||||
no-hosts
|
||||
# 不读取 /etc/resolv.conf 文件
|
||||
no-resolv"
|
||||
|
||||
echo "$dnsmasq_config" > /etc/dnsmasq.conf
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "文件 /etc/dnsmasq.conf 已成功生成。"
|
||||
else
|
||||
echo "生成 /etc/dnsmasq.conf 文件时出错。"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 生成 /etc/network/interfaces 文件
|
||||
network_config="# interface file auto-generated by buildroot
|
||||
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
auto eth0
|
||||
iface eth0 inet static
|
||||
address 192.168.1.${sequence_number}
|
||||
netmask 255.255.255.0
|
||||
gateway 192.168.1.1
|
||||
dns-nameservers 192.168.1.1 8.8.8.8
|
||||
post-up /usr/sbin/ethtool -s eth0 speed 100 duplex full autoneg off
|
||||
pre-down /usr/sbin/ethtool -s eth0 autoneg on
|
||||
# post-up 网络接口被激活之后应该执行的命令。
|
||||
# pre-down 在网络接口即将被关闭之前执行的命令。
|
||||
# 添加这两行命令是为了限制网速为100M,解决phy网络排线过长导致网卡不稳定的问题。
|
||||
|
||||
auto wlan0
|
||||
iface wlan0 inet static
|
||||
address 192.168.10.${sequence_number}
|
||||
netmask 255.255.255.0
|
||||
gateway 192.168.10.1
|
||||
dns-nameservers 192.168.10.1 8.8.8.8"
|
||||
|
||||
# 生成 /etc/network/interfaces 文件
|
||||
echo "$network_config" > /etc/network/interfaces
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "文件 /etc/network/interfaces 已成功生成。"
|
||||
else
|
||||
echo "生成 /etc/network/interfaces 文件时出错。"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -d "/root/tiles" ]; then
|
||||
if [ -f "tiles.zip" ]; then # 检查 tiles.zip 文件是否存在
|
||||
unzip -q "tiles.zip" -d "/root/" # 解压 tiles.zip 到 /root/ 目录
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "tiles.zip 已成功解压到 /root/ 目录。"
|
||||
else
|
||||
echo "解压 tiles.zip 到 /root/ 目录时出错。"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "当前目录下未找到 tiles.zip 文件。"
|
||||
fi
|
||||
else
|
||||
echo "瓦片文件夹已存在。"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# 检查当前目录下的 Radarcape_Local_Server_aarch64-buildroot-linux-gnu-gxx_Linux_Debug 文件是否存在
|
||||
if [ -f "Radarcape_Local_Server_aarch64-buildroot-linux-gnu-gxx_Linux_Debug" ]; then
|
||||
# 给文件添加执行权限
|
||||
chmod +x "Radarcape_Local_Server_aarch64-buildroot-linux-gnu-gxx_Linux_Debug"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "已成功给当前目录下的 Radarcape_Local_Server_aarch64-buildroot-linux-gnu-gxx_Linux_Debug 文件添加执行权限。"
|
||||
else
|
||||
echo "给当前目录下的 Radarcape_Local_Server_aarch64-buildroot-linux-gnu-gxx_Linux_Debug 文件添加执行权限时出错。"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "当前目录下未找到 Radarcape_Local_Server_aarch64-buildroot-linux-gnu-gxx_Linux_Debug 文件。"
|
||||
fi
|
||||
|
||||
# 定义要设置的 root 密码
|
||||
ROOT_PASSWORD="123"
|
||||
|
||||
# 使用 expect 来非交互式地修改 root 密码
|
||||
expect << EOF
|
||||
spawn passwd root
|
||||
expect "New password:"
|
||||
send "$ROOT_PASSWORD\r"
|
||||
expect "Retype new password:"
|
||||
send "$ROOT_PASSWORD\r"
|
||||
expect eof
|
||||
EOF
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "root 用户密码已成功设置。"
|
||||
else
|
||||
echo "设置 root 用户密码时出错。"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user