#!/bin/bash
groupadd -g 0 AID_ROOT
groupadd -g 1 AID_DAEMON
groupadd -g 2 AID_BIN
groupadd -g 3 AID_SYS
groupadd -g 1000 AID_SYSTEM
groupadd -g 1001 AID_RADIO
groupadd -g 1002 AID_BLUETOOTH
groupadd -g 1003 AID_GRAPHICS
groupadd -g 1004 AID_INPUT
groupadd -g 1005 AID_AUDIO
groupadd -g 1006 AID_CAMERA
groupadd -g 1007 AID_LOG
groupadd -g 1008 AID_COMPASS
groupadd -g 1009 AID_MOUNT
groupadd -g 1010 AID_WIFI
groupadd -g 1011 AID_ADB
groupadd -g 1012 AID_INSTALL
groupadd -g 1013 AID_MEDIA
groupadd -g 1014 AID_DHCP
groupadd -g 1015 AID_SDCARD_RW
groupadd -g 1016 AID_VPN
groupadd -g 1017 AID_KEYSTORE
groupadd -g 1018 AID_USB
groupadd -g 1019 AID_DRM
groupadd -g 1020 AID_MDNSR
groupadd -g 1021 AID_GPS
groupadd -g 1022 AID_UNUSED1
groupadd -g 1023 AID_MEDIA_RW
groupadd -g 1024 AID_MTP
groupadd -g 1025 AID_UNUSED2
groupadd -g 1026 AID_DRMRPC
groupadd -g 1027 AID_NFC
groupadd -g 1028 AID_SDCARD_R
groupadd -g 1029 AID_CLAT
groupadd -g 1030 AID_LOOP_RADIO
groupadd -g 1031 AID_MEDIA_DRM
groupadd -g 1032 AID_PACKAGE_INFO
groupadd -g 1033 AID_SDCARD_PICS
groupadd -g 1034 AID_SDCARD_AV
groupadd -g 1035 AID_SDCARD_ALL
groupadd -g 1036 AID_LOGD
groupadd -g 1037 AID_SHARED_RELRO
groupadd -g 1038 AID_DBUS
groupadd -g 1039 AID_TLSDATE
groupadd -g 1040 AID_MEDIA_EX
groupadd -g 1041 AID_AUDIOSERVER
groupadd -g 1042 AID_METRICS_COLL
groupadd -g 1043 AID_METRICSD
groupadd -g 1044 AID_WEBSERV
groupadd -g 1045 AID_DEBUGGERD
groupadd -g 1046 AID_MEDIA_CODEC
groupadd -g 1047 AID_CAMERASERVER
groupadd -g 1048 AID_FIREWALL
groupadd -g 1049 AID_TRUNKS
groupadd -g 1050 AID_NVRAM
groupadd -g 1051 AID_DNS
groupadd -g 1052 AID_DNS_TETHER
groupadd -g 1053 AID_WEBVIEW_ZYGOTE
groupadd -g 1054 AID_VEHICLE_NETWORK
groupadd -g 1055 AID_MEDIA_AUDIO
groupadd -g 1056 AID_MEDIA_VIDEO
groupadd -g 1057 AID_MEDIA_IMAGE
groupadd -g 1058 AID_TOMBSTONED
groupadd -g 1059 AID_MEDIA_OBB
groupadd -g 1060 AID_ESE
groupadd -g 1061 AID_OTA_UPDATE
groupadd -g 1062 AID_AUTOMOTIVE_EVS
groupadd -g 1063 AID_LOWPAN
groupadd -g 1064 AID_HSM
groupadd -g 1065 AID_RESERVED_DISK
groupadd -g 1066 AID_STATSD
groupadd -g 1067 AID_INCIDENTD
groupadd -g 1068 AID_SECURE_ELEMENT
groupadd -g 1069 AID_LMKD
groupadd -g 1070 AID_LLKD
groupadd -g 1071 AID_IORAPD
groupadd -g 1072 AID_GPU_SERVICE
groupadd -g 1073 AID_NETWORK_STACK
groupadd -g 1074 AID_GSID
groupadd -g 1075 AID_FSVERITY_CERT
groupadd -g 1076 AID_CREDSTORE
groupadd -g 1077 AID_EXTERNAL_STORAGE
groupadd -g 1078 AID_EXT_DATA_RW
groupadd -g 1079 AID_EXT_OBB_RW
groupadd -g 1080 AID_CONTEXT_HUB
groupadd -g 1081 AID_VIRTUALIZATIONSERVICE
groupadd -g 1082 AID_ARTD
groupadd -g 1083 AID_UWB
groupadd -g 1084 AID_THREAD_NETWORK
groupadd -g 1085 AID_DICED
groupadd -g 1086 AID_DMESGD
groupadd -g 1087 AID_JC_WEAVER
groupadd -g 1088 AID_JC_STRONGBOX
groupadd -g 1089 AID_JC_IDENTITYCRED
groupadd -g 1090 AID_SDK_SANDBOX
groupadd -g 1091 AID_SECURITY_LOG_WRITER
groupadd -g 1092 AID_PRNG_SEEDER
groupadd -g 2000 AID_SHELL
groupadd -g 2001 AID_CACHE
groupadd -g 2002 AID_DIAG
groupadd -g 2900 AID_OEM_RESERVED_START
groupadd -g 2999 AID_OEM_RESERVED_END
groupadd -g 3001 AID_NET_BT_ADMIN
groupadd -g 3002 AID_NET_BT
groupadd -g 3003 AID_INET
groupadd -g 3004 AID_NET_RAW
groupadd -g 3005 AID_NET_ADMIN
groupadd -g 3006 AID_NET_BW_STATS
groupadd -g 3007 AID_NET_BW_ACCT
groupadd -g 3009 AID_READPROC
groupadd -g 3010 AID_WAKELOCK
groupadd -g 3011 AID_UHID
groupadd -g 3012 AID_READTRACEFS
groupadd -g 5000 AID_OEM_RESERVED_2_START
groupadd -g 5999 AID_OEM_RESERVED_2_END
groupadd -g 6000 AID_SYSTEM_RESERVED_START
groupadd -g 6499 AID_SYSTEM_RESERVED_END
groupadd -g 6500 AID_ODM_RESERVED_START
groupadd -g 6999 AID_ODM_RESERVED_END
groupadd -g 7000 AID_PRODUCT_RESERVED_START
groupadd -g 7499 AID_PRODUCT_RESERVED_END
groupadd -g 7500 AID_SYSTEM_EXT_RESERVED_START
groupadd -g 7999 AID_SYSTEM_EXT_RESERVED_END
groupadd -g 9997 AID_EVERYBODY
groupadd -g 9998 AID_MISC
groupadd -g 9999 AID_NOBODY
groupadd -g 10000 AID_APP
groupadd -g 10000 AID_APP_START
groupadd -g 19999 AID_APP_END
groupadd -g 20000 AID_CACHE_GID_START
groupadd -g 29999 AID_CACHE_GID_END
groupadd -g 30000 AID_EXT_GID_START
groupadd -g 39999 AID_EXT_GID_END
groupadd -g 40000 AID_EXT_CACHE_GID_START
groupadd -g 49999 AID_EXT_CACHE_GID_END
groupadd -g 50000 AID_SHARED_GID_START
groupadd -g 59999 AID_SHARED_GID_END
groupadd -g 65534 AID_OVERFLOWUID
groupadd -g 20000 AID_SDK_SANDBOX_PROCESS_START
groupadd -g 29999 AID_SDK_SANDBOX_PROCESS_END
groupadd -g 90000 AID_ISOLATED_START
groupadd -g 99999 AID_ISOLATED_END
groupadd -g 100000 AID_USER
groupadd -g 100000 AID_USER_OFFSET
usermod -g 3003 -G 3003,3004 -a _apt
useradd -m ${CREATE_USER} 
sed -i /${CREATE_USER}/s/sh/bash/ /etc/passwd
echo "设置${CREATE_USER}用户密码"
passwd ${CREATE_USER}
echo "设置root用户密码"
passwd
chmod 755 /
chmod 755 /bin /usr /home /media /opt /sbin /srv /tmp /var /boot /etc /lib /mnt /run /proc /sys /dev
chmod 755 -R /usr
chmod 755 /etc/bash.bashrc
chmod 644 /etc/passwd
chmod 755 /etc/profile
for i in root ${CREATE_USER}
do usermod -a -G AID_ROOT,AID_DAEMON,AID_BIN,AID_SYS,AID_SYSTEM,AID_RADIO,AID_BLUETOOTH,AID_GRAPHICS,AID_INPUT,AID_AUDIO,AID_CAMERA,AID_LOG,AID_COMPASS,AID_MOUNT,AID_WIFI,AID_ADB,AID_INSTALL,AID_MEDIA,AID_DHCP,AID_SDCARD_RW,AID_VPN,AID_KEYSTORE,AID_USB,AID_DRM,AID_MDNSR,AID_GPS,AID_UNUSED1,AID_MEDIA_RW,AID_MTP,AID_UNUSED2,AID_DRMRPC,AID_NFC,AID_SDCARD_R,AID_CLAT,AID_LOOP_RADIO,AID_MEDIA_DRM,AID_PACKAGE_INFO,AID_SDCARD_PICS,AID_SDCARD_AV,AID_SDCARD_ALL,AID_LOGD,AID_SHARED_RELRO,AID_DBUS,AID_TLSDATE,AID_MEDIA_EX,AID_AUDIOSERVER,AID_METRICS_COLL,AID_METRICSD,AID_WEBSERV,AID_DEBUGGERD,AID_MEDIA_CODEC,AID_CAMERASERVER,AID_FIREWALL,AID_TRUNKS,AID_NVRAM,AID_DNS,AID_DNS_TETHER,AID_WEBVIEW_ZYGOTE,AID_VEHICLE_NETWORK,AID_MEDIA_AUDIO,AID_MEDIA_VIDEO,AID_MEDIA_IMAGE,AID_TOMBSTONED,AID_MEDIA_OBB,AID_ESE,AID_OTA_UPDATE,AID_AUTOMOTIVE_EVS,AID_LOWPAN,AID_HSM,AID_RESERVED_DISK,AID_STATSD,AID_INCIDENTD,AID_SECURE_ELEMENT,AID_LMKD,AID_LLKD,AID_IORAPD,AID_GPU_SERVICE,AID_NETWORK_STACK,AID_GSID,AID_FSVERITY_CERT,AID_CREDSTORE,AID_EXTERNAL_STORAGE,AID_EXT_DATA_RW,AID_EXT_OBB_RW,AID_CONTEXT_HUB,AID_VIRTUALIZATIONSERVICE,AID_ARTD,AID_UWB,AID_THREAD_NETWORK,AID_DICED,AID_DMESGD,AID_JC_WEAVER,AID_JC_STRONGBOX,AID_JC_IDENTITYCRED,AID_SDK_SANDBOX,AID_SECURITY_LOG_WRITER,AID_PRNG_SEEDER,AID_SHELL,AID_CACHE,AID_DIAG,AID_OEM_RESERVED_START,AID_OEM_RESERVED_END,AID_NET_BT_ADMIN,AID_NET_BT,AID_INET,AID_NET_RAW,AID_NET_ADMIN,AID_NET_BW_STATS,AID_NET_BW_ACCT,AID_READPROC,AID_WAKELOCK,AID_UHID,AID_READTRACEFS,AID_OEM_RESERVED_2_START,AID_OEM_RESERVED_2_END,AID_SYSTEM_RESERVED_START,AID_SYSTEM_RESERVED_END,AID_ODM_RESERVED_START,AID_ODM_RESERVED_END,AID_PRODUCT_RESERVED_START,AID_PRODUCT_RESERVED_END,AID_SYSTEM_EXT_RESERVED_START,AID_SYSTEM_EXT_RESERVED_END,AID_EVERYBODY,AID_MISC,AID_NOBODY,AID_APP,AID_APP_START,AID_APP_END,AID_CACHE_GID_START,AID_CACHE_GID_END,AID_EXT_GID_START,AID_EXT_GID_END,AID_EXT_CACHE_GID_START,AID_EXT_CACHE_GID_END,AID_SHARED_GID_START,AID_SHARED_GID_END,AID_OVERFLOWUID,AID_SDK_SANDBOX_PROCESS_START,AID_SDK_SANDBOX_PROCESS_END,AID_ISOLATED_START,AID_ISOLATED_END,AID_USER,AID_USER_OFFSET $i
done
